ImageMagick is automatically rotating my watermark PNG

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
gavin310
Posts: 2
Joined: 2014-06-23T17:20:07-07:00
Authentication code: 6789

ImageMagick is automatically rotating my watermark PNG

Post 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
Last edited by gavin310 on 2014-06-23T17:46:02-07:00, edited 1 time in total.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: ImageMagick is automatically rotating my watermark PNG

Post 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
gavin310
Posts: 2
Joined: 2014-06-23T17:20:07-07:00
Authentication code: 6789

Re: ImageMagick is automatically rotating my watermark PNG

Post 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.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: ImageMagick is automatically rotating my watermark PNG

Post 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.
Post Reply