If you are on Linux/OSX, you can get the image dimensions like this:
identify -format "%w %h" input.jpg
So, if you want the width and height in variables w
and h
, do this:
read w h < <(identify -format "%w %h" input.jpg)
Now you can test the width and height and do further processing if necessary:
[ $w -gt 300 -o $h -gt 100 ] && convert input.jpg -set units ...
Or, if you want to be more verbose:
if [ $w -gt 300 -o $h -gt 100 ]; then
convert ...
fi
So, the total solution I am proposing looks like this:
#!/usr/bin/bash
read w h < <(identify -format "%w %h" input.jpg)
[ $w -gt 300 -o $h -gt 100 ] && convert input.jpg -set units ...
JPEG
or PNG
makes no difference, so just replace my JPG
with PNG
if that is the format of your choice.
Updated for Windows
Ok, no-one else is helping so I will get out my (very) rusty Windows skills. Get the image width something like this under Windows:
identify -format "%w" input.png > w.txt
set /p w=<w.txt
Now get the height:
identify -format "%h" input.png > h.txt
set /p h=<h.txt
You should now have the width and height of image input.png
in 2 variables, w
and h
, check by typing
echo %w%
echo %h%
Now you need to do some IF
statements:
if %w% LEQ 300 GOTO SKIP
if %h% LEQ 100 GOTO SKIP
convert ....
:SKIP
Note:: You may need ^
in front of the percent sign in Windows.
Note: You may need double @
signs in scripts because Windows is illogical.