0

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

arvenyon
  • 153
  • 1
  • 8
  • 1
    Questions on the use of general software belong on [Super User](https://superuser.com/), but have you considered the possibility that the file doesn't have that data? – Andrew Morton Feb 02 '18 at 12:07
  • `.png` pictures does not store exif data.Even in `jpg` file the data can be deleted. You take a look at [tooltipinfo.bat](https://github.com/npocmaka/batch.scripts/blob/master/hybrids/jscript/tooltipInfo.bat) which can read the exif data through the windows api . – npocmaka Feb 02 '18 at 12:08
  • @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 Feb 02 '18 at 12:15
  • @npocmaka Yes, your right, but however, I just need it for jpgs. And thx for the tip! – arvenyon Feb 02 '18 at 12:16
  • You state that you're trying to get the 'taken' date and time, you state that you know how to use `exiftool` and provide the command you used based on that knowledge. Could you therefore please clarify your question? because it appears to me that you don't have one! _Is the command you have used from the tool you say you know how to use not producing the output you wanted or expected? what is that output? what do you want to do with that output? have you tried it? did it work? what happened which was different to your expectations? That information should be added to your question as an edit._ – Compo Feb 02 '18 at 12:42
  • Are you wanting us to rewrite exiftool? or suggest another software? _Please note that questions asking us to recommend or find a book, tool, software library, tutorial or other off-site resource are off-topic here_. You need to describe the problem and what has been done so far to solve it! – Compo Feb 02 '18 at 13:01
  • 3
    @npocmaka, PNG files now have an EXIF standard. It is stored in the `eXIf ` ancillary chunks. See http://ftp-osl.osuosl.org/pub/libpng/documents/pngext-1.5.0.html#C.eXIf – StarGeek Feb 02 '18 at 17:33
  • @StarGeek - interesting.Thanks. – npocmaka Feb 02 '18 at 22:16

2 Answers2

2

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.

StarGeek
  • 4,948
  • 2
  • 19
  • 30
0

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
David Wilson
  • 4,369
  • 3
  • 18
  • 31