Issue somewhere between Piexif and Exiftool

Started by BigHandsome, August 03, 2016, 07:08:01 AM

Previous topic - Next topic

BigHandsome

System Type: OS X 10.11.6 (15G31)
Exiftool Version: 10.24
Specific Command: exiftool -ProfileCopyright Test.jpg
Console Output: Profile Copyright : 66 114 105 97 110 32 76 101 118 105 110 32 50 48 49 54 44 32 65 108 108 32 82 105 103 104 116 115 32 82 101 115 101 114 118 101 100

I am working on a python tool that uses the Piexif library https://github.com/hMatoba/Piexif/.

I use the following python code to add the author and copyright information to the file. The code produces an incorrect result for ProfileCopyright that exiftool reads as a list of integers. It should display:

Brian Levin 2016, All Rights Reserved

Instead it displays the UTF-8 integer bit representation of that string.

I have filed a bug with Piexif and the author has stated that it is an issue with Exiftool.

https://github.com/hMatoba/Piexif/issues/19

Please help me determine where the bug exists. I have attached a sample image with the troubled exif. Thank you in advance for your help.


import piexif
from PIL import Image


def manipulate_exif(img, remove_gps):

    author = 'Brian Levin'
    license = '{} 2016, All Rights Reserved'
    utf8_bytearray = tuple(bytearray(license.format(author), 'utf-8'))
    utf16_bytearray = tuple(bytearray(author, 'utf-16'))

    exif = piexif.load(img.info['exif'])
    exif['0th'][piexif.ImageIFD.Artist] = author
    exif['0th'][piexif.ImageIFD.XPAuthor] = utf16_bytearray

    exif['0th'][piexif.ImageIFD.ProfileCopyright] = utf8_bytearray
    exif['0th'][piexif.ImageIFD.Copyright] = license.format(author)

    return piexif.dump(exif)


img = Image.open('./IMG_2223.jpg')
exif_copy = manipulate_exif(img, False)
img.save('./Test.jpg', 'JPEG', exif=exif_copy)

Phil Harvey

Right.  Piexif is correct.  According to the DNG specification the ProfileCopyright tag may be stored either as TIFF ASCII or BYTE format.  The ExifTool tag definition must be changed to override the stored format and force ASCII (well, UTF-8) interpretation regardless, because otherwise ExifTool shows it as a series of byte values when stored as BYTE.  The people who wrote the spec apparently didn't understand the difference between a string and a series of bytes. :(  (They made some other, more serious blunders too, so this isn't too surprising.)

This is fixed in version 10.25, which has just been released.

Thanks for this report.

- Phil
...where DIR is the name of a directory/folder containing the images.  On Mac/Linux/PowerShell, use single quotes (') instead of double quotes (") around arguments containing a dollar sign ($).