This is a tiny "one command userlib" to get Exif date/time information (UTC) of jpeg images:
ExifDate()
Download: ExifDate.zip
ExifDate -> PureLibraries/UserLibraries
ExifDate.chm -> Help
Have fun - and please tell me if you like it.

Code: Select all
; Modify Exif Date example by PB. Feel free to use in any way. :)
; Works fine with photos taken with a Pentax Optio S digital camera.
; May work with photos by other cameras, but no guarantee is given!
;
; *** Any use of this procedure is entirely at your own risk! ***
Procedure ModifyExifDate(file$,ye,mo,da,ho,mi,se)
If OpenFile(0,file$)=0
ProcedureReturn 0 ; Couldn't open file, or it doesn't exist.
Else
a$=FormatDate("%yyyy:%mm:%dd %hh:%ii:%ss",Date(ye,mo,da,ho,mi,se)) ; Prepare new date to write.
; Next line writes new date into the 3 date offsets in the photo's Exif Data (228, 694 and 714).
FileSeek(228) : WriteString(a$) : FileSeek(694) : WriteString(a$) : FileSeek(714) : WriteString(a$)
CloseFile(0) : ProcedureReturn 1 ; Successful! :)
EndIf
EndProcedure
Debug ModifyExifDate("C:\IMGP0695.JPG",2005,12,25,0,0,0) ; Modify date to Christmas Day for this example.
Code: Select all
UseJPEGImageDecoder()
#Exif_DateTime = 306
#Header = 12
Global date_time
Procedure.s GetExifDateTime(jpg$, writeIt, newDateTime$)
OpenFile(0, jpg$)
; --> Byte 0 of EXIF begins after JPEG header
FileSeek(#Header)
; --> Bytes 0-1 is word order 18761 ($4949) is Intel and 19789 ($4D4D) is Motorola
wordOrder = ReadWord()
If wordOrder = $4949
; --> Bytes 2-3 is TIFF format, it's always 42 ($2A). If not, give up.
tifFormat = ReadWord()
If tifFormat = $2A
; --> Bytes 4-7 is starting offset for IFD (Image File Directory)
ifd1 = ReadLong()
; --> Move to start of IFD
FileSeek(ifd1 + #Header)
; --> First 2 bytes of IFD is number of field entries
nFields = ReadWord()
; --> Loop through all fields to find Date/Time stamp
date_time = #False
For i = 1 To nFields
; --> Bytes 0-1 contain the Tag for the field.
currentTag = ReadWord()
If currentTag = #Exif_DateTime
; --> Bytes 2-3 contain the field Type.
; --> We know this will be 2 (ASCII) For Date/Time
fieldType = ReadWord()
; --> Bytes 4-7 contain the Length of the field.
fieldLength = ReadLong()
currentloc = Loc()
; --> Bytes 8-11 contain a pointer to ASCII Date/Time
fieldValue = ReadLong()
; --> Move to that pointer
FileSeek(fieldValue + #Header)
; --> This is the start point of Dat/Time ASCII string
If writeIt And newDateTime$
WriteString(newDateTime$)
date_time$ = newDateTime$
MessageRequester("Info", "Date and Time have been changed.")
Else
date_time$ = ReadString()
EndIf
date_time = #True
Break
Else
; --> Move to next field. Each field is 12 bytes.
; --> currentTag (2 bytes) is current Loc() so we add 10
FileSeek(Loc()+10)
EndIf
Next
If date_time <> #True
MessageRequester("Sorry", "Date Time field was not found.")
EndIf
Else
MessageRequester("Error", "Invalid file format!")
EndIf
Else
MessageRequester("Sorry", "Invalid file format!")
EndIf
CloseFile(0)
ProcedureReturn date_time$
EndProcedure
If OpenWindow(0, 10, 10, 300, 200, #PB_Window_SystemMenu, "Exif Date/Time") And CreateGadgetList(WindowID())
ButtonGadget(0, 10, 10, 280, 20, "Open JPG")
TextGadget(1, 10, 40, 280, 60, "", #PB_Text_Center)
TextGadget(2, 10, 80, 280, 20, "", #PB_Text_Center)
ButtonGadget(3, 10, 110, 280, 20, "Change Date")
DisableGadget(3, 1)
DateGadget(4, 10, 140, 280, 20, "%yyyy:%mm:%dd %hh:%ii")
Repeat
event = WaitWindowEvent()
If event = #PB_EventGadget
Select EventGadgetID()
Case 0
fileOpen$ = (OpenFileRequester("Select JPEG", "C:\Documents and Settings\Owner\My Documents\My Pictures\", "JPG files (JPG)|*.jpg;*.jpeg", 0))
If fileOpen$
dt$ = GetExifDateTime(fileOpen$, 0, "")
If date_time
SetGadgetText(1, fileOpen$)
SetGadgetText(2, "Original Date/Time is " + dt$)
DisableGadget(3, 0)
EndIf
EndIf
Case 3
; --> DateGadget has no support for seconds so add your own below
newDT$ = GetGadgetText(4) + ":00"
dt$ = GetExifDateTime(fileOpen$, 1, newDT$)
EndSelect
EndIf
Until event = #PB_Event_CloseWindow
EndIf
End
Code: Select all
UseJPEGImageDecoder()
jpg$ = OpenFileRequester("Select JPEG", "C:\Documents and Settings\Owner\My Documents\My Pictures\", "JPG files (JPG)|*.jpg;*.jpeg", 0)
If jpg$
OpenFile(0, jpg$)
FileSeek(188)
dateInfo$ = "Modified: " + Chr(9)
dateInfo$ + ReadString() + #CRLF$
FileSeek(586)
dateInfo$ + "Taken: " + Chr(9)
dateInfo$ + ReadString() + #CRLF$
FileSeek(606)
dateInfo$ + "Digitized: " + Chr(9)
dateInfo$ + ReadString()
CloseFile(0)
MessageRequester("Exif Date Info", dateInfo$)
EndIf
End