GraphicsMagick in FileMaker, part 19
🎄 |
19 of 24 |
Welcome to the 19th door of our advent calendar. In this advent calendar I would like to take you on a journey through the GraphicsMagick component in December. Every day I will introduce you to one or more functions from this component. In this component you will find functions with which you can analyze images, convert them, change them with filters, draw them and much much more. In the end, you too can take the magic of GraphicsMagick to your images. I wish you a lot of fun in the process.
We have already seen in door 2 that we can query some information about an image. If we have photos, but also the metadata created by the device when taking the picture are very interesting. Today I want to show you how you can retrieve some of this information.
We use the functions GMImage.GetAttribute for this purpose. But before we start with this function I would like to introduce you to name related functions. On the one hand we have the GMImage.GetAttributesJSON function. It returns the attributes that have been created before as JSON.
Set Variable [ $JSON ; Value: MBS( "GMImage.GetAttributesJSON"; $GM ) ]
In the image we can see in the field how this JSON can look like.
These values can then be read out with the JSON function of FileMaker or the plugin.
If we want to have the names of the single attributes we can use the GMImage.GetAttributeNames. For example, we can output the attribute names in a dialog. These are returned by the function as a list.
Show Custom Dialog [ "Attribute names" ; MBS( "GMImage.GetAttributeNames";$GM) ]
We see when we open the info of the image on the computer that there is still a lot of information behind it that we don't get through the JSON.
This is because in both functions only attributes created before are visible, so e.g. EXIF data may not yet be loaded and parsed. But with the GMImage.GetAttribute function we can retrieve EXIF data by specifically querying the individual attributes. In the function we first specify our reference and then the name of the attribute. Optionally we can specify the encoding of the text. As return we get our value to the matching attribute. If we want to retrieve a value from the EXIF data, it is not enough to specify the tag name, but we have to specify the tag further, so that the attribute name has the following form:EXIF:Attribute tag
In our example we have stored a list of some possible EXIF attribute names.
In our example we go through this list and append the tag and the corresponding value to the result string which we then output in a field. Here is the code for this:
Set Variable [ $GM ; Value: MBS("GMImage.NewFromContainer"; GraphicsMagick Advent::Image) ] Set Variable [ $tags ; Value: "GPSLatitudeRef¶GPSLatitude¶GPSLongitudeRef¶GPSLongitude¶ GPSAltitudeRef¶GPSAltitude¶GPSTimeStamp¶GPSSatellites¶GPSStatus¶GPSMeasureMode¶GPSDOP¶ GPSSpeedRef¶GPSSpeed¶GPSTrackRef¶GPSTrack¶GPSImgDirectionRef¶GPSImgDirection¶ GPSMapDatum¶GPSDestLatitudeRef¶GPS..." ] Set Variable [ $count ; Value: ValueCount ( $tags ) ] Set Variable [ $index ; Value: 1 ] Set Variable [ $result ; Value: "" ] Loop # get the property name from the list Set Variable [ $tag ; Value: GetValue ( $tags; $index ) ] # Get the value of the property Set Variable [ $value ; Value: MBS("GMImage.GetAttribute"; $GM; "EXIF:" & $tag) ] If [ $value ≠ "unknown" ] # add the property and the value to the result Set Variable [ $result ; Value: $result & $tag & ": " & $value & "¶" ] End If Set Variable [ $index ; Value: $index +1 ] Exit Loop If [ $index > $count ] End Loop Set Field [ GraphicsMagick Advent::Result ; $result ] Set Variable [ $r ; Value: MBS("GMImage.Free"; $GM) ]
We then first look how many entries we have in this list. Set our index to 1 because we start with a FileMaker list with an index of 1. In the loop we get each Tag from the list, put the string together appropriately in the function call and then get the appropriate value. We can see that in this line:
Set Variable [ $value ; Value: MBS("GMImage.GetAttribute"; $GM; "EXIF:" & $tag) ]If we have a value that is not unknown, then we append this information to our result.
When the loop is finished, we write the result text in the field and release our reference.
I hope you enjoyed this door and I will see you again tomorrow.