Trimming 3 margins
Trimming 3 margins
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
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
- fmw42
- Posts: 25562
- Joined: 2007-07-02T17:14:51-07:00
- Authentication code: 1152
- Location: Sunnyvale, California, USA
Re: Trimming 3 margins
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.
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.
- anthony
- Posts: 8883
- Joined: 2004-05-31T19:27:03-07:00
- Authentication code: 8675308
- Location: Brisbane, Australia
Re: Trimming 3 margins
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.
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.
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
https://imagemagick.org/Usage/
- fmw42
- Posts: 25562
- Joined: 2007-07-02T17:14:51-07:00
- Authentication code: 1152
- Location: Sunnyvale, California, USA
Re: Trimming 3 margins
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).
- anthony
- Posts: 8883
- Joined: 2004-05-31T19:27:03-07:00
- Authentication code: 8675308
- Location: Brisbane, Australia
Re: Trimming 3 margins
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

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

Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
https://imagemagick.org/Usage/
Re: Trimming 3 margins
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.
- anthony
- Posts: 8883
- Joined: 2004-05-31T19:27:03-07:00
- Authentication code: 8675308
- Location: Brisbane, Australia
Re: Trimming 3 margins
To draw a single pixel see the 'pixel' primative for -draw
http://www.imagemagick.org/Usage/draw/#primitives
http://www.imagemagick.org/Usage/draw/#primitives
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
https://imagemagick.org/Usage/
Re: Trimming 3 margins
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:
The result is 2 blue rectangles but no dots on them.
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.
- anthony
- Posts: 8883
- Joined: 2004-05-31T19:27:03-07:00
- Authentication code: 8675308
- Location: Brisbane, Australia
Re: Trimming 3 margins
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
See IM Examples, Windows Usage, DOS Scripts
http://www.imagemagick.org/Usage/windows/#dos
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
https://imagemagick.org/Usage/
Re: Trimming 3 margins
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?
- fmw42
- Posts: 25562
- Joined: 2007-07-02T17:14:51-07:00
- Authentication code: 1152
- Location: Sunnyvale, California, USA
Re: Trimming 3 margins
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 (...)
convert image \( -size 1x1 xc:black \) -gravity north -compose over -composite result
In windows leave off the \ and just use (...)
Re: Trimming 3 margins
That worked beautifully, thank you all for help