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?".
I want to resize all png files in directory to match heigth 190px, but some images less than 190 and some bigger. So I want to have if statement in bash script like this
for f in *.*
do
h=`identify -format %h $f` | if [ "$h" -gt 190 ]; then convert $f -strip -thumbnail x190 test/$f; fi ;
convert $f -strip -gravity center -extent x190 -transparent white test/$f;
done
So images that less than 190px height will be enlarged to 190px without increasing in width.
Images that bigger than 190px height will be resized to 190px.
But it seems that I have some problem here [ "$h" -gt 190 ]
So images that less than 190px height will be enlarged to 190px without increasing in width.
Perhaps I misunderstood. If you do what I said above with the resize, then you will distort the look of the images, if you force the width not to change, and resize only the height. Is that what you really want?
Or do you want to resize both dimensions to fit the 190 height and preserve aspect ration, but then crop or pad to the original width? You can do that by simply getting the image width before processing and then resize and extend.
images.sh: line 38: [: -gt: unary operator expected
I don't know why.
Anyway thanks for your help. I found good solution with you. The code below do the job.
A little bit more explanation for you to better understand my target. I have folder with png files with transparency. To have good looking web page I need all of them height 190px.
So if initial height less than 190px I just extent height adding transparent pixels and not distorting initial picture.
And if initial height greater than 190px I resize picture down to 190px height keeping aspect ratio. hope you understand me now.
for f in *.*
do
w=`convert $f -format "%w" info:`
h=`convert $f -format "%h" info:`
if [ $h -gt 190 ];
then convert $f -strip -transparent white -thumbnail x190 output/$f;
else convert $f -strip -gravity center -transparent white -extent ${w}x190 output/$f;
fi
done
You should remove the -transparent white unless there is white in your input image that you need to replace with transparent. The -background none does the extent with a transparent background.
This isn't a scripting foum, and I'm no expert on bash, but what arguments is smartresize() receiving? Put an echo at the start to see the first 3 arguments.