Tech Tip: Extracting blocks of picture metadata
PRODUCT: 4D | VERSION: 12.2 | PLATFORM: Mac & Win
Published On: August 18, 2011
As of 4D v12, picture metadata can be extracted from a picture field or variable using the GET PICTURE METADATA command. This command is capable, among other things, of returning an entire block of metadata with a single call. A block being "TIFF", "EXIF", "GPS" or "IPTC".
Given this new command, it is a relatively straightforward task to extract all picture metadata. Here is a sample method that extracts all the metadata from a picture file. In this example, the method simply generates an XML file with all of the metadata.
C_STRING(16;$xml_root;$xml_TIFF;$xml_GPS;$xml_EXIF;$xml_IPTC) C_PICTURE($1;$image_i) $image_i:=$1 $xml_root:=DOM Create XML Ref("Root") // Creation of an XML DOM tree $xml_TIFF:=DOM Create XML element($xml_root;"/Root/TIFF") GET PICTURE METADATA($image_i;"TIFF";$xml_TIFF) $xml_GPS:=DOM Create XML element($xml_root;"/Root/GPS") GET PICTURE METADATA($image_i;"GPS";$xml_GPS) $xml_EXIF:=DOM Create XML element($xml_root;"/Root/EXIF") GET PICTURE METADATA($image_i;"EXIF";$xml_EXIF) $xml_IPTC:=DOM Create XML element($xml_root;"/Root/IPTC") GET PICTURE METADATA($image_i;"IPTC";$xml_IPTC) DOM EXPORT TO FILE($xml;Get 4D folder(Database Folder)+"image_meta.xml") DOM CLOSE XML($xml) |
Here is an example of the XML output, when this code is run on a picture variable which contains some metadata:
<?xml version="1.0" encoding="UTF-8" standalone="no" ?> <Root> <TIFF DateTime="2004-03-10T09:37:27Z" Make="Canon" Model="Canon DIGITAL IXUS 400" Orientation="1" ResolutionUnit="2" Software="Adobe Photoshop 7.0" XResolution="180" YResolution="180"/> <GPS/> <EXIF ApertureValue="5.65625" ColorSpace="1" ComponentsConfiguration="1;2;3;0" CompressedBitsPerPixel="5" CustomRendered="0" DateTimeDigitized="2004-03-09T17:47:30Z" DateTimeOriginal="2004-03-09T17:47:30Z" DigitalZoomRatio="1" ExifVersion="0220" ExposureBiasValue="0" ExposureMode="0" ExposureTime="0.0025" FNumber="7.1" FileSource="3" Flash="24" FlashPixVersion="0100" FocalLength="7.40625" FocalPlaneResolutionUnit="2" FocalPlaneXResolution="8114.2857142857" FocalPlaneYResolution="8114.2857142857" MaxApertureValue="2.96875" MeteringMode="5" PixelXDimension="2272" PixelYDimension="1704" SceneCaptureType="0" SensingMethod="2" ShutterSpeedValue="8.65625" WhiteBalance="0"/> <IPTC/> </Root> |
Here is another example showing what the XML will look like if the picture contained no metadata.
<?xml version="1.0" encoding="UTF-8" standalone="no" ?> <Root> <TIFF/> <GPS/> <EXIF/> <IPTC/> </Root> |
Notice that all 4 blocks are empty.