railsguy wrote: ↑2017-05-21T10:59:51-07:00what i want to do is to trim out as much whitespace as possible but i want to maintain the aspect ratio and i want the photos width/height to stay the same... so there might still be some whitespace at the end.
This can be done pretty much in a single ImageMagick command. With IM 6.7.7-10 and working from the ubuntu bash shell on Windows 10 I can run this...
Code: Select all
convert input.jpg -write mpr:input -fill white -colorize 100 -fuzz 5% \
\( mpr:input -trim +repage \) \
-set option:orig "%[fx:(u.w/u.h<v.w/v.h)*s.w],%[fx:(u.w/u.h>v.w/v.h)*s.h]" \
-set option:dest "%[fx:(u.w/u.h<v.w/v.h)*u.w],%[fx:(u.w/u.h>v.w/v.h)*u.h]" \
-set option:distort:viewport "%[fx:u.w]x%[fx:u.h]" \
-virtual-pixel white -distort affine "0,0 0,0 %[orig] %[dest]" \
\( -clone 1 -trim +repage \) -delete 1 -gravity center -composite result.jpg
That will take any size image, make a white canvas of the same dimensions, trim the white off the original, resize the trimmed original as large as possible to fit within the original dimensions, and composite that sized and trimmed original centered on the white canvas.
Note the "-fuzz 5%" – you might want to adjust that if the "-trim" takes off more or less white than you want.
If you're concerned about quality for the output JPG, you might add "-quality 100" right before the output image name at the end, or even use a less lossy output format like PNG.
I'd probably run that from a script and set variables for the "input.jpg" and "result.jpg" file names.
There would be less complicated methods to do the same thing using IM7.