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.
trim image whitespace but leave 30 pixel
Re: trim image whitespace but leave 30 pixel
I would use -trim as normal and then add a 30px white border afterwards.
Re: trim image whitespace but leave 30 pixel
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
This is the problem if you do not include all the information you probably will not get the answer you are looking forThe issue is that I don't want to apply this to all images. Only the images that have white spaces.
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
Code: Select all
convert input.jpg -bordercolor White -border 30x30 output.jpg
Re: trim image whitespace but leave 30 pixel
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)
- fmw42
- Posts: 25562
- Joined: 2007-07-02T17:14:51-07:00
- Authentication code: 1152
- Location: Sunnyvale, California, USA
Re: trim image whitespace but leave 30 pixel
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.
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.