Menu

#6 Wrong EXIF Tag values returned when recursing through directory of jpg files

v1.0_(example)
open
nobody
1
2015-07-08
2013-07-18
Simon Ajina
No

I am using the ExifReader.cls in Excel vba. When recursing through a directory of jpg files the exif tag values returned are wrong for the 2nd and following images.

I put some debug stops in the class code and found the following:

Looking into Sub GetDirectoryEntries
Whilst handling first image : IDFDirectory is type IFD_Data(1 to 11) with IFDDirectory(4) containing the orientation tag value of 6 for this image file
Later on the array becomes 21 elements with Upper_IFDDirectory set to 11 and both IFDDirectory(4) and IFDDirectory(11+4) containing the orientation tag value for this image (which was value of 6)

when we come to process the second image file in the folder, the IFDDirectory array is now 62 elements with Upper_IFDirectory set to 51. IFDDirectory(51+4) contains the orientation tag value for the second image which was value of 1 but IFDDirectory(4) and (15) still hold the orientation value of the first image,

Then looking at the get code for tag in routine:
Public Property Get Tag(Optional ByVal ExifTag As EXIF_TAG) As Variant

It has code that goes through the IFDDirectory from array element 1 looking for the required tag. Well it will return the first value it stumbles on - that being for the first photo image file !!!

For i = 1 To UBound(IFDDirectory)
If IFDDirectory(i).Tag_No = ExifTag Then

Is there a fix for this??

There is a similar post under discussions raised a few years ago but raising one here now as it os surely a bug.

Discussion

  • Simon Ajina

    Simon Ajina - 2013-07-18

    This is an issue with the excel vba environment. I have now found the way to fix it. The following ensures new instance loaded on each recursion.

    The declaration would be
    Dim myJPGexif As ExifReader
    instead of the example
    Dim myJPGexif As New ExifReader
    .....

    and then to use the ExifReader class tag reader:

    Set myJPGexif = New ExifReader
    
    myJPGexif.Load (p)
    txtExifOrientation = myJPGexif.Tag(Orientation)
    

    So now all ok.

     
  • Reinhold Thurner

    The reader is what I was really looking for, because I would like to sort a lot of Pictures from different sources on e.g. the creation date.
    I looked at a lot of other programs - but exifreader is much easier and straighforward and still very versatile!

    Sofar so good. After the recommended correction it worked fine for about 20 pictures, then it crashed with an overflow.
    I tried to dig into the code - but this is beyond my understanding.
    I suspect that the redim preserve of the IFDDirectory is the cause ???
    An Update or help would be greatly appreciated

     
  • Reinhold Thurner

    I have updated the program to handle all JPG-Files in a Directory.
    As a suggestion.

     

Log in to post a comment.