Page 1 of 1
Trimming 3 margins
Posted: 2012-03-05T20:23:37-07:00
by wile
Hi,
I have been successfully using trim command along with fuzz to remove white margins from my images. This time I want to remove only left, bottom and right margins, the top one must remain intact. I'm not sure how to do this, can anyone help please. I do batch processing so hopefully it can be done in a single line.
Many thanks
Re: Trimming 3 margins
Posted: 2012-03-05T20:29:25-07:00
by fmw42
I think you will have to do 3 successive one-sided trims as depicted in
http://www.imagemagick.org/Usage/crop/#trim_oneside. They can all be chained in one command line, I believe.
You can also use my bash unix script, trimmer, if on Mac/Linux or Windows with Cygwin. See the link below. Or you can duplicate my code as you need and fold into one command line.
Re: Trimming 3 margins
Posted: 2012-03-05T21:43:21-07:00
by anthony
Or add a single 'changed' pixel in the center of the top row of the image, the trim.
After the trim fix that pixel!
Making -trim, trim only selected sides as been something I wanted for a long time.
trouble is getting someone to do the work. The trim code itself is VERY straight forward.
Re: Trimming 3 margins
Posted: 2012-03-05T21:59:32-07:00
by fmw42
anthony wrote:Or add a single 'changed' pixel in the center of the top row of the image, the trim.
After the trim fix that pixel!
Making -trim, trim only selected sides as been something I wanted for a long time.
trouble is getting someone to do the work. The trim code itself is VERY straight forward.
Yes, that is basically what I did in my trimmer script. Added one black pixel to the center of the added border(s).
Re: Trimming 3 margins
Posted: 2012-03-06T00:13:48-07:00
by anthony
As long as the rest of those pixels weren't black
Actually negating that one pixel should work well, unless the pixel is a perfect (or near perfect) gray. negateing it back after trimming will restore it.
Of course this assumes the 'center' is not actually part of the trim region

Re: Trimming 3 margins
Posted: 2012-03-06T05:09:30-07:00
by wile
Thanks for your suggestions. Background is always white or near white and margins are more or less even so changing colour of a single pixel in the middle of the top row of pixels and changing it back would work. Could somebody please help me with the actual command line for it. Much appreciated.
Re: Trimming 3 margins
Posted: 2012-03-06T05:54:42-07:00
by anthony
To draw a single pixel see the 'pixel' primative for
-draw
http://www.imagemagick.org/Usage/draw/#primitives
Re: Trimming 3 margins
Posted: 2012-03-06T06:19:14-07:00
by wile
I don't know what I'm doing here. I tried the first basic examples from the link you've given but all I'm getting is this:
Code: Select all
D:\Images>convert -size 10x6 xc:skyblue -fill black -draw 'point 3,2' -scale 10
0x60 draw_point.gif
convert.exe: Non-conforming drawing primitive definition `point' @ error/draw.c/
DrawImage/3142.
convert.exe: unable to open image `3,2'': No such file or directory @ error/blob
.c/OpenBlob/2589.
convert.exe: no decode delegate for this image format `3,2'' @ error/constitute.
c/ReadImage/532.
convert.exe: Non-conforming drawing primitive definition `point' @ error/draw.c/
DrawImage/3142.
D:\Images>convert -size 10x6 xc:skyblue -fill black -draw 'color 6,3 point' -sc
ale 100x60 draw_color_point.gif
convert.exe: Non-conforming drawing primitive definition `color' @ error/draw.c/
DrawImage/3142.
convert.exe: unable to open image `6,3': No such file or directory @ error/blob.
c/OpenBlob/2589.
convert.exe: no decode delegate for this image format `6,3' @ error/constitute.c
/ReadImage/532.
convert.exe: unable to open image `point'': No such file or directory @ error/bl
ob.c/OpenBlob/2589.
convert.exe: no decode delegate for this image format `point'' @ error/constitut
e.c/ReadImage/532.
convert.exe: Non-conforming drawing primitive definition `color' @ error/draw.c/
DrawImage/3142.
The result is 2 blue rectangles but no dots on them.
Re: Trimming 3 margins
Posted: 2012-03-06T06:21:38-07:00
by anthony
As you are on windows you need to use DOS script syntax. Replace the single quotes with double.
See IM Examples, Windows Usage, DOS Scripts
http://www.imagemagick.org/Usage/windows/#dos
Re: Trimming 3 margins
Posted: 2012-03-06T08:26:35-07:00
by wile
OK that worked fine. So I should be able to paint 1 pixel black but this command seems to be using absolute coordinates while my images have very different dimensions. How can I paint it exactly in the middle of the top row of pixels regardless of image width?
Re: Trimming 3 margins
Posted: 2012-03-06T11:24:11-07:00
by fmw42
Use -gravity north with your composition
convert image \( -size 1x1 xc:black \) -gravity north -compose over -composite result
In windows leave off the \ and just use (...)
Re: Trimming 3 margins
Posted: 2012-03-06T15:17:39-07:00
by wile
That worked beautifully, thank you all for help