Page 1 of 1

trim image whitespace but leave 30 pixel

Posted: 2013-10-07T02:15:00-07:00
by abcplex
I have found this page very help-full,
viewtopic.php?f=1&t=15675

This works great but I need to trim all but leave 30 pixel from top, bottom, left and right.

Re: trim image whitespace but leave 30 pixel

Posted: 2013-10-07T04:38:46-07:00
by Bonzo
I would use -trim as normal and then add a 30px white border afterwards.

Re: trim image whitespace but leave 30 pixel

Posted: 2013-10-07T06:20:31-07:00
by abcplex
The issue is that I don't want to apply this to all images. Only the images that have white spaces. BTW, how to do add 30 pixels to image

Re: trim image whitespace but leave 30 pixel

Posted: 2013-10-07T07:52:24-07:00
by Bonzo
The issue is that I don't want to apply this to all images. Only the images that have white spaces.
This is the problem if you do not include all the information you probably will not get the answer you are looking for :)

Now you have two choices:

Are you looking to keep all the images the same size? If so you could use -extent to pad the trimed image out to the same size as the others.
In this case I have assumed the other images are 500x500

Code: Select all

convert input.jpg -background White -gravity center -extent 500x500 output.jpg
Otherwise you could use -border to add the 30 pixels

Code: Select all

convert input.jpg -bordercolor White -border 30x30 output.jpg

Re: trim image whitespace but leave 30 pixel

Posted: 2013-10-07T08:00:36-07:00
by abcplex
I have lot of images. My background process is removing all the white spaces from all images. Now, I need to add 30px white border only to those images that have white spaces (not all images)

Re: trim image whitespace but leave 30 pixel

Posted: 2013-10-07T10:30:24-07:00
by fmw42
Can you post examples of your input and explain what you want to do? You can post an example to any free image hosting service and put a link to it here.

My guess is you want

convert your image -bordercolor white -border 1 -fuzz XX% -trim +repage resultimage

Adding the 1 pixel white border will the allow -trim to trim images with no white around them back to their original size, but will trim any image that has near-white on the border to get rid of all near-white borders.

If you want to limit the trim to 30 pixels and are on Linux/Mac or Windows with cygwind, see my script, limitedtrim at the link below.