Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- UsePNGImageDecoder()
- UseJPEGImageDecoder()
- UseJPEG2000ImageDecoder()
- UseTGAImageDecoder()
- UseTIFFImageDecoder()
- UseGIFImageDecoder()
- #FILE_PB_PAINT = 100
- Procedure.s get_png_info(sFile.s)
- *pngHead.BYTE = AllocateMemory(8192 + 1)
- If *pngHead
- If ReadFile(#FILE_PB_PAINT,sFile)
- If Lof(#FILE_PB_PAINT) > 8192
- ReadData(#FILE_PB_PAINT,*pngHead, 8192)
- Else
- ReadData(#FILE_PB_PAINT,*pngHead, Lof(#FILE_PB_PAINT))
- EndIf
- CloseFile(#FILE_PB_PAINT)
- For t=0 To 8192-1
- v = PeekB(*pngHead + t)
- If v < ' ' Or v >= 127
- PokeB(*pngHead + t, ' ') ; Space
- EndIf
- Next
- head$ = UCase(PeekS(*pngHead, -1, #PB_Ascii))
- If FindString(head$, UCase("Paint.NET"), 1)
- result.s = "Paint.NET"
- EndIf
- If FindString(head$, UCase("Adobe ImageReady"), 1)
- result.s = "Adobe ImageReady"
- EndIf
- If FindString(head$, UCase("Photoshop"), 1)
- result.s = "Photoshop"
- EndIf
- If FindString(head$, UCase("Macromedia Fireworks"), 1)
- result.s = "Macromedia Fireworks"
- EndIf
- If FindString(head$, UCase("Created with GIMP"), 1)
- result.s = "GIMP"
- EndIf
- If FindString(head$, UCase("Created with The GIMP"), 1)
- result.s = "GIMP"
- EndIf
- If FindString(head$, UCase("PhotoFiltre"), 1)
- result.s = "PhotoFiltre"
- EndIf
- If FindString(head$, UCase("gnome-panel-screenshot"), 1)
- result.s = "gnome Screenshot"
- EndIf
- If FindString(head$, UCase("Ghostscript"), 1)
- result.s = "Ghostscript"
- EndIf
- If FindString(head$, UCase("www.inkscape.org"), 1)
- result.s = "Inkscape"
- EndIf
- If FindString(head$, UCase("XV Version"), 1)
- result.s = "XV"
- EndIf
- If FindString(head$, UCase("MATLAB"), 1)
- result.s = "MATLAB"
- EndIf
- EndIf
- FreeMemory(*pngHead)
- EndIf
- If result <> ""
- result + "\"
- EndIf
- ProcedureReturn result
- EndProcedure
- ;SRC:http://purebasic.info/phpBB3ex/viewtopic.php?f=10&t=3258
- Enumeration
- #FileA = 144
- EndEnumeration
- Structure FileMate
- Filename.s
- ModifyDate.s
- EndStructure
- Global *imageAdress = AllocateMemory(8192+$FFFFFF) ;+$FFFFFF for security
- Procedure.s SQLEscape(str.s)
- str.s = ReplaceString(str, "'","''")
- ProcedureReturn str
- EndProcedure
- Procedure.w xchEndianW(e.w)
- ProcedureReturn (e & $FF) << 8 + (e >> 8) & $FF
- EndProcedure
- Procedure xchEndianL(e.l)
- ProcedureReturn (e & $FF) << 24 + (e & $FF00) << 8 + (e >> 8) & $FF00 + (e >> 24) & $FF
- EndProcedure
- Procedure.s GetPhotoInfo(Filenamepath.s,Tag) ; 306 Date, 207 Description, 272 Model, 305 Software
- ReadFile(#FileA,Filenamepath)
- ReadData(#FileA, *imageAdress, 8192)
- CloseFile(#FileA)
- Protected OffsetField.q = *imageAdress +3
- Protected Header.b, wordOrder.l, tifFormat.l, ifd1.l, nFields.l, currentTag.l, flg.b
- Protected fieldType.l, fieldLength.l, fieldValue.l, currentloc.l, cam$
- If PeekB(OffsetField) &$FF = $E1
- Header = 12
- Else
- Header = 30
- EndIf
- OffsetField = *imageAdress + Header
- wordOrder = PeekW(OffsetField)
- OffsetField + 2
- If wordOrder = $4949 Or wordOrder = $4D4D
- If wordOrder = $4949
- tifFormat = PeekW(OffsetField)
- Else
- tifFormat = xchEndianW(PeekW(OffsetField))
- EndIf
- OffsetField + 2
- If tifFormat = $2A
- If wordOrder = $4949
- ifd1 = PeekL(OffsetField)
- Else
- ifd1 = xchEndianL(PeekL(OffsetField) )
- EndIf
- OffsetField + 4
- OffsetField = *imageAdress + ifd1 + Header
- If wordOrder = $4949
- nFields = PeekW(OffsetField)
- Else
- nFields = xchEndianW(PeekW(OffsetField))
- EndIf
- OffsetField + 2
- For i = 1 To nFields
- If wordOrder = $4949
- currentTag = PeekW(OffsetField)
- Else
- currentTag = xchEndianW(PeekW(OffsetField))
- EndIf
- OffsetField + 2
- If currentTag = Tag
- If wordOrder = $4949
- fieldType = PeekW(OffsetField)
- Else
- fieldType = xchEndianW(PeekW(OffsetField))
- EndIf
- OffsetField + 2
- fieldLength = PeekL(OffsetField)
- OffsetField + 4
- If fieldLength <= 4
- currentloc = OffsetField
- ; AddGadgetItem(#ListView, -1, PeekS(OffsetField,0, #PB_Ascii))
- OffsetField + 4
- Else
- currentloc = OffsetField
- If wordOrder = $4949
- fieldValue = PeekL(OffsetField)
- Else
- fieldValue = xchEndianL(PeekL(OffsetField))
- EndIf
- OffsetField = *imageAdress + fieldValue + Header
- If fieldValue + Header < 8192
- name$=Trim(PeekS(OffsetField, 255, #PB_Ascii))
- If CheckFilename(name$) = #False
- name$ = ""
- EndIf
- If Len(name$)>64
- name$=Trim(Left(name$,64))
- EndIf
- ProcedureReturn name$
- Else
- ProcedureReturn ""
- EndIf
- OffsetField = currentloc + 4
- EndIf
- Else
- OffsetField +10
- EndIf
- Next
- EndIf
- EndIf
- EndProcedure
- Procedure.s MyMonth(x)
- Select x
- Case 1
- ProcedureReturn "Januar"
- Case 2
- ProcedureReturn "Februar"
- Case 3
- ProcedureReturn "Maerz"
- Case 4
- ProcedureReturn "April"
- Case 5
- ProcedureReturn "Mai"
- Case 6
- ProcedureReturn "Juni"
- Case 7
- ProcedureReturn "Juli"
- Case 8
- ProcedureReturn "August"
- Case 9
- ProcedureReturn "September"
- Case 10
- ProcedureReturn "Oktober"
- Case 11
- ProcedureReturn "November"
- Case 12
- ProcedureReturn "Dezember"
- EndSelect
- ProcedureReturn "Error"
- EndProcedure
- Procedure.s get_file_creation_string(sFile.s, LongDatePath)
- creation_date = GetFileDate(sFile,#PB_Date_Created )
- If GetFileDate(sFile, #PB_Date_Modified ) < creation_date
- creation_date = GetFileDate(sFile,#PB_Date_Modified )
- EndIf
- ext.s = LCase(GetExtensionPart(sFile))
- If ext = "JPEG" Or ext="JPG"
- dateString.s = Trim(GetPhotoInfo(sFile, 306)) ; 306 Date, 207 Description, 272 Model, 305 Software
- If dateString <> ""
- date = ParseDate("%yyyy:%mm:%dd %hh:%ii:%ss", dateString)
- If Year(date) > 1999 And date < Date()
- If LongDatePath
- ProcedureReturn Str(Day(date))+". " + MyMonth(Month(date)) +" "+ Str(Year(date))
- Else
- ProcedureReturn Str(Year(date))
- EndIf
- EndIf
- EndIf
- EndIf
- ; month.s = Str(Month(creation_date))
- ; If Len(month) < 2
- ; month = "0" + month
- ; EndIf
- If LongDatePath
- ProcedureReturn Str(Day(creation_date))+". " + MyMonth(Month(creation_date)) +" "+ Str(Year(creation_date))
- Else
- ProcedureReturn Str(Year(creation_date))
- EndIf
- ; Str(Year(creation_date));+"-" + month
- EndProcedure
- Procedure GetRotationExif(jpg$)
- If OpenFile(0, jpg$)
- ;--> Byte 0 of EXIF begins after JPEG header
- FileSeek(0,12)
- ;--> Bytes 0-1 is word order 18761 ($4949) is Intel and 19789 ($4D4D) is Motorola
- byteOrder = ReadWord(0)
- ;--> For now I only handle Little Endian
- If byteOrder = $4949
- ; --> Bytes 2-3 is TIFF format, it's always 42 ($2A). If not, give up.
- tifFormat = ReadWord(0)
- ;--> This is always $2A. If not, give up.
- If tifFormat = $2A
- ;--> Bytes 4-7 is starting offset for IFD (Image File Directory)
- ifd1 = ReadLong(0)
- ;--> Move to start of IFD
- FileSeek(0,ifd1 + 12)
- ;--> First 2 bytes of IFD is number of field entries
- nFields = ReadWord(0)
- ;--> Loop through all fields to find Date/Time stamp
- For i = 1 To nFields
- ;--> Bytes 0-1 contain the Tag for the field.
- currentTag = ReadWord(0) &$FFFF
- Select currentTag
- Case 274 ;orientation
- FileSeek(0,Loc(0) + 6)
- orientation= ReadWord(0)
- ReadWord(0)
- Default
- num_champ+1
- ;--> Move to next field. Each field is 12 bytes.
- ;--> currentTag (2 bytes) is current Loc(0) so we add 10
- FileSeek(0,Loc(0) + 10)
- EndSelect
- Next i
- CloseFile(0)
- exifResult = orientation
- Else
- ;--> Wrong format, display Unavailable
- exifResult = 0
- EndIf
- Else
- ;--> Wrong byte order, display Unavailable
- exifResult = 0
- EndIf
- Else
- ;--> Impossible de lire le fichier
- exifResult = 0
- EndIf
- ProcedureReturn exifResult
- EndProcedure
- Procedure.s escape(A$)
- A$=ReplaceString(A$,";", " ")
- A$=ReplaceString(A$,":", " ")
- ProcedureReturn Trim(A$)
- EndProcedure
- Procedure.s TAG(Name$, Value$)
- ProcedureReturn Name$+": " + escape(Value$) + ";"
- EndProcedure
- Procedure.s EXT(A$)
- ProcedureReturn UCase(GetExtensionPart(A$))
- EndProcedure
- Procedure.s MyFileInfo(file$)
- If FileSize(file$)>=0
- A$=TAG("DATE", get_file_creation_string(file$, 1))
- Debug EXT(file$)
- If EXT(file$) = "JPG" Or EXT(file$) = "JPEG"
- A$+TAG("JPGDATETIME", GetPhotoInfo(file$,306)) ; 306 Date
- A$+TAG("JPEGDESC", GetPhotoInfo(file$,207)) ; 207 Description
- A$+TAG("JPEGMODEL", GetPhotoInfo(file$,272)); 272 Model
- A$+TAG("SOFTWARE", GetPhotoInfo(file$,305)); 305 Software
- EndIf
- If EXT(file$) = "PNG"
- A$+TAG("SOFTWARE", get_png_info(file$))
- EndIf
- EndIf
- ProcedureReturn A$
- EndProcedure
- Debug MyFileInfo("/hdd/v2/Bilder Paradies/Bilder Paradies neu/bearbeitet/_DSC0232-edit.jpg" )
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement