Page 1 of 1

ImageMagick is automatically rotating my watermark PNG

Posted: 2014-06-23T17:23:52-07:00
by gavin310
I'm trying to resize an uploaded image then add a watermark. My watermark is a transparent 24bit PNG that was created in Photoshop. The problem is when ImageMagick loads the watermark, it's rotated 90 degrees counter-clockwise. I can't figure out how to stop the PNG from rotating.

Code: Select all

convert uploadFile.jpg -resize "980x700^>" -quality 70 watermark.png -gravity southeast -geometry +30 -composite newFile.jpg
EDIT: I figured out the problem. I had a hunch to try with some different base photos and that was the problem. The images I was testing with were from an iPhone and it had rotation EXIF data. I still don't understand why ImageMagick would behave this way, but I guess it must have overlayed the composite image based on the base image's EXIF data? Why would it do that?

I changed the command to this and it worked, but I still don't understand why ImageMagick would rotate the composited image based on the base image's EXIF data. (notice the -auto-orient)

Code: Select all

convert uploadFile.jpg -resize "980x700^>" -auto-orient -quality 70 watermark.png -gravity southeast -geometry +30 -composite newFile.jpg

Re: ImageMagick is automatically rotating my watermark PNG

Posted: 2014-06-23T17:37:30-07:00
by fmw42
How are you viewing it? IM probably loses the JPG EXIF tag for auto-rotation during processing. So the original is perhaps auto-oriented and the output is not by your viewer. It is hard to know without having your files. IM is likely using the input data from the first (background image) and not the data from the watermark to transfer to the output.


But check

identify -verbose backgroundimage

and

identify -verbose watermarkimage

and

identify -verbose outputimage

and see what the EXIF data shows about rotation.


Try in Unix syntax

Code: Select all

convert \( uploadFile.jpg -auto-orient \) -resize "980x700^>" -quality 70 \( watermark.png -auto-orient \) -gravity southeast -geometry +30 -composite newFile.jpg

see http://www.imagemagick.org/script/comma ... uto-orient

Re: ImageMagick is automatically rotating my watermark PNG

Posted: 2014-06-23T17:52:06-07:00
by gavin310
Yep, I think you're right. See the edit I made to the post. It's just weird that the image wouldn't be imported rotated based on it's original rotation (not EXIF), since I didn't have auto-orient set. And that it does orient itself automatically after the watermark is applied.

Re: ImageMagick is automatically rotating my watermark PNG

Posted: 2014-06-23T18:21:21-07:00
by fmw42
As I mention, I think IM takes the first image in the command sequence to use for transferring any meta data. Since you have more than one image, it is going to be based upon the background image and not the watermark image.