-auto-orient not updating Exif

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
southbayriders

-auto-orient not updating Exif

Post by southbayriders »

When I use the following command to auto orient pictures, the picture is correctly oriented, but the Exif data is not updated.

mogrify -auto-orient -quality 80% /home/path/to/my/picture.jpg

When I take a picture with an iPhone holding the phone in the portrait position, the Exif shows the orientation as Right/Top. If I post this image to a forum and view the picture with an iPhone the picture is shows correctly. But if I view the image using a desktop computer (using Firefox or similar browser) the picture is shown sidways.

So if I use -auto-orient command, it properly flips the image and viewing with a desktop browser the picture displays properly, but now if if I view the same picture using an iPhone the picture is sideways.

The problem I think is that after I run the -auto-orient command the Exif data is not updated. The original picture Exif shows Right/Top where the Exif data after using the -auto-orient should have been updated to show Top/Left.

Is there any way to update the Exif data when the -auto-orient command is issued?

I'm running the latest version of ImageMagick 6.6.3-2 on a Centos 5.4 server.

Thank you for a great program.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: -auto-orient not updating Exif

Post by fmw42 »

Suggest you do a single image test with convert and see if that works. If so, then the issue is with the old mogrify. If so report it as a bug in the Bugs forum. Barring a fix, you can, I believe, use exiftool to update the exif information (outside of IM).

You can check your image to see about the orientation using string formats for exif tags. see http://www.imagemagick.org/script/escape.php

convert image -format "%[exif:orientation]" info:

I believe is the syntax.
southbayriders

Re: -auto-orient not updating Exif

Post by southbayriders »

fmw42 wrote:Suggest you do a single image test with convert and see if that works. If so, then the issue is with the old mogrify. If so report it as a bug in the Bugs forum. Barring a fix, you can, I believe, use exiftool to update the exif information (outside of IM).

You can check your image to see about the orientation using string formats for exif tags. see http://www.imagemagick.org/script/escape.php

convert image -format "%[exif:orientation]" info:

I believe is the syntax.
Hi Fred,

Thank you for your suggestions, they really helped.

My problem was that I was using the php exec command to invoke ImageMagick. For example I was using:

exec('mogrify -auto-orient -quality 80% /home/path/to/my/picture.jpg');

The problem apparently is that exec commands called from within vBulletin the forum software I was calling it from just doesn't work right. So now I use a cURL command to call a simple script and all works perfect. The morgify command properly does the -auto-orient in that it updates the Exif data to show Top/Left as it should.

Thanks again for your help.

Andy
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: -auto-orient not updating Exif

Post by fmw42 »

when using exec in PHP, one often has to provide convert or mogrify with the full path to it. So for example when I use PHP I have to use

exec('/usr/local/bin/convert ... ')

Some external tools that work with PHP/IM, also need to know where IM resides, but you may not be able to provide that to them unless as above.

try

system('which convert')

or

system('type convert')

to find out where IM resides for use with PHP.
southbayriders

Re: -auto-orient not updating Exif

Post by southbayriders »

fmw42 wrote:when using exec in PHP, one often has to provide convert or mogrify with the full path to it. So for example when I use PHP I have to use

exec('/usr/local/bin/convert ... ')

Some external tools that work with PHP/IM, also need to know where IM resides, but you may not be able to provide that to them unless as above.

try

system('which convert')

or

system('type convert')

to find out where IM resides for use with PHP.
Hi Fred,

You are awesome. That was the problem alright. By putting the path in for mogrify as you suggested my code works perfectly.

Thank you so kindly for taking the time to expertly troubleshoot my problem.
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: -auto-orient not updating Exif

Post by anthony »

southbayriders wrote:When I use the following command to auto orient pictures, the picture is correctly oriented, but the Exif data is not updated.

Code: Select all

mogrify -auto-orient -quality 80% /home/path/to/my/picture.jpg
Asside from the solution about PHP execution paths. The above is a BAD idea!

JPEG image file format is a lossy format. Reading the image data and writing it again as ImageMagick does, will cause the image to degrade.

The -auto-orient is ment to be used when you are processing the JPEG in some way that requires data manipulation. For example making thumbnails, or doing perspective. In the above repeated mogrifies will make the image worse and worse.

The solution is to use a JPEG file format specific program to fix the orientation such that the image data itself is not read and re-written. "jhead" is probably one of the most common solutions.

Code: Select all

  jhead -autorot  /home/path/to/my/picture.jpg
See IM Examples Photo Handling, orientation,
http://www.imagemagick.org/Usage/photos/#orient

JHead Home page (its probably in your package management library)
http://www.sentex.net/~mwandel/jhead/
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
Drarakel
Posts: 547
Joined: 2010-04-07T12:36:59-07:00
Authentication code: 8675308

Re: -auto-orient not updating Exif

Post by Drarakel »

anthony wrote:Asside from the solution about PHP execution paths. The above is a BAD idea!
I wouldn't be that harsh. :)
The complete JPG recompression after rotating an image can be ok - it can degrade the quality, but at least it works in every case without further problems.
Lossless JPG rotation doesn't degrade the quality, but it won't work without problems for some files (files that have partial JPG blocks). If you have such files, jhead, for example, might move the right and/or lower border to the opposite side. That might look odd. :wink:
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: -auto-orient not updating Exif

Post by anthony »

Drarakel wrote:Lossless JPG rotation doesn't degrade the quality, but it won't work without problems for some files (files that have partial JPG blocks). If you have such files, jhead, for example, might move the right and/or lower border to the opposite side. That might look odd. :wink:
You you have an example of jhead doing that? I have never seen it.
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
Drarakel
Posts: 547
Joined: 2010-04-07T12:36:59-07:00
Authentication code: 8675308

Re: -auto-orient not updating Exif

Post by Drarakel »

That gets a bit off-topic.. But ok. I'll take the Taj Mahal image as example:
Image

I made a rotated version out of it (with orientation tag included):
Image

Now with "jhead -autorot image.jpg" on the last file, the result is this:
Image
(By the way: jhead strips the JFIF header.)

With this example, the 'error' doesn't even catch one's eye instantly. But look closer: The tower on the very left has moved to the right side. :wink:
That's not a bug - that's just the way lossless JPG rotation has to work, as partial JPG blocks can only reside at the right and lower border. (There are some alternatives in how the partial blocks are dealt with.)
Of course, you won't have problems if you're using lossless rotation only for pictures with only complete blocks (sizes dividable by 8 or 16) - which should be the case for most (but not all) digicams, I guess.
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: -auto-orient not updating Exif

Post by anthony »

Thanks.

I have added a warning about it in IM Examples, Digital Photo Orientation
with a link directly to the above article.
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
Post Reply