0
votes

Hey community,

Since a few days I'm stuck while trying to get the date of a .jpg or .png image file, when the picture was taken. I believe it was called DateTimeOriginal. What I'm trying to do, is getting just this one specific info, DateTimeOriginal, not more, not less.

This is part of a selfmade project, a program to sort pictures by the date when they were taken. I'm programming with VB, and for the exif data I'm calling a batch file.

So i know how to use the exiftool. It's common use is: exiftool file.jpg But I need something like: exiftool -DateTimeOriginal file.jpg >> DateTaken.txt I have tried this one, but I'm not getting the Date, I only got a list of any jpg found in the directory, but without metadata. I was searching so long for any option like this, but I can't find anything useful. Perhaps there is another, more efficient way to get metadata of an image, only using VB.

Has anyone an advise or other idea?

Thanks

2
Questions on the use of general software belong on Super User, but have you considered the possibility that the file doesn't have that data? - Andrew Morton
.png pictures does not store exif data.Even in jpg file the data can be deleted. You take a look at tooltipinfo.bat which can read the exif data through the windows api . - npocmaka
@AndrewMorton Similar questions were moved to stackoverflow because they don't belong to Superuser, thats why I am asking here, also this isn't specifically "software". Yes I have considered that, but the point is, the batch file doesen't even work like this, I search for an advise to get this batch file to work properly. - arvenyon
@npocmaka Yes, your right, but however, I just need it for jpgs. And thx for the tip! - arvenyon
@npocmaka, PNG files now have an EXIF standard. It is stored in the eXIf ancillary chunks. See ftp-osl.osuosl.org/pub/libpng/documents/… - StarGeek

2 Answers

2
votes

You have the correct command to get the DateTimeOriginal tag from a file (exiftool -DateTimeOriginal file.jpg). But you say you are getting a list of filenames in a directory, which sounds like you're passing a directory name, not a file name. If you wish to get DateTimeOriginal for only those files in a directory that have a value in the tag, use exiftool -if "$DateTimeOriginal" -DateTimeOriginal C:/path/to/dir. Any file that doesn't have a DateTimeOriginal will not be listed then.

One thing to note is that the windows "Date Taken" property will be filled by a variety of metadata tags depending upon the filetype. For example, in PNG files, Windows will use PNG:CreationTime. In jpg files, Windows will use, in order, EXIF:DateTimeOriginal, IPTC:DateCreated + IPTC:TimeCreated, XMP:CreateDate, EXIF:CreateDate, and then XMP:DateTimeOriginal tags.

0
votes

After a bit of digging, I found that you can get a list of properties if a bitmap.

Unfortunately the property IDs are numeric and rather cryptic.

Have a look here to find out more

After a bit more digging, it seems that the propertyId &h132 (a hexadecimal number) is the date stored as an array of integers in ascii encoding. This function finds propertyid &h132 and returns the date info as a string in year:month:date hour:minute:second format.

You might get variations with localization.. for example using /,: or - for the date separators etc, so, to parse it as a date type, you might need to work around that.

Public Function GetImageTakenDate(theimage As Bitmap) As String
    Dim propItems As List(Of PropertyItem) = theimage.PropertyItems.ToList
    Dim dt As PropertyItem = propItems.Find(Function(x) x.Id = &H132)
    Dim datestring As String = ""
    For Each ch As Integer In dt.Value
        datestring += Chr(ch)
    Next
    datestring = datestring.Remove(datestring.Length - 1)
    Return datestring
End Function