Components All New MacOS Windows Linux iOS
Examples Mac & Win Server Client Guides Statistic FMM Blog Deprecated Old

GMImage.SetColorFuzz

Sets the color fuzz.

Component Version macOS Windows Linux Server iOS SDK
GraphicsMagick 2.0 ✅ Yes ✅ Yes ✅ Yes ✅ Yes ✅ Yes
MBS( "GMImage.SetColorFuzz"; ImageRef; value )   More

Parameters

Parameter Description Example
ImageRef The image reference number. 1
value a float number.

Since MBS Plugin 9.x uses 16-bit values, please multiple by 257 to expand older 8-bit values to 16-bit.
50 * 257

Result

Returns "OK" on success.

Description

Sets the color fuzz.
Colors within this distance are considered equal.
Used for example with GMImage.Trim function.
Range is from 0 to 65535 with zero being no fuzz and 65535 to match all colors.
Useful range may be around 50*257.

Examples

Trim a picture:

Set Variable [$BigImageRef; Value:MBS("GMImage.NewFromContainer"; Test::BigImage)]
Set Variable [$Result; Value:MBS( "GMImage.SetBackgroundColor"; $BigImageRef; "white" )]
Set Variable [$Result; Value:MBS( "GMImage.SetColorFuzz"; $BigImageRef; 50*257 )]
Set Variable [$Result; Value:MBS("GMImage.Trim"; $BigImageRef)]
Set Field [Test::Result; MBS( "GMImage.WriteToJPEGContainer"; $BigImageRef )]
Set Variable [$Error; Value:MBS("GMImage.Release";$BigImageRef)]

Make a picture transparent:

#load a picture
Set Variable [$image; Value:MBS( "GMImage.NewFromContainer"; Test::BigImage)]
#white in RGB
Set Variable [$f; Value:"white"]
#Replace all white with nearly white
Set Variable [$r; Value:MBS( "GMImage.ReplaceColor"; $image; $f; "white"; 0)]
#now flood fill it with 5 as tolerance
Set Variable [$r; Value:MBS( "GMImage.SetColorFuzz"; $image; 5 )]
Set Variable [$r; Value:MBS( "GMImage.FloodFillColorXY"; $image; 0; 0; $f )]
#now set back fuzz and make transparent using white
Set Variable [$r; Value:MBS( "GMImage.SetColorFuzz"; $image; 0 )]
Set Variable [$imagecolor; Value:MBS( "GMImage.Transparent"; $image; $f)]
#write back to container
Set Field [Test::Result; MBS( "GMImage.WriteToPNGContainer"; $image;)]
#cleanup
Set Variable [$Error; Value:MBS("GMImage.Release";$image)]

See also

Example Databases

This function checks for a license.

Created 18th August 2014, last changed 14th October 2022


GMImage.SetClassType - GMImage.SetColorMap