GraphicsMagick in FileMaker, part 4
🎄 |
4 of 24 |
Welcome to the fourth 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 I will show you how to paint a border around an image. The focus is on the GMImage.Border function. This function again requires our reference.
Set Variable [ $r ; Value: MBS( "GMImage.Border"; $GM) ]
When we use the function like this, a gray fine border is drawn around the image by default. If the image is very large, as you can see here, it is not so noticeable.
But we can change that. In the function itself we can change the thickness of the frame by specifying a geometry and we can change the color of the frame. Let's start with the thickness of the border. In a geometry we specify a width and height. In our case the thickness of the border. The two values are separated from each other with an x. If I enter as geometry e.g. 200x0 then our frame looks like this.
Set Variable [ $r ; Value: MBS( "GMImage.Border";$GM; "200x0") ]
Left and right we have now a frame of 200 pixel. If we invert the values, we get a frame at the top and bottom.
But we can change not only the thickness of the border, but also the color. The color must be set before we paint the border. For this we use the GMImage.SetBorderColor function. In the parameters we specify the reference and the color. The color can be specified in different color spaces. Here you can see a list of the color spaces that are possible:
- HSL h s l a
- YUV y u v a
- RGB r g b a
- MONO m a
- GRAY g a
- COLOR R G B a
also you can specify a color value as a hexadecimal number. As you can see, you can also always define an alpha value, which means we define the transparency. This value is between 0.0 and 1.0.
Set Variable [ $GM ; Value: MBS("GMImage.NewFromFile"; "/Users/sj/Desktop/abc.png") ] Set Variable [ $r ; Value: MBS( "GMImage.SetBorderColor"; $GM; "#FF000034" ) ] Set Variable [ $r ; Value: MBS( "GMImage.Border";$GM; "200x200") ] Set Field [ GraphicsMagick Advent::Image ; MBS( "GMImage.WriteToContainer"; $GM ; "abc.png" ) ] Set Variable [ $r ; Value: MBS( "GMImage.Release"; $GM ) ]
In the example code I have defined a hexadecimal number that describes a color that is red and has a high transparency. The result looks like this.
Of course, you can choose the colors that you like. Here you see for example a picture with a purple (#6959CD) frame. The frame has the size 500x500.
So give your pictures the frame you need. Tomorrow we will continue. Until then have a nice 4th of December