« GraphicsMagick in Fil… | Home | Follow up on SMTP wit… »

GraphicsMagick in FileMaker, part 6

🎄
6 of 24

Welcome to the 6th 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.

Today we want to rotate the image and for this we use the function GMImage.Rotate. In the parameters we first specify the reference and then the number of degrees by which we want to rotate the image. The image will be rotated clockwise if the degree is positive and counterclockwise if the degree is negative. In our example file, I have included two buttons that rotate the image clockwise and counterclockwise. Both buttons call the same script. When pressing the buttons, different script parameters are passed, so we know which button was pressed. Clockwise passes the 0 and counterclockwise passes the 1. By how many degrees we want to rotate the image we specify in the appropriate field. The script looks like this:

Set Variable [ $direction ; Value: Get(ScriptParameter) ] 
If [ $direction=1 ] 
	Set Variable [ $degrees ; Value: Abs ( GraphicsMagick Advent::RotationDegree )*-1 ] 
Else
	Set Variable [ $degrees ; Value: Abs ( GraphicsMagick Advent::RotationDegree ) ] 
End If
Set Variable [ $GM ; Value: MBS("GMImage.NewFromContainer"; GraphicsMagick Advent::Image) ] 
Set Variable [ $r ; Value: MBS( "GMImage.Rotate"; $GM; $degrees ) ] 
Set Field [ GraphicsMagick Advent::Image ; MBS( "GMImage.WriteToContainer"; $GM ; "abc.png" ) ] 
Set Variable [ $r ; Value: MBS( "GMImage.Release"; $GM ) ] 

So we first get the parameter that gives us the direction. If it is a 1 then we get the amount of degrees that is in the field and multiply it by -1 since the button was pressed counterclockwise. We take the amount so that in case the user entered a negative number we would still rotate counterclockwise. A negative number multiplied by -1 would otherwise result in a positive number and we would rotate clockwise again. If the script parameter was not 1, it can only be a zero or the script was started otherwise and in these two cases we want to rotate clockwise. Before we can rotate the image, we must first load the image from the container into a reference and then we can apply the rotation to it. As we already know, the image is then saved again and the reference is released.

I hope you are looking at your pictures from the right angle now. I hope you have fun trying it out. Let's see tomorrow if our image fits as well as today.

Previous day   Next day

Claris FileMaker Plugin
06 12 22 - 06:58