Possible bug: Not copying over all EXIF tags curing TIFF to JPEG conversion

Post any defects you find in the released or beta versions of the ImageMagick software here. Include the ImageMagick version, OS, and any command-line required to reproduce the problem. Got a patch for a bug? Post it here.
Post Reply
wumpus
Posts: 11
Joined: 2016-04-29T17:02:11-07:00
Authentication code: 1151

Possible bug: Not copying over all EXIF tags curing TIFF to JPEG conversion

Post by wumpus » 2017-09-11T23:15:15-07:00

I'm adding some standard EXIF tags, using ExifTool, to the TIFF files generated by my scanner tools. The ImageMagick convert tool is not copying the tags over when converting from TIFF to JPEG, namely:
  • DateTime (ModifyDate to exiftool)
  • DateTimeDigitized (CreateDate to exiftool)
  • DateTimeOriginal
I have a sample image IMG_20170912_0001.tif created by my Canon 9000F Mark II scanner and it's Canon IJ Scan Utility. ExifTool shows it contains the following tags:

Code: Select all

C:\TEMP\test>exiftool -v IMG_20170912_0001.tif
  ExifToolVersion = 10.61
  FileName = IMG_20170912_0001.tif
  Directory = .
  FileSize = 5303788
  FileModifyDate = 1505192941.45003
  FileAccessDate = 1505192958.3514
  FileCreateDate = 1505192958.3514
  FilePermissions = 33206
  FileType = TIFF
  FileTypeExtension = TIF
  MIMEType = image/tiff
  ExifByteOrder = II
  + [IFD0 directory with 14 entries]
  | 0)  SubfileType = 0
  | 1)  ImageWidth = 1788
  | 2)  ImageHeight = 988
  | 3)  BitsPerSample = 8 8 8
  | 4)  Compression = 1
  | 5)  PhotometricInterpretation = 2
  | 6)  StripOffsets = 8 10736 21464 32192 42920 53648 64376 75104 85832 96560 107288 1[snip]
  | 7)  SamplesPerPixel = 3
  | 8)  RowsPerStrip = 2
  | 9)  StripByteCounts = 10728 10728 10728 10728 10728 10728 10728 10728 10728 10728 1[snip]
  | 10) XResolution = 300 (300000/1000)
  | 11) YResolution = 300 (300000/1000)
  | 12) PlanarConfiguration = 1
  | 13) ResolutionUnit = 2
If I convert it using ImageMagick:

Code: Select all

C:\TEMP\test>convert -version
Version: ImageMagick 7.0.6-0 Q16 x64 2017-06-11 http://www.imagemagick.org
Copyright: Copyright (C) 1999-2015 ImageMagick Studio LLC
License: http://www.imagemagick.org/script/license.php
Visual C++: 180040629
Features: Cipher DPC Modules OpenMP
Delegates (built-in): bzlib cairo flif freetype jng jp2 jpeg lcms lqr openexr pangocairo png ps rsvg tiff webp xml zlib

C:\TEMP\test>convert IMG_20170912_0001.tif -quality 95 IMG_20170912_0001.jpg
ExifTool shows the converted JPEG file contains the following tags:

Code: Select all

C:\TEMP\test>exiftool -v IMG_20170912_0001.jpg
  ExifToolVersion = 10.61
  FileName = IMG_20170912_0001.jpg
  Directory = .
  FileSize = 1166897
  FileModifyDate = 1505193588.30088
  FileAccessDate = 1505193588.23837
  FileCreateDate = 1505193468.87307
  FilePermissions = 33206
  FileType = JPEG
  FileTypeExtension = JPG
  MIMEType = image/jpeg
JPEG APP0 (14 bytes):
  + [BinaryData directory, 9 bytes]
  | JFIFVersion = 1 1
  | ResolutionUnit = 1
  | XResolution = 300
  | YResolution = 300
  | ThumbnailWidth = 0
  | ThumbnailHeight = 0
JPEG DQT (65 bytes):
JPEG DQT (65 bytes):
JPEG SOF0 (15 bytes):
  ImageWidth = 1788
  ImageHeight = 988
  EncodingProcess = 0
  BitsPerSample = 8
  ColorComponents = 3
JPEG DHT (28 bytes):
JPEG DHT (85 bytes):
JPEG DHT (27 bytes):
JPEG DHT (93 bytes):
JPEG SOS
Now if I copy the original TIFF file and use ExifTool to add the DateTime, DateTimeDigitized and DateTimeOriginal tags:

Code: Select all

C:\TEMP\test>copy IMG_20170912_0001.tif IMG_20170912_0002.tif
        1 file(s) copied.

C:\TEMP\test>exiftool -exif:DateTimeOriginal="20170912 00:00:00" -exif:CreateDate="20170912 00:00:00" -exif:ModifyDate="20170912 00:00:00" IMG_20170912_0002.tif
    1 image files updated
ExifTool shows the new TIFF to have the following tags (which include the newly added tags):

Code: Select all

C:\TEMP\test>exiftool -v IMG_20170912_0002.tif
  ExifToolVersion = 10.61
  FileName = IMG_20170912_0002.tif
  Directory = .
  FileSize = 5303950
  FileModifyDate = 1505193366.22399
  FileAccessDate = 1505193366.20836
  FileCreateDate = 1505193007.81244
  FilePermissions = 33206
  FileType = TIFF
  FileTypeExtension = TIF
  MIMEType = image/tiff
  ExifByteOrder = II
  + [IFD0 directory with 16 entries]
  | 0)  SubfileType = 0
  | 1)  ImageWidth = 1788
  | 2)  ImageHeight = 988
  | 3)  BitsPerSample = 8 8 8
  | 4)  Compression = 1
  | 5)  PhotometricInterpretation = 2
  | 6)  StripOffsets = 4318 15046 25774 36502 47230 57958 68686 79414 90142 100870 1115[snip]
  | 7)  SamplesPerPixel = 3
  | 8)  RowsPerStrip = 2
  | 9)  StripByteCounts = 10728 10728 10728 10728 10728 10728 10728 10728 10728 10728 1[snip]
  | 10) XResolution = 300 (300000/1000)
  | 11) YResolution = 300 (300000/1000)
  | 12) PlanarConfiguration = 1
  | 13) ResolutionUnit = 2
  | 14) ModifyDate = 2017:09:12 00:00:00
  | 15) ExifOffset (SubDirectory) -->
  | + [ExifIFD directory with 6 entries]
  | | 0)  ExifVersion = 0231
  | | 1)  DateTimeOriginal = 2017:09:12 00:00:00
  | | 2)  CreateDate = 2017:09:12 00:00:00
  | | 3)  ComponentsConfiguration = 1 2 3 0
  | | 4)  FlashpixVersion = 0100
  | | 5)  ColorSpace = 65535
If I now convert that new TIFF to JPEG using ImageMagick and look at the tags in that JPEG file, the new tags in the TIFF file aren't the resultant JPEG file:

Code: Select all

C:\TEMP\test>convert IMG_20170912_0002.tif -quality 95 IMG_20170912_0002.jpg

C:\TEMP\test>exiftool -v IMG_20170912_0002.jpg
  ExifToolVersion = 10.61
  FileName = IMG_20170912_0002.jpg
  Directory = .
  FileSize = 1166897
  FileModifyDate = 1505193772.48408
  FileAccessDate = 1505193772.4216
  FileCreateDate = 1505193772.4216
  FilePermissions = 33206
  FileType = JPEG
  FileTypeExtension = JPG
  MIMEType = image/jpeg
JPEG APP0 (14 bytes):
  + [BinaryData directory, 9 bytes]
  | JFIFVersion = 1 1
  | ResolutionUnit = 1
  | XResolution = 300
  | YResolution = 300
  | ThumbnailWidth = 0
  | ThumbnailHeight = 0
JPEG DQT (65 bytes):
JPEG DQT (65 bytes):
JPEG SOF0 (15 bytes):
  ImageWidth = 1788
  ImageHeight = 988
  EncodingProcess = 0
  BitsPerSample = 8
  ColorComponents = 3
JPEG DHT (28 bytes):
JPEG DHT (85 bytes):
JPEG DHT (27 bytes):
JPEG DHT (93 bytes):
JPEG SOS
But I can add them back to the new JPEG file using ExifTool again:

Code: Select all

C:\TEMP\test>exiftool -exif:DateTimeOriginal="20170912 00:00:00" -exif:CreateDate="20170912 00:00:00" -exif:ModifyDate="20170912 00:00:00" IMG_20170912_0002.jpg
    1 image files updated

C:\TEMP\test>exiftool -v IMG_20170912_0002.jpg
  ExifToolVersion = 10.61
  FileName = IMG_20170912_0002.jpg
  Directory = .
  FileSize = 1167147
  FileModifyDate = 1505194089.85091
  FileAccessDate = 1505194089.83525
  FileCreateDate = 1505193772.4216
  FilePermissions = 33206
  FileType = JPEG
  FileTypeExtension = JPG
  MIMEType = image/jpeg
JPEG APP0 (14 bytes):
  + [BinaryData directory, 9 bytes]
  | JFIFVersion = 1 1
  | ResolutionUnit = 1
  | XResolution = 300
  | YResolution = 300
  | ThumbnailWidth = 0
  | ThumbnailHeight = 0
JPEG APP1 (246 bytes):
  ExifByteOrder = MM
  + [IFD0 directory with 6 entries]
  | 0)  XResolution = 300 (300/1)
  | 1)  YResolution = 300 (300/1)
  | 2)  ResolutionUnit = 2
  | 3)  ModifyDate = 2017:09:12 00:00:00
  | 4)  YCbCrPositioning = 1
  | 5)  ExifOffset (SubDirectory) -->
  | + [ExifIFD directory with 6 entries]
  | | 0)  ExifVersion = 0231
  | | 1)  DateTimeOriginal = 2017:09:12 00:00:00
  | | 2)  CreateDate = 2017:09:12 00:00:00
  | | 3)  ComponentsConfiguration = 1 2 3 0
  | | 4)  FlashpixVersion = 0100
  | | 5)  ColorSpace = 65535
JPEG DQT (65 bytes):
JPEG DQT (65 bytes):
JPEG SOF0 (15 bytes):
  ImageWidth = 1788
  ImageHeight = 988
  EncodingProcess = 0
  BitsPerSample = 8
  ColorComponents = 3
JPEG DHT (28 bytes):
JPEG DHT (85 bytes):
JPEG DHT (27 bytes):
JPEG DHT (93 bytes):
JPEG SOS
Why doesn't the ImageMagick convert tool preserve the tags from the TIFF file into the new JPEG file?

EDIT: Added link to test TIFF
Last edited by wumpus on 2017-09-12T13:30:54-07:00, edited 2 times in total.

User avatar
dlemstra
Posts: 1386
Joined: 2013-05-04T15:28:54-07:00
Authentication code: 6789
Contact:

Re: Possible bug: Not copying over all EXIF tags curing TIFF to JPEG conversion

Post by dlemstra » 2017-09-12T11:47:34-07:00

Can you add a link to your test image so we can reproduce your issue?
.NET + ImageMagick = Magick.NET https://github.com/dlemstra/Magick.NET, @MagickNET, Donate

wumpus
Posts: 11
Joined: 2016-04-29T17:02:11-07:00
Authentication code: 1151

Re: Possible bug: Not copying over all EXIF tags curing TIFF to JPEG conversion

Post by wumpus » 2017-09-12T11:53:52-07:00

dlemstra wrote:
2017-09-12T11:47:34-07:00
Can you add a link to your test image so we can reproduce your issue?
oops. didn't see this. I added it to the top of my post just now. Sorry.

User avatar
dlemstra
Posts: 1386
Joined: 2013-05-04T15:28:54-07:00
Authentication code: 6789
Contact:

Re: Possible bug: Not copying over all EXIF tags curing TIFF to JPEG conversion

Post by dlemstra » 2017-09-12T13:21:40-07:00

It looks like your image was "stripped" it does not contain an exif profile anymore. You might want to use something like onedrive/dropbox instead.
.NET + ImageMagick = Magick.NET https://github.com/dlemstra/Magick.NET, @MagickNET, Donate

wumpus
Posts: 11
Joined: 2016-04-29T17:02:11-07:00
Authentication code: 1151

Re: Possible bug: Not copying over all EXIF tags curing TIFF to JPEG conversion

Post by wumpus » 2017-09-12T13:31:20-07:00

Grrrr.... Let's try dropbox

User avatar
dlemstra
Posts: 1386
Joined: 2013-05-04T15:28:54-07:00
Authentication code: 6789
Contact:

Re: Possible bug: Not copying over all EXIF tags curing TIFF to JPEG conversion

Post by dlemstra » 2017-09-12T14:00:54-07:00

It looks like the exif information is not stored inside the `TIFFTAG_EXIFIFD` but somewhere else. I have no clue where exiftool is finding the information. And the profile cannot be read because the information is not stored in that tag.
.NET + ImageMagick = Magick.NET https://github.com/dlemstra/Magick.NET, @MagickNET, Donate

wumpus
Posts: 11
Joined: 2016-04-29T17:02:11-07:00
Authentication code: 1151

Re: Possible bug: Not copying over all EXIF tags curing TIFF to JPEG conversion

Post by wumpus » 2017-09-12T14:08:48-07:00

You're not seeing any exif data... even from the original file? If I upload the exiftool-modified JPEG file to Google Photos, it seems to read the EXIF data fine (as the date is shown correctly). Very odd.

User avatar
dlemstra
Posts: 1386
Joined: 2013-05-04T15:28:54-07:00
Authentication code: 6789
Contact:

Re: Possible bug: Not copying over all EXIF tags curing TIFF to JPEG conversion

Post by dlemstra » 2017-09-12T14:39:59-07:00

The tiff decoder cannot find the exif information. I have no idea how the exiftool is finding the information.
.NET + ImageMagick = Magick.NET https://github.com/dlemstra/Magick.NET, @MagickNET, Donate

wumpus
Posts: 11
Joined: 2016-04-29T17:02:11-07:00
Authentication code: 1151

Re: Possible bug: Not copying over all EXIF tags curing TIFF to JPEG conversion

Post by wumpus » 2017-09-12T14:40:21-07:00

That was a dumb comparison. Sorry. I was just surprised. nconvert from XnView passes the tags through the conversion, as does IrfanView.

User avatar
dlemstra
Posts: 1386
Joined: 2013-05-04T15:28:54-07:00
Authentication code: 6789
Contact:

Re: Possible bug: Not copying over all EXIF tags curing TIFF to JPEG conversion

Post by dlemstra » 2017-09-12T14:57:20-07:00

Looks like I was testing with the wrong file. I do get the following exif information after I add it with exiftool:

Code: Select all

  Properties:
    date:create: 2017-09-12T22:44:11+02:00
    date:modify: 2017-09-12T22:45:47+02:00
    exif:DateTimeDigitized: 2017:09:12 00:00:00
    exif:DateTimeOriginal: 2017:09:12 00:00:00
But the way we store them on the image is not in the form of an exif profile and that is why it doesn't end up in the JPEG file. We store the fields as separate 'attributes' on the image. We will need to change our code to create an exif profile instead. I have given this a try in the past but I failed. I might give it another try in the future.
.NET + ImageMagick = Magick.NET https://github.com/dlemstra/Magick.NET, @MagickNET, Donate

wumpus
Posts: 11
Joined: 2016-04-29T17:02:11-07:00
Authentication code: 1151

Re: Possible bug: Not copying over all EXIF tags curing TIFF to JPEG conversion

Post by wumpus » 2017-09-12T15:20:39-07:00

Cool. As long as it's been identified. At least I'm not crazy.

I'll use nconvert for now as IrfanView has an issue on how it passes a couple of the other tags through (StripOffsets & StripByteCounts if I remember correctly) and I'll keep checking new ImageMagick versions changelogs.

Thanks, eh?

Post Reply