« MBS FileMaker Plugin … | Home | MBS FileMaker Plugin,… »

GraphicsMagick in FileMaker, part 1

🎄
1 of 24

Welcome to the first door of our advent calendar. In this advent calendar I would like to take you on a journey through the GraphicsMagick component. Every day I will present you 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 on them and much much more. In the end, you can also take the magic of GraphicsMagick to your images. I wish you a lot of fun with it.

Today I will show you how to load an image from a file or container so that you can edit it in the later doors. When loading an image we have the possibility to load it from a container. For this we use the GMImage.NewFromContainer function. We pass the container to this function in the parameters. With this we load the image into the working memory and get a reference number as return which we can use in the other steps.

Set Variable [ $ref1 ; Value: MBS( "GMImage.NewFromContainer"; GraphicsMagick Advent::Image) ] 

If we have an image file with multiple images in a container, we have the function GMImage.NewImagesFromContainer that gives us a list of reference numbers. Each image in the container is loaded into memory and has its own reference number.

Set Variable [ $ref2 ; Value: MBS( "GMImage.NewImagesFromContainer"; GraphicsMagick Advent::Image ) ] 

The image cannot only be a container value, but also a file on your computer. You can then load this via the file path. We use the GMImage.NewFromFile function for this. We specify the native path in the parameters. If you have a FileMaker path, the path must first be converted to a native path. Then use the Path.FileMakerPathToNativePath function to do this. If you want, you can optionally specify a codec here that will take care of decoding the image.

Set Variable [ $ref3 ; Value: MBS( "GMImage.NewFromFile"; "/Users/sj/Desktop/IMG_4420.jpeg"; "JPEG") ] 

Also to this function there is of course a function that if we have several images in a file, loads these images into memory and returns us a list of references. This function is called GMImage.NewImagesFromFile.

Images can now not only be a file or container value, but also encoded as a string. We can use the functions GMImage.NewFromBase64 and GMImage.NewFromHex to receive image data as a hexadecimal string or a base64 string. The images are decoded and loaded into memory in the same way as the other functions and as return we get the reference number.

Set Variable [ $ref4 ; Value: MBS( "GMImage.NewFromBase64"; GraphicsMagick Advent::Text) ] 
Set Variable [ $Ref5 ; Value: MBS( "GMImage.NewFromHex"; GraphicsMagick Advent::Text) ] 

Before I leave you excited about door number two, I would like to explain one very important thing about working with GraphicsMagick. We store our image references in memory. If we create a new image reference then again a piece of memory is allocated. So that we don't block our memory now we free the memory when we don't need the reference anymore. We can do this with the function GMImage.Release for a single reference by specifying the reference number to be released in the parameters, or for all reference numbers with the function GMImage.ReleaseAll.

Set Variable [ $r ; Value: MBS( "GMImage.Release"; $ref1 ) ] 
Set Variable [ $r ; Value: MBS( "GMImage.ReleaseAll" ) ]

Tomorrow we will continue. I wish you a nice first of December

Next day

01 12 22 - 09:07