Page 1 of 1

How to use extent conditionally, based on image size?

Posted: 2017-09-25T08:07:42-07:00
by TheBladeRoden
I figured out how to enlarge only pictures that are smaller than 1440x900, but the same technique doesn't work for extent (i.e. it will clip a 1600x1080 picture down to 1440x900 instead of leaving it alone)

Code: Select all

mogrify -path results -resize 1440x900^< -extent 1440x900^< -background black -gravity center -quality 95 *.jpg
PAUSE
I'm using version 7.0.7 with a Windows bat file.

Re: How to use extent conditionally, based on image size?

Posted: 2017-09-25T08:39:35-07:00
by snibgo
In v7, you can put fx: expressions in the extent, such as something like this (untested):

Code: Select all

-extent "%[fx:w<1440?1440:w]x%[fx:h<900?900:h]"
For Window BAT, double the % signs.

Re: How to use extent conditionally, based on image size?

Posted: 2017-09-25T08:41:45-07:00
by GeeMack
TheBladeRoden wrote: 2017-09-25T08:07:42-07:00I figured out how to enlarge only pictures that are smaller than 1440x900, but the same technique doesn't work for extent (i.e. it will clip a 1600x1080 picture down to 1440x900 instead of leaving it alone).
My testing seems to indicate that "mogrify" isn't compatible with FX expressions, so I'd probably run the process as a "for" loop using "magick" instead of "mogrify". Something like this in a BAT script should do pretty much what you're trying to accomplish...

Code: Select all

for %%I in ( *.jpg ) do (
   magick "%%I" -set filename: "%%[t]" -resize 1440x900^< -gravity center ^
   -background black -extent "%%[fx:max(w,1440)]x%%[fx:max(h,900)]" "result\%%[filename:].jpg"
)

Re: How to use extent conditionally, based on image size?

Posted: 2017-09-25T10:09:20-07:00
by fmw42
Only magick (replacement for convert) allows %[fx: ...] computation inline for arguments. Mogrify, montage, etc do not.

Re: How to use extent conditionally, based on image size?

Posted: 2017-09-25T14:35:39-07:00
by TheBladeRoden
GeeMack wrote: 2017-09-25T08:41:45-07:00
TheBladeRoden wrote: 2017-09-25T08:07:42-07:00I figured out how to enlarge only pictures that are smaller than 1440x900, but the same technique doesn't work for extent (i.e. it will clip a 1600x1080 picture down to 1440x900 instead of leaving it alone).
My testing seems to indicate that "mogrify" isn't compatible with FX expressions, so I'd probably run the process as a "for" loop using "magick" instead of "mogrify". Something like this in a BAT script should do pretty much what you're trying to accomplish...

Code: Select all

for %%I in ( *.jpg ) do (
   magick "%%I" -set filename: "%%[t]" -resize 1440x900^< -gravity center ^
   -background black -extent "%%[fx:max(w,1440)]x%%[fx:max(h,900)]" "result\%%[filename:].jpg"
)
Hey that worked out pretty well, thanks!