Preserving EXIF information from JPG to TIF

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
posterChild

Preserving EXIF information from JPG to TIF

Post by posterChild »

I'm trying to convert JPEG files to TIFF files (specifically, ptif) and would like to retain the EXIF data. I've tried several different examples and none seem to preserve the EXIF information, although the documentation suggests it should be automatic.

Using the example image found here:

http://www.imagemagick.org/Usage/photos/#exif

I execute the following:

Code: Select all

identify -format %[EXIF:*] pagoda_sm.jpg
And receive the same output as on the example page. Then, if I convert the image like so:

Code: Select all

convert pagoda_sm.jpg pagoda_sm.tif
and then execute:

Code: Select all

identify -format %[EXIF:*] pagoda_sm.tif
I get no output. Opening the file with an "EXIF Viewer" also shows the file contains no EXIF information. However, if I perform a resize operation on the original JPG to a new JPG, the EXIF information is preserved:

Code: Select all

convert -resize 60x60 pagoda_sm.jpg pagoda_sm-resized.jpg
identify -format %[EXIF:*] pagoda_sm-resized.jpg
Any suggestions on how to preserve the information between file type conversions? I have tried the +/-profile option in various combinations, but haven't had any luck thus far with that either.

This is on WIndows 7 x64

Version: ImageMagick 6.6.3-7 2010-08-14 Q8 http://www.imagemagick.org
Copyright: Copyright (C) 1999-2010 ImageMagick Studio LLC
Features: OpenMP
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Preserving EXIF information from JPG to TIF

Post by fmw42 »

try

convert pagoda_sm.jpg -taint pagoda_sm.tif

or

convert pagoda_sm.jpg -distort SRT 0 pagoda_sm.tif

The latter is a no-op affine transformation (no rotation, no scale, no translate)
posterChild

Re: Preserving EXIF information from JPG to TIF

Post by posterChild »

Thank you for the quick reply. I tried both of those options with no luck. Is the expected output that it would/does preserve the EXIF data? Is this possibly a bug or am doing something wrong/using it wrong?

Code: Select all

C:\tmp>del *.tif
Could Not Find C:\tmp\*.tif

C:\tmp>dir pagoda_sm.jpg
 Volume in drive C has no label.
 Volume Serial Number is 1813-F908

 Directory of C:\tmp

08/03/2008  10:15 PM            69,165 pagoda_sm.jpg
               1 File(s)         69,165 bytes
               0 Dir(s)  32,014,856,192 bytes free

C:\tmp>convert pagoda_sm.jpg -taint pagoda_sm.tif

C:\tmp>identify -format %[EXIF:*] pagoda_sm.tif


C:\tmp>convert pagoda_sm.jpg -distort SRT 0 pagoda_sm.tif

C:\tmp>identify -format %[EXIF:*] pagoda_sm.tif


C:\tmp>identify -format %[EXIF:*] pagoda_sm.jpg
exif:ColorSpace=1
exif:ComponentsConfiguration=1, 2, 3, 0
exif:CompressedBitsPerPixel=4/1
exif:Compression=6
exif:Contrast=0
exif:CustomRendered=0
exif:DateTime=2005:07:09 14:05:15
exif:DateTimeDigitized=2005:07:09 14:05:15
exif:DateTimeOriginal=2005:07:09 14:05:15
exif:DigitalZoomRatio=0/10
exif:ExifImageLength=1728
exif:ExifImageWidth=2304
exif:ExifOffset=198
exif:ExifVersion=48, 50, 50, 48
exif:ExposureBiasValue=66/100
exif:ExposureMode=0
exif:ExposureProgram=2
exif:ExposureTime=10/800
exif:FileSource=3
exif:Flash=24
exif:FlashPixVersion=48, 49, 48, 48
exif:FNumber=56/10
exif:FocalLength=61/10
exif:FocalLengthIn35mmFilm=37
exif:GainControl=0
exif:InteroperabilityIndex=R98
exif:InteroperabilityOffset=6432
exif:InteroperabilityVersion=48, 49, 48, 48
exif:ISOSpeedRatings=64
exif:LightSource=0
exif:Make=Panasonic
exif:MakerNote=80, 97, 110, 97, ... SNIPPED
exif:MaxApertureValue=30/10
exif:MeteringMode=5
exif:Model=DMC-LZ1
exif:Orientation=1
exif:ResolutionUnit=2
exif:Saturation=0
exif:SceneCaptureType=0
exif:SceneType=1
exif:SensingMethod=2
exif:Sharpness=0
exif:Software=Ver.1.0
exif:WhiteBalance=0
exif:XResolution=72/1
exif:YCbCrPositioning=2
exif:YResolution=72/1


C:\tmp>
Thanks again for the quick reply!
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Preserving EXIF information from JPG to TIF

Post by fmw42 »

I am surprised that it does not, especially since when you resize it does. That was why I had you do some operation that tells IM that the image has changed. So I would think (but am not sure) that this is a bug.

Can you post a link to your input image?
posterChild

Re: Preserving EXIF information from JPG to TIF

Post by posterChild »

I used the image in the EXIF documentation/example from the ImageMagick site, as I knew someone would want to play with it:

http://www.imagemagick.org/Usage/photos/pagoda_sm.jpg

It would be great to identify if there is a problem with this and/or if there is a work around, even if it is manually stitching the information back into the resulting TIFF 'manually' using a second operation.

Thanks again for the attention!
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Preserving EXIF information from JPG to TIF

Post by fmw42 »

It would be great to identify if there is a problem with this and/or if there is a work around, even if it is manually stitching the information back into the resulting TIFF 'manually' using a second operation.
At least some of it could be written back into the tif file using exiftool, I would think.

By the way, resizing for me does not preserve the exif data in the IM identify -verbose information nor by using exiftool. Only some of it, the basic info is shown in exiftool.
Drarakel
Posts: 547
Joined: 2010-04-07T12:36:59-07:00
Authentication code: 8675308

Re: Preserving EXIF information from JPG to TIF

Post by Drarakel »

The EXIF tags were preserved in the 'resize command', as it was only an example to show that JPG->JPG commands do preserve it, but not with JPG->TIF.

I think, the problem is, that the EXIF tags in JPG are read as 'exif:' attributes in ImageMagick - but the EXIF tags in TIFF are treated as 'tiff:' attributes. ImageMagick would have to map its 'exif:' attributes to 'tiff:' attributes (or from 'tiff:' to 'exif:' in conversions from TIF to JPG, for example). Theoretically, you can do part of that yourself, by first reading all the EXIF tags, and then specifying them as additional attributes in the following conversion (example with one of the tags: "convert pagoda_sm.jpg -set tiff:make Panasonic pagoda_sm.tif").
Of course, it will be MUCH easier to do that with ExifTool:

Code: Select all

convert pagoda_sm.jpg -compress zip -quality 95 pagoda_sm.tif
exiftool -tagsFromFile pagoda_sm.jpg -All:All --IFD1:All pagoda_sm.tif
(In this special example, the IFD1 part in the source EXIF profile doesn't look complete, so I would leave this part out. Otherwise, ImageMagick complains about the resulting TIFF file. Additionally, ExifTool complains about the offset of the MakerNotes. But this is only a result of this special source file - and it's probably not a severe problem.)
Last edited by Drarakel on 2010-08-23T12:29:33-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: Preserving EXIF information from JPG to TIF

Post by fmw42 »

It seems like the exif data is preserved if you convert (without processing) from jpg to jpg or jpg to png, but not from jpg to tif or jpg to psd.
posterChild

Re: Preserving EXIF information from JPG to TIF

Post by posterChild »

Thanks again for the follow up and additional testing. I guess given how insanely capable Imagemagick is, the idea of transferring exif: to tiff: attributes didn't seem that complex and I assumed it was 'built in'. I suppose the documentation should be updated to reflect that this capability doesn't currently exist as well as clarify which conversion do preserve the data.

I'm doing all of these translations programatically, so adding another call to exiftool may work, or may increase the complexity too much to worry about. Using just convert, is there a way to supply the exif data as tiff attributes via a 'profile'?

As a side note, is this a reasonable feature request item to put in for? Unfortunately, I'm not super familiar with all the image formats, so I don't know what the compatibility/conversion matrix looks like between JPEG EXIF and all other image containers/formats. I did think there was a reserved place in a TIFF for EXIF data though. In any case, should this be officially requested somehow?

posterChild
Drarakel
Posts: 547
Joined: 2010-04-07T12:36:59-07:00
Authentication code: 8675308

Re: Preserving EXIF information from JPG to TIF

Post by Drarakel »

Just as an update - I think that this ExifTool command could be better suited for re-inserting the EXIF tags into TIFF:

Code: Select all

exiftool -EXIF:XResolution= -EXIF:YResolution= -EXIF:ResolutionUnit= -IPTC:All= -tagsFromFile image.jpg -EXIF:All --IFD1:All -IPTC:All image.tif
(The other profiles should already be preserved by ImageMagick. I've also added some special treatment for the density and the IPTC profile, as there could be some minor problems with that when IM converts from JPG to TIFF.)
One probably should also check the return code/errorlevel after these commands, as with some files, there might be errors that would hinder ExifTool from inserting the tags.
posterChild wrote:Using just convert, is there a way to supply the exif data as tiff attributes via a 'profile'?
You can save the EXIF profile with ImageMagick. But it won't help you. Example:

Code: Select all

convert pagoda_sm.jpg -compress zip -quality 95 pagoda_sm.tif
convert pagoda_sm.jpg exif:pagoda.exif
mogrify -set profile exif:pagoda.exif pagoda_sm.tif
The last command would work for a JPG file. But not for a TIFF file - as ImageMagick doesn't know a separate EXIF "profile" in TIFF (only some tiff: attributes). Of course, simply replacing the whole profile would be problematic, too, as part of the EXIF tags in TIFF contain the main header values.

By the way: According to the documentation, there is a "-define tiff:exif=true" option for TIFF files ('to read the EXIF profile'). But in a current ImageMagick, it doesn't seem to make a difference.

So, maybe the handling of the EXIF tags with TIFF could be improved in ImageMagick. (Maybe, libtiff would have to be adjusted, too. Though, libtiff itself seems to be able to at least read all the EXIF tags/MakerNotes in a TIFF file.)
posterChild wrote:In any case, should this be officially requested somehow?
A request shouldn't hurt. :)
posterChild

Re: Preserving EXIF information from JPG to TIF

Post by posterChild »

Thanks for the additional examples Drarakel. I think I may end up using exiftool in the manner you suggested if we end up taking all the EXIF data. Thank you also for showing an example of how to set a single exif attribute in a TIFF. This may end up being all I need to accomplish the end goal, as I may only need cherry picked attributes.

I do appreciate all the help and attention to my inquiry. I wish more communities were are nice, welcoming, and helpful as you guys have been.

Oh, and any suggestions about how one might make an 'official' request for a feature?

Cheers,

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

Re: Preserving EXIF information from JPG to TIF

Post by fmw42 »

Oh, and any suggestions about how one might make an 'official' request for a feature?
Post the suggestion to the Developers forum and put a link back to this topic discussion
Post Reply