mogrify -trim and -flatten in 1 command not working

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
seansan
Posts: 2
Joined: 2016-05-13T06:43:02-07:00
Authentication code: 1151

mogrify -trim and -flatten in 1 command not working

Post by seansan »

We are processing 500 images tiff and jpg using this command

Code: Select all

mogrify -path "PATH_TO\DONE" -trim -flatten -define jpeg:extent=500kb -format jpg -resize "1200x1200>" *.*
It should open all images, trim the image, flatten the image, resize to 1200px and then save in optimal jpg quality with a filesize lower than 500kb.

I thought I hadd it all working. Then I had to add -flatten to process the tiff files (otherwise 3 outputted files) and as a result the -trim stopped working on all images. Now the images are all OK, just not trimmed.

question: how can I force the trim command to work in this context?

Help appreciated
seansan
Posts: 2
Joined: 2016-05-13T06:43:02-07:00
Authentication code: 1151

Re: mogrify -trim and -flatten in 1 command not working

Post by seansan »

This seems to work but we don't know why repage is necessary here

Code: Select all

mogrify -path "PATH\DONE" -layers merge +repage -trim -resize "1200x1200>" -define jpeg:extent=500kb -format jpg *.*
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: mogrify -trim and -flatten in 1 command not working

Post by snibgo »

"-trim" creates canvas dimensions and offsets for each image, that gives the location of the trimmed area on the original image. "-layers merge" uses canvas dimensions and offsets for the alignment of layers. "+repage" removes canvas dimensions and offsets, so they will be aligned by top-left corners.

See documentation http://www.imagemagick.org/script/comma ... php#repage etc.
snibgo's IM pages: im.snibgo.com
Post Reply