Help w/ uni-directional trimming / parameters

Questions and postings pertaining to the usage of ImageMagick regardless of the interface. This includes the command-line utilities, as well as the C and C++ APIs. Usage questions are like "How do I use ImageMagick to create drop shadows?".
Post Reply
SaveOurBolts
Posts: 1
Joined: 2016-02-01T19:22:45-07:00
Authentication code: 1151

Help w/ uni-directional trimming / parameters

Post 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
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Help w/ uni-directional trimming / parameters

Post 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.
snibgo's IM pages: im.snibgo.com
Post Reply