|17 of 24
Welcome to the 17th 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 it will be really colorful, at least today we want to try some backgrounds for our logo. Our original image has a red background.
Now we want to replace it with another color. For this we use the GMImage.ReplaceColor. In this function we have again our reference in the parameters and then we specify the color that should be replaced. We also specify a second color to replace the color we just defined. We can also specify a factor for how much the color value that should be replaced can deviate so that a replacement is performed. But for now we want to ignore this optional parameter. In our image with the logo the background has the color red. To be more precise #EB3D00 as hexadecimal. We don't have anything else on the image that is red and thus would be replaced as well. Now we want to replace the background with green, so we specify #66CD00 as another color parameter. This color describes a toxic green
Set Variable [ $r ; Value: MBS( "GMImage.ReplaceColor"; $GM; "#EB3D00"; "#66CD00") ]
Of course we can do this with any colors
If we give the whole thing a black background we can see it best. Around the logo a very fine red border remains.
The reason is that the logo pixels mix slightly with the color of the background to create a smooth transition in the image. Since these pixels are not exactly the color we specified in the function, they are not replaced the way the function is currently used. But we can change this by defining a deviation factor for the exchange color value. This factor must be multiplied by 257 since version 9 of the plugin uses 16-bit values. So if we specify a tolerance of 1*257, the specified color in your channel can deviate by 1. To make the red border disappear we choose a 50*257
Set Variable [ $r ; Value: MBS( "GMImage.ReplaceColor"; $GM; "#EB3D00"; "#000000"; 50 * 257 ) ]
I hope you enjoyed it again this time and now you bring a little buzz in your pictures we'll see you again tomorrow. See you soon.