Page 1 of 1

Help w/ uni-directional trimming / parameters

Posted: 2016-02-01T19:39:22-07:00
by SaveOurBolts
Hello,

I've tried to figure this out for a while without luck, so here we go. I'm using IM to trim/resize product images, which works beautifully when they're edited well. However, on natural backgrounds, it gets tricky. Here is what I use 90% of the time:

mogrify -trim -fuzz 15% -background white -gravity center -resize 800x800 -extent 800x800 *.jpg

When using this, however, on images with shadows, etc. I end up with hard lines between product and padding:
Original: https://s3-us-west-1.amazonaws.com/imma ... _Image.jpg
Edited (w/ above command): https://s3-us-west-1.amazonaws.com/imma ... _Image.jpg

In this case, I ideally want to trim to the largest aspect, in this case width, then resize to 800, then trim/pad the other dimension (vert in this case) to 800. Make sense?

In this ideal case, I keep the natural shadows in the vertical space while still trimming and resizing my image down to the target size. It would end up looking like this: https://s3-us-west-1.amazonaws.com/imma ... _image.jpg

Thanks in advance!
Ben

Re: Help w/ uni-directional trimming / parameters

Posted: 2016-02-01T20:06:52-07:00
by snibgo
"mogrify" is great for simple processing of many files. When things get complicated, "convert" in a script loop is easier.

Code: Select all

convert -format %@ info:
That gives you what the trim would be. In the script, you can find the largest dimension. Then see if the other axis has that many pixels, so you can crop to a square and resize.