• Welcome to Theos PowerBasic Museum 2017.

EXIF (reading/writing TAGs from digital photography)

Started by Patrice Terrier, November 24, 2010, 05:22:02 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Patrice Terrier

This GDImage example shows you how to get all the TAG's properties from a digital photography


'+--------------------------------------------------------------------------+
'|                                                                          |
'|                                  Exif                                    |
'|                                                                          |
'|              Reading/writing TAGs from digital photography.              |
'|                                                                          |
'|                              Version 1.00                                |
'+--------------------------------------------------------------------------+
'|                                                                          |
'|                         Author Patrice TERRIER                           |
'|                                                                          |
'|                         copyright(c) 2005-2010                           |
'|                                                                          |
'|                Patrice Terrier http://www.zapsolution.com                |
'|                                                                          |
'+--------------------------------------------------------------------------+
'|                  Project started on : 11-24-2010 (MM-DD-YYYY)            |
'|                        Last revised : 11-24-2010 (MM-DD-YYYY)            |
'+--------------------------------------------------------------------------+

#COMPILE EXE "Exif.exe"
#DIM ALL

#INCLUDE "gdimage.inc"
DECLARE FUNCTION zTrace LIB "zTrace.DLL" ALIAS "zTrace" (zMessage AS ASCIIZ) AS LONG

%PropertyTagTypeASCII              = 2
%PropertyTagImageDescription       = &H010E???

FUNCTION PropertyToString(BYVAL nProperty AS LONG) AS STRING
    LOCAL sItem AS STRING
    SELECT CASE LONG nProperty
    CASE &H8769&: sItem = "Exif IFD"
    CASE &H8825&: sItem = "Gps IFD"
    CASE &H00FE&: sItem = "New subfile type"
    CASE &H00FF&: sItem = "Sub file type"
    CASE &H0100&: sItem = "Image width"
    CASE &H0101&: sItem = "Image height"
    CASE &H0102&: sItem = "Bits per sample"
    CASE &H0103&: sItem = "Compression"
    CASE &H0106&: sItem = "Photo metric interp"
    CASE &H0107&: sItem = "ThreshHolding"
    CASE &H0108&: sItem = "Cell width"
    CASE &H0109&: sItem = "Cell height"
    CASE &H010A&: sItem = "Fill order"
    CASE &H010D&: sItem = "Document name"
    CASE &H010E&: sItem = "Image description"
    CASE &H010F&: sItem = "Manufacturer"
    CASE &H0110&: sItem = "Model"
    CASE &H0111&: sItem = "Strip offsets"
    CASE &H0112&: sItem = "Orientation"   ' 1 - The 0th row is at the top of the visual image, and the 0th column is the visual left side.
                                          ' 2 - The 0th row is at the visual top of the image, and the 0th column is the visual right side.
                                          ' 3 - The 0th row is at the visual bottom of the image, and the 0th column is the visual right side.
                                          ' 4 - The 0th row is at the visual bottom of the image, and the 0th column is the visual left side.
                                          ' 5 - The 0th row is the visual left side of the image, and the 0th column is the visual top.
                                          ' 6 - The 0th row is the visual right side of the image, and the 0th column is the visual top.
                                          ' 7 - The 0th row is the visual right side of the image, and the 0th column is the visual bottom.
                                          ' 8 - The 0th row is the visual left side of the image, and the 0th column is the visual bottom.
    CASE &H0115&: sItem = "Samples per pixel"
    CASE &H0116&: sItem = "Rows per strip"
    CASE &H0117&: sItem = "Strip bytes count"
    CASE &H0118&: sItem = "Minimum sample value"
    CASE &H0119&: sItem = "Maximum sample value"
    CASE &H011A&: sItem = "Horizontal resolution"
    CASE &H011B&: sItem = "Vertical resolution"
    CASE &H011C&: sItem = "Planar config"
    CASE &H011D&: sItem = "Page name"
    CASE &H011E&: sItem = "Horizontal position"
    CASE &H011F&: sItem = "Vertical position"
    CASE &H0120&: sItem = "Free offset"
    CASE &H0121&: sItem = "Free byte counts"
    CASE &H0122&: sItem = "Gray response unit"
    CASE &H0123&: sItem = "Gray response curve"
    CASE &H0124&: sItem = "T4 option"
    CASE &H0125&: sItem = "T6 option"
    CASE &H0128&: sItem = "Resolution unit (2 = inch, 3 = cm)"
    CASE &H0129&: sItem = "Page number"
    CASE &H012D&: sItem = "Transfer function"
    CASE &H0131&: sItem = "Software used"
    CASE &H0132&: sItem = "Date Time"
    CASE &H013B&: sItem = "Artist"
    CASE &H013C&: sItem = "Host Computer"
    CASE &H013D&: sItem = "Predictor"
    CASE &H013E&: sItem = "White point"
    CASE &H013F&: sItem = "Primary chromaticities"
    CASE &H0140&: sItem = "Color map"
    CASE &H0141&: sItem = "Halftone hints"
    CASE &H0142&: sItem = "Tile width"
    CASE &H0143&: sItem = "Tile length"
    CASE &H0144&: sItem = "Tile offset"
    CASE &H0145&: sItem = "Tile byte counts"
    CASE &H014C&: sItem = "Ink set"
    CASE &H014D&: sItem = "Ink names"
    CASE &H014E&: sItem = "Number of inks"
    CASE &H0150&: sItem = "Dot range"
    CASE &H0151&: sItem = "Target printer"
    CASE &H0152&: sItem = "Extra samples"
    CASE &H0153&: sItem = "Sample format"
    CASE &H0154&: sItem = "S Min sample value"
    CASE &H0155&: sItem = "S Max sample value"
    CASE &H0156&: sItem = "Transfer range"
    CASE &H0200&: sItem = "Jpeg proc"
    CASE &H0201&: sItem = "Jpeg inter format"
    CASE &H0202&: sItem = "Jpeg inter length"
    CASE &H0203&: sItem = "Jpeg restart interval"
    CASE &H0205&: sItem = "Jpeg lossless predictors"
    CASE &H0206&: sItem = "Jpeg point transforms"
    CASE &H0207&: sItem = "Jpeg Q tables"
    CASE &H0208&: sItem = "Jpeg DC tables"
    CASE &H0209&: sItem = "Jpeg AC tables"
    CASE &H0211&: sItem = "Height Cb Cr coefficients"
    CASE &H0212&: sItem = "Height Cb Cr subsampling"
    CASE &H0213&: sItem = "Height Cb Cr positioning"
    CASE &H0214&: sItem = "REF black white"
    CASE &H8773&: sItem = "ICC profile"
    CASE &H0301&: sItem = "Gamma"
    CASE &H0302&: sItem = "ICC profile descriptor"
    CASE &H0303&: sItem = "SRGB rendering intent"
    CASE &H0320&: sItem = "Image title"
    CASE &H8298&: sItem = "Copyright"
    CASE &H5001&: sItem = "Width resolution unit"
    CASE &H5002&: sItem = "Height resolution unit"
    CASE &H5003&: sItem = "Resolution width length unit"
    CASE &H5004&: sItem = "Resolution height length unit"
    CASE &H5005&: sItem = "Print flags"
    CASE &H5006&: sItem = "Print flags version"
    CASE &H5007&: sItem = "Print flags crop"
    CASE &H5008&: sItem = "Print flags bleed width"
    CASE &H5009&: sItem = "Print flags bleed Width Scale"
    CASE &H500A&: sItem = "Halftone LPI"
    CASE &H500B&: sItem = "Halftone LPI unit"
    CASE &H500C&: sItem = "Halftone degree"
    CASE &H500D&: sItem = "Halftone shape"
    CASE &H500E&: sItem = "Halftone misc"
    CASE &H500F&: sItem = "Halftone screen"
    CASE &H5010&: sItem = "Jpeg quality"
    CASE &H5011&: sItem = "Grid size"
    CASE &H5012&: sItem = "Thumbnail format"
    CASE &H5013&: sItem = "Thumbnail width"
    CASE &H5014&: sItem = "Thumbnail height"
    CASE &H5015&: sItem = "Thumbnail color depth"
    CASE &H5016&: sItem = "Thumbnail Planes"
    CASE &H5017&: sItem = "Thumbnail raw bytes"
    CASE &H5018&: sItem = "Thumbnail size"
    CASE &H5019&: sItem = "Thumbnail compressed size"
    CASE &H501A&: sItem = "Color transfer function"
    CASE &H501B&: sItem = "Thumbnail data"
    CASE &H5020&: sItem = "Thumbnail image width"
    CASE &H5021&: sItem = "Thumbnail image height"
    CASE &H5022&: sItem = "Thumbnail bits per sample"
    CASE &H5023&: sItem = "Thumbnail compression"
    CASE &H5024&: sItem = "Thumbnail photometric interp"
    CASE &H5025&: sItem = "Thumbnail image description"
    CASE &H5026&: sItem = "Thumbnail equip make"
    CASE &H5027&: sItem = "Thumbnail equip model"
    CASE &H5028&: sItem = "Thumbnail strip offsets"
    CASE &H5029&: sItem = "Thumbnail orientation"
    CASE &H502A&: sItem = "Thumbnail samples per pixel"
    CASE &H502B&: sItem = "Thumbnail rows per strip"
    CASE &H502C&: sItem = "Thumbnail strip bytes count"
    CASE &H502D&: sItem = "Thumbnail width"
    CASE &H502E&: sItem = "Thumbnail height"
    CASE &H502F&: sItem = "Thumbnail planar config"
    CASE &H5030&: sItem = "Thumbnail resolution unit"
    CASE &H5031&: sItem = "Thumbnail transfer function"
    CASE &H5032&: sItem = "Thumbnail software used"
    CASE &H5033&: sItem = "Thumbnail date time"
    CASE &H5034&: sItem = "Thumbnail artist"
    CASE &H5035&: sItem = "Thumbnail white point"
    CASE &H5036&: sItem = "Thumbnail primary chromaticities"
    CASE &H5037&: sItem = "Thumbnail Y Cb Cr coefficients"
    CASE &H5038&: sItem = "Thumbnail Y Cb Cr subsampling"
    CASE &H5039&: sItem = "Thumbnail Y Cb Crp positioning"
    CASE &H503A&: sItem = "Thumbnail ref black & white"
    CASE &H503B&: sItem = "Thumbnail copyright"
    CASE &H5090&: sItem = "Luminance table"
    CASE &H5091&: sItem = "Chrominance table"
    CASE &H5100&: sItem = "Frame delay"
    CASE &H5101&: sItem = "Loop count"
    CASE &H5102&: sItem = "Global palette"
    CASE &H5103&: sItem = "Index background"
    CASE &H5104&: sItem = "Index transparent"
    CASE &H5110&: sItem = "Pixel unit"
    CASE &H5111&: sItem = "Horizontal pixel per unit"
    CASE &H5112&: sItem = "Vertical pixel per unit"
    CASE &H5113&: sItem = "Palette histogram"
    CASE &H829A&: sItem = "Exposure time in seconds"
    CASE &H829D&: sItem = "F Number"
    CASE &H8822&: sItem = "Class of program used for exposure"
    CASE &H8824&: sItem = "Spectral Sensitivity of each channel"
    CASE &H8827&: sItem = "ISO Speed"
    CASE &H8828&: sItem = "Opto-Electronic Conversion Function"
    CASE &H9000&: sItem = "EXIF Version number"
    CASE &H9003&: sItem = "Date + time of original"
    CASE &H9004&: sItem = "Date + time of digitized"
    CASE &H9101&: sItem = "Configuration of components"
    CASE &H9102&: sItem = "Compression in bits per pixel"
    CASE &H9201&: sItem = "Shutter speed, in APEX unit"
    CASE &H9202&: sItem = "Lens aperture, in APEX unit"
    CASE &H9203&: sItem = "Brightness, in APEX unit"
    CASE &H9204&: sItem = "Exposure bias, unit is APEX"
    CASE &H9205&: sItem = "Smallest F number of lens, in APEX"
    CASE &H9206&: sItem = "Distance to subject, in meters"
    CASE &H9207&: sItem = "Metering Mode" ' 0 - unknown, 1 - Average, 2 - CenterWeightedAverage, 3 - Spot, 4 - MultiSpot, 5 - Pattern, 6 - Partial, 7 to 254 - reserved, 255 - other.
    CASE &H9208&: sItem = "Light Source"
    CASE &H9209&: sItem = "Strobe light (flash) source data"
    CASE &H920A&: sItem = "Focal length, in mm"
    CASE &h9214&: sItem = "Location and area of the main subject in the overall scene"
    CASE &H927C&: sItem = "Manufacturer note"
    CASE &H9286&: sItem = "Comments from user"

    CASE &H9290&: sItem = "Exif DT Subsec"
    CASE &H9291&: sItem = "Exif DT Orig SS"
    CASE &H9292&: sItem = "Exif DT Dig SS"

    CASE &HA000&: sItem = "Version of FlashPix"
    CASE &HA001&: sItem = "Color space information"
    CASE &HA002&, &H1001: sItem = "Width in pixels"
    CASE &HA003&, &H1002: sItem = "Height in pixels"
    CASE &HA004&: sItem = "Related WAV (8.3) sound file name"
    CASE &HA005&: sItem = "Exif Interop"
    CASE &HA20B&: sItem = "Strobe energy during image capture"
    CASE &HA20C&: sItem = "Input device spatial frequency"
    CASE &HA20E&: sItem = "Horizontal focal resolution (pixels/unit)"
    CASE &HA20F&: sItem = "Vertical focal resolution (pixels/unit)"
    CASE &HA210&: sItem = "Unit used for horizontal and vertical focal plane resolution"
    CASE &HA214&: sItem = "Location of the main subject"
    CASE &HA215&: sItem = "Exposure index of input device"
    CASE &HA217&: sItem = "Image sensor type on input device"
    CASE &HA300&: sItem = "Image source"
    CASE &HA301&: sItem = "Type of scene"
    CASE &HA302&: sItem = "Color filter array geometric pattern"
    CASE &HA401&: sItem = "Special processing on image data"
    CASE &HA402&: sItem = "Exposure mode"
    CASE &HA403&: sItem = "White balance"
    CASE &HA404&: sItem = "Digital zoom ratio"
    CASE &HA405&: sItem = "Equivalent focal length in 35 mm film"
    CASE &HA406&: sItem = "Type of scene that was shot"
    CASE &HA407&: sItem = "Gain"
    CASE &HA408&: sItem = "Contrast"
    CASE &HA409&: sItem = "Saturation"
    CASE &HA40A&: sItem = "Sharpness"
    CASE &HA40B&: sItem = "Information on the picture-taking conditions"
    CASE &HA40C&: sItem = "Distance to the subject"
    CASE &HA420&: sItem = "Unique image ID"
    CASE &H0000&: sItem = "Gps version"
    CASE &H0001&: sItem = "Gps latitude ref"
    CASE &H0002&: sItem = "Gps latitude"
    CASE &H0003&: sItem = "Gps longitude ref"
    CASE &H0004&: sItem = "Gps longitude"
    CASE &H0005&: sItem = "Gps altitude ref"
    CASE &H0006&: sItem = "Gps altitude"
    CASE &H0007&: sItem = "Gps time"
    CASE &H0008&: sItem = "Gps satellites"
    CASE &H0009&: sItem = "Gps status"
    CASE &H000A&: sItem = "Gps measure mode"
    CASE &H000B&: sItem = "Gps dop"
    CASE &H000C&: sItem = "Gps speed ref"
    CASE &H000D&: sItem = "Gps speed"
    CASE &H000E&: sItem = "Gps track ref"
    CASE &H000F&: sItem = "Gps track"
    CASE &H0010&: sItem = "Gps Img Dir ref"
    CASE &H0011&: sItem = "Gps Img Dir"
    CASE &H0012&: sItem = "Gps map datum"
    CASE &H0013&: sItem = "Gps Dest Lat ref"
    CASE &H0014&: sItem = "Gps Dest Lat"
    CASE &H0015&: sItem = "Gps Dest Long ref"
    CASE &H0016&: sItem = "Gps Dest Long"
    CASE &H0017&: sItem = "Gps Dest Bear ref"
    CASE &H0018&: sItem = "Gps Dest Bear"
    CASE &H0019&: sItem = "Gps Dest Dist ref"
    CASE &H001A&: sItem = "Gps Dest Dist"
    CASE &H001B&: sItem = "Gps processing method"
    CASE &H001C&: sItem = "Gps area information"
    CASE &H001D&: sItem = "Gps date"
    CASE &H001E&: sItem = "Gps differential"
    CASE ELSE
         sItem = "Unknown property"
    END SELECT
    FUNCTION = sItem + ": "
END FUNCTION

FUNCTION PBMAIN

    LOCAL pImage, pNewImage, K, imgW, imgH, numOfProperty, UsePixelFormat, nItem AS LONG
    LOCAL szTitle AS ASCIIZ * 260, zFileName AS ASCIIZ * 260
    LOCAL sMsg AS STRING
   
    ZI_LoadDLL("") '// Load GDImage
   
    zFileName = EXE.Path$ + "Annecy.jpg"
   
    pImage = zLoadImageFromFile(zFileName, imgW, imgH, 0)
    IF pImage THEN
       numOfProperty = ZI_GetImageInfoCount(pImage)
       IF numOfProperty THEN
          DIM Arraylist(1 TO numOfProperty) AS LONG
          IF ZI_GetImageInfoList(pImage, numOfProperty, ArrayList(1)) = 0 THEN
             FOR K = LBOUND(ArrayList) TO UBOUND(ArrayList)
                 nItem = ArrayList(K)
                 zTrace( "0x" + RIGHT$("0000" + HEX$(nItem), 4) + " " + PropertyToString(nItem) + ZI_GetImageInfoString(pImage, nItem) )
             NEXT
          END IF
       END IF
    END IF

    pNewImage = zCloneImage(pImage)
    IF pNewImage THEN
       zFileName = EXE.Path$ + "Annecy_modified.jpg"
       szTitle = "This is the title of the new clone image"
       IF ZI_SetImageInfoProperty(pNewImage, _
                                  %PropertyTagImageDescription, _
                                  LEN(szTitle) + 1, _              ' // Includes null terminator
                                  %PropertyTagTypeASCII, _
                                  VARPTR(szTitle) _
                                  ) = 0 THEN
          sMsg = $CR + $CR + "The name of the clone image is:" + $CR + zFileName + $CR + $CR + "Its new title is: """ + szTitle + """"
       END IF
       zSaveImageToFile (zFileName, pNewImage, 0)
       ' // Cleanup the clone
       ZI_DeleteImageObject(pNewImage)
    END IF

    ' // Cleanup the original image
    ZI_DeleteImageObject(pImage)

    MsgBox "This image has" + str$(numOfProperty) + " TAG properties" + sMsg,,"GDImage " + ZI_Version()

END FUNCTION


Added:
You can find the complete list of TAG properties in the José_Roca's GdiPlusImaging.inc include file.

And make sure you fix this small typo:
the PropertyTagTransferFuncition must be renamed to PropertyTagTransferFunction.

Screen shot:



...
Patrice Terrier
GDImage (advanced graphic addon)
http://www.zapsolution.com

Patrice Terrier

The first post of this thread has been updated, to fix the ZIP file corruption caused by the "Server Collapse".

...
Patrice Terrier
GDImage (advanced graphic addon)
http://www.zapsolution.com