Advertisement
Guest User

Image informaition

a guest
Dec 28th, 2018
200
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.  
  2. UsePNGImageDecoder()
  3. UseJPEGImageDecoder()
  4. UseJPEG2000ImageDecoder()
  5. UseTGAImageDecoder()
  6. UseTIFFImageDecoder()
  7. UseGIFImageDecoder()
  8.  
  9. #FILE_PB_PAINT = 100
  10.  
  11. Procedure.s get_png_info(sFile.s)
  12.   *pngHead.BYTE = AllocateMemory(8192 + 1)
  13.   If *pngHead
  14.     If ReadFile(#FILE_PB_PAINT,sFile)
  15.       If Lof(#FILE_PB_PAINT) > 8192
  16.         ReadData(#FILE_PB_PAINT,*pngHead, 8192)
  17.       Else
  18.         ReadData(#FILE_PB_PAINT,*pngHead, Lof(#FILE_PB_PAINT))
  19.       EndIf  
  20.       CloseFile(#FILE_PB_PAINT)
  21.      
  22.       For t=0 To 8192-1
  23.         v = PeekB(*pngHead + t)
  24.         If v < ' ' Or v >= 127
  25.           PokeB(*pngHead + t, ' ') ; Space
  26.         EndIf  
  27.       Next
  28.       head$ = UCase(PeekS(*pngHead, -1, #PB_Ascii))
  29.      
  30.       If FindString(head$, UCase("Paint.NET"), 1)
  31.         result.s = "Paint.NET"
  32.       EndIf  
  33.      
  34.       If FindString(head$, UCase("Adobe ImageReady"), 1)
  35.         result.s = "Adobe ImageReady"
  36.       EndIf        
  37.       If FindString(head$, UCase("Photoshop"), 1)
  38.         result.s = "Photoshop"
  39.       EndIf          
  40.       If FindString(head$, UCase("Macromedia Fireworks"), 1)
  41.         result.s = "Macromedia Fireworks"
  42.       EndIf  
  43.      
  44.       If FindString(head$, UCase("Created with GIMP"), 1)
  45.         result.s = "GIMP"
  46.       EndIf      
  47.       If FindString(head$, UCase("Created with The GIMP"), 1)
  48.         result.s = "GIMP"
  49.       EndIf          
  50.       If FindString(head$, UCase("PhotoFiltre"), 1)
  51.         result.s = "PhotoFiltre"
  52.       EndIf            
  53.      
  54.       If FindString(head$, UCase("gnome-panel-screenshot"), 1)
  55.         result.s = "gnome Screenshot"
  56.       EndIf  
  57.       If FindString(head$, UCase("Ghostscript"), 1)
  58.         result.s = "Ghostscript"
  59.       EndIf    
  60.       If FindString(head$, UCase("www.inkscape.org"), 1)
  61.         result.s = "Inkscape"
  62.       EndIf
  63.       If FindString(head$, UCase("XV Version"), 1)
  64.         result.s = "XV"
  65.       EndIf  
  66.       If FindString(head$, UCase("MATLAB"), 1)
  67.         result.s = "MATLAB"
  68.       EndIf      
  69.      
  70.     EndIf
  71.     FreeMemory(*pngHead)
  72.   EndIf
  73.   If result <> ""
  74.     result + "\"
  75.   EndIf  
  76.   ProcedureReturn result
  77. EndProcedure  
  78.  
  79. ;SRC:http://purebasic.info/phpBB3ex/viewtopic.php?f=10&t=3258
  80. Enumeration
  81.   #FileA = 144
  82. EndEnumeration
  83.  
  84. Structure FileMate
  85.   Filename.s
  86.   ModifyDate.s
  87. EndStructure
  88.  
  89. Global *imageAdress = AllocateMemory(8192+$FFFFFF) ;+$FFFFFF for security
  90.  
  91. Procedure.s SQLEscape(str.s)
  92.   str.s = ReplaceString(str, "'","''")
  93.   ProcedureReturn str
  94. EndProcedure
  95.  
  96. Procedure.w xchEndianW(e.w)
  97.   ProcedureReturn (e & $FF) << 8 + (e >> 8) & $FF
  98. EndProcedure
  99.  
  100. Procedure xchEndianL(e.l)
  101.   ProcedureReturn (e & $FF) << 24 + (e & $FF00) << 8 + (e >> 8) & $FF00 + (e >> 24) & $FF
  102. EndProcedure
  103.  
  104. Procedure.s GetPhotoInfo(Filenamepath.s,Tag) ; 306 Date, 207 Description, 272 Model, 305 Software
  105.   ReadFile(#FileA,Filenamepath)
  106.   ReadData(#FileA, *imageAdress, 8192)
  107.   CloseFile(#FileA)
  108.  
  109.   Protected OffsetField.q = *imageAdress +3
  110.   Protected Header.b, wordOrder.l, tifFormat.l, ifd1.l, nFields.l, currentTag.l, flg.b
  111.   Protected fieldType.l, fieldLength.l, fieldValue.l, currentloc.l, cam$
  112.   If PeekB(OffsetField) &$FF = $E1
  113.     Header = 12
  114.   Else
  115.     Header = 30
  116.   EndIf
  117.   OffsetField = *imageAdress + Header
  118.   wordOrder = PeekW(OffsetField)
  119.   OffsetField + 2
  120.   If wordOrder = $4949 Or wordOrder = $4D4D
  121.     If wordOrder = $4949
  122.       tifFormat = PeekW(OffsetField)
  123.     Else
  124.       tifFormat = xchEndianW(PeekW(OffsetField))
  125.     EndIf
  126.     OffsetField + 2
  127.     If tifFormat = $2A
  128.       If wordOrder = $4949
  129.         ifd1 = PeekL(OffsetField)
  130.       Else
  131.         ifd1 = xchEndianL(PeekL(OffsetField) )
  132.       EndIf
  133.       OffsetField + 4
  134.       OffsetField = *imageAdress + ifd1 + Header
  135.       If wordOrder = $4949
  136.         nFields = PeekW(OffsetField)
  137.       Else
  138.         nFields = xchEndianW(PeekW(OffsetField))
  139.       EndIf
  140.       OffsetField + 2
  141.       For i = 1 To nFields
  142.         If wordOrder = $4949
  143.           currentTag = PeekW(OffsetField)
  144.         Else
  145.           currentTag = xchEndianW(PeekW(OffsetField))
  146.         EndIf
  147.         OffsetField + 2
  148.  
  149.         If currentTag = Tag
  150.           If wordOrder = $4949
  151.             fieldType = PeekW(OffsetField)
  152.           Else
  153.             fieldType = xchEndianW(PeekW(OffsetField))
  154.           EndIf
  155.           OffsetField + 2
  156.           fieldLength = PeekL(OffsetField)
  157.           OffsetField + 4
  158.           If fieldLength <= 4
  159.             currentloc = OffsetField
  160.             ;            AddGadgetItem(#ListView, -1, PeekS(OffsetField,0, #PB_Ascii))
  161.             OffsetField + 4
  162.           Else
  163.             currentloc = OffsetField
  164.             If wordOrder = $4949
  165.               fieldValue = PeekL(OffsetField)
  166.             Else
  167.               fieldValue = xchEndianL(PeekL(OffsetField))
  168.             EndIf
  169.             OffsetField = *imageAdress + fieldValue + Header          
  170.             If fieldValue + Header < 8192
  171.               name$=Trim(PeekS(OffsetField, 255, #PB_Ascii))
  172.               If CheckFilename(name$) = #False
  173.                 name$ = ""
  174.               EndIf  
  175.               If Len(name$)>64
  176.                 name$=Trim(Left(name$,64))  
  177.               EndIf  
  178.               ProcedureReturn name$
  179.             Else
  180.               ProcedureReturn ""
  181.             EndIf  
  182.             OffsetField = currentloc + 4
  183.           EndIf
  184.         Else
  185.           OffsetField +10
  186.         EndIf
  187.       Next
  188.     EndIf
  189.   EndIf
  190. EndProcedure
  191.  
  192. Procedure.s MyMonth(x)
  193.   Select x
  194.     Case 1
  195.       ProcedureReturn "Januar"
  196.     Case 2
  197.       ProcedureReturn "Februar"
  198.     Case 3
  199.       ProcedureReturn "Maerz"
  200.     Case 4
  201.       ProcedureReturn "April"
  202.     Case 5
  203.       ProcedureReturn "Mai"
  204.     Case 6
  205.       ProcedureReturn "Juni"
  206.     Case 7
  207.       ProcedureReturn "Juli"
  208.     Case 8
  209.       ProcedureReturn "August"
  210.     Case 9
  211.       ProcedureReturn "September"
  212.     Case 10
  213.       ProcedureReturn "Oktober"
  214.     Case 11
  215.       ProcedureReturn "November"
  216.     Case 12
  217.       ProcedureReturn "Dezember"
  218.   EndSelect
  219.   ProcedureReturn "Error"
  220. EndProcedure
  221.    
  222.  
  223. Procedure.s get_file_creation_string(sFile.s, LongDatePath)
  224. creation_date = GetFileDate(sFile,#PB_Date_Created )
  225. If GetFileDate(sFile, #PB_Date_Modified ) < creation_date
  226. creation_date = GetFileDate(sFile,#PB_Date_Modified )
  227. EndIf
  228.  
  229. ext.s = LCase(GetExtensionPart(sFile))
  230. If ext = "JPEG" Or ext="JPG"
  231.  
  232.   dateString.s = Trim(GetPhotoInfo(sFile, 306)) ; 306 Date, 207 Description, 272 Model, 305 Software
  233.  
  234.   If dateString <> ""
  235.     date = ParseDate("%yyyy:%mm:%dd %hh:%ii:%ss", dateString)
  236.     If Year(date) > 1999 And date < Date()
  237.       If LongDatePath
  238.         ProcedureReturn Str(Day(date))+". " + MyMonth(Month(date)) +" "+ Str(Year(date))
  239.       Else
  240.         ProcedureReturn Str(Year(date))        
  241.       EndIf  
  242.     EndIf  
  243.    
  244.   EndIf  
  245. EndIf  
  246.  
  247. ; month.s = Str(Month(creation_date))
  248. ; If Len(month) < 2
  249. ;   month = "0" + month
  250. ; EndIf  
  251. If LongDatePath
  252.   ProcedureReturn Str(Day(creation_date))+". " + MyMonth(Month(creation_date)) +" "+ Str(Year(creation_date))
  253. Else
  254.   ProcedureReturn Str(Year(creation_date))  
  255. EndIf  
  256.   ;  Str(Year(creation_date));+"-" + month
  257. EndProcedure
  258.  
  259.  
  260. Procedure GetRotationExif(jpg$)
  261.   If  OpenFile(0, jpg$)
  262.   ;--> Byte 0 of EXIF begins after JPEG header
  263.   FileSeek(0,12)
  264.   ;--> Bytes 0-1 is word order 18761 ($4949) is Intel and 19789 ($4D4D) is Motorola
  265.   byteOrder = ReadWord(0)
  266.   ;--> For now I only handle Little Endian
  267.   If byteOrder = $4949
  268.     ; --> Bytes 2-3 is TIFF format, it's always 42 ($2A). If not, give up.
  269.     tifFormat = ReadWord(0)
  270.     ;--> This is always $2A. If not, give up.
  271.     If tifFormat = $2A
  272.       ;--> Bytes 4-7 is starting offset for IFD (Image File Directory)
  273.       ifd1 = ReadLong(0)
  274.       ;--> Move to start of IFD
  275.       FileSeek(0,ifd1 + 12)
  276.       ;--> First 2 bytes of IFD is number of field entries
  277.       nFields = ReadWord(0)
  278.       ;--> Loop through all fields to find Date/Time stamp
  279.       For i = 1 To nFields
  280.         ;--> Bytes 0-1 contain the Tag for the field.
  281.         currentTag = ReadWord(0) &$FFFF
  282.         Select currentTag
  283.           Case 274 ;orientation
  284.             FileSeek(0,Loc(0) + 6)
  285.             orientation= ReadWord(0)
  286.             ReadWord(0)
  287.           Default
  288.             num_champ+1
  289.             ;--> Move to next field. Each field is 12 bytes.
  290.             ;--> currentTag (2 bytes) is current Loc(0) so we add 10
  291.             FileSeek(0,Loc(0) + 10)
  292.         EndSelect
  293.       Next i
  294.       CloseFile(0)
  295.       exifResult = orientation
  296.     Else
  297.       ;--> Wrong format, display Unavailable
  298.       exifResult = 0
  299.     EndIf
  300.   Else
  301.     ;--> Wrong byte order, display Unavailable
  302.     exifResult = 0
  303.   EndIf
  304. Else
  305.   ;--> Impossible de lire le fichier
  306.   exifResult = 0
  307. EndIf
  308.   ProcedureReturn exifResult
  309. EndProcedure
  310.  
  311.  
  312. Procedure.s escape(A$)
  313.   A$=ReplaceString(A$,";", " ")
  314.   A$=ReplaceString(A$,":", " ")
  315.   ProcedureReturn Trim(A$)
  316. EndProcedure
  317.  
  318. Procedure.s TAG(Name$, Value$)
  319.   ProcedureReturn Name$+": " + escape(Value$) + ";"  
  320. EndProcedure
  321.  
  322. Procedure.s EXT(A$)
  323.   ProcedureReturn UCase(GetExtensionPart(A$))
  324. EndProcedure
  325.  
  326.  
  327. Procedure.s MyFileInfo(file$)
  328.   If FileSize(file$)>=0
  329.   A$=TAG("DATE", get_file_creation_string(file$, 1))
  330.  
  331.   Debug EXT(file$)
  332.  
  333.   If EXT(file$) = "JPG" Or EXT(file$) = "JPEG"
  334.     A$+TAG("JPGDATETIME", GetPhotoInfo(file$,306)) ; 306 Date
  335.     A$+TAG("JPEGDESC", GetPhotoInfo(file$,207)) ; 207 Description      
  336.     A$+TAG("JPEGMODEL", GetPhotoInfo(file$,272)); 272 Model
  337.     A$+TAG("SOFTWARE", GetPhotoInfo(file$,305)); 305 Software
  338.   EndIf
  339.  
  340.   If EXT(file$) = "PNG"
  341.     A$+TAG("SOFTWARE", get_png_info(file$))
  342.   EndIf  
  343.   EndIf
  344.   ProcedureReturn A$
  345. EndProcedure
  346.  
  347.    
  348.  
  349.  
  350. Debug MyFileInfo("/hdd/v2/Bilder Paradies/Bilder Paradies neu/bearbeitet/_DSC0232-edit.jpg" )
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement