« MBS FileMaker Plugin,… | Home | Change brightness sat… »

GraphicsMagick in FileMaker, part 8

8 of 24

Welcome to the 8th 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 would like to show you how to convert your image into a black and white image or how to display it in grayscale. Let's start with the grayscale. For this we use the function GMImage.SetType. This function sets the repression type of the image. We can specify the following values:

  • UndefinedType = 0
  • BilevelType = 1
  • GrayscaleType = 2
  • GrayscaleMatteType = 3
  • PaletteType = 4
  • PaletteMatteType = 5
  • TrueColorType = 6
  • TrueColorMatteType = 7
  • ColorSeparationType = 8
  • ColorSeparationMatteType = 9
  • OptimizeType = 10

You can do very cool things with these types. We are only interested in the value two, because with it we can convert an image from a color image to a grayscale image. You can see the script for this here:

Set Variable [ $GM ; Value: MBS("GMImage.NewFromContainer"; GraphicsMagick Advent::Image) ] 
Set Variable [ $r ; Value: MBS( "GMImage.SetType"; $GM; 2 ) ] 
Set Field [ GraphicsMagick Advent::Image ; MBS( "GMImage.WriteToContainer"; $GM ; "abc.png" ) ] 
Set Variable [ $r ; Value: MBS( "GMImage.ReleaseAll" ) ] 

But with this function we can't make the image only black and white, for that we need another function, the GMImage.Threshold function. If you want to convert an image into a black and white image then it is enough to pass the image reference to this function.

With this function we can set the value from which a color is interpreted as white. For this we have the optional parameter Threshold. The values of this threshold can be between 0 (everything is interpreted as white) and 65535 (everything is interpreted as black). Here you can see the image with a threshold of 50,000. The branches which are paler and cannot be seen at all with the default value are clearly displayed.

In the next image we have chosen a threshold of 12,500 here we see lighter areas in the forest floor.

Try it out and get creative. Hope to see you again tomorrow for the opening of the next door.

Previous day   Next day

08 12 22 - 07:41