Topics   All   Mac OS X (Only)   Windows (Only)   Linux (Only, Not)   iOS (Only, Not)  
Components   Crossplatform Mac & Win   Server (Not)   Client   Old   Guides   Examples
New in version: 6.3   6.4   6.5   7.0   7.1   7.2   7.3   7.4   7.5   7.6    Statistic  

GMImage.ReplaceColor

Replaces a color with another color value for the whole image.

Component Version macOS Windows Server FileMaker Cloud FileMaker iOS SDK
GraphicsMagick 4.3 Yes Yes Yes Yes Yes

MBS( "GMImage.ReplaceColor"; ImageRef; color1; color2 { ; Tolerance } )

Parameters

Parameter Description Example value
ImageRef The image reference number. 1
color1 A color value.
This can be a string in the following format "HSL h s l a", "YUV y u v a", "RGB r g b a", "MONO m a", "GRAY g a" or "COLOR R G B a". Alpha value a is optional. Range of values is 0 to 1.0 except if you use COLOR where RGB values are 0 to 255.
Starting with version 5.4 of our plugin, you can use hex notation. # followed by 2 digits for red, green, blue and optional alpha, e.g. #FF0000 for full red.
"RGB 1 0 0"
color2 A color value.
This can be a string in the following format "HSL h s l a", "YUV y u v a", "RGB r g b a", "MONO m a", "GRAY g a" or "COLOR R G B a". Alpha value a is optional. Range of values is 0 to 1.0 except if you use COLOR where RGB values are 0 to 255.
Starting with version 5.4 of our plugin, you can use hex notation. # followed by 2 digits for red, green, blue and optional alpha, e.g. #FF0000 for full red.
"RGB 0 1 0"
Tolerance Optional
The tolerance to allow for a match. Pass 1 to have one channel be matched if value is one away, e.g. 128 is accepted if searched for 127 or 129. Default is 0.
1

Result

Returns OK or error.

Description

Replaces a color with another color value for the whole image.
Match is exact, so no fuzzy matching.

Examples

Replaces a nearly white color with red:

Set Variable [$img; Wert:MBS( "GMImage.NewFromContainer"; Replace Colors::Input)]
Set Variable [$r; Wert:MBS( "GMImage.ReplaceColor"; $img; "COLOR 254 254 254"; "COLOR 255 0 0")]
Set Variable [Replace Colors::Output; MBS( "GMImage.WriteToPNGContainer"; $img; "logo.png" )]
Set Variable [$r; Wert:MBS( "GMImage.Destroy"; $img )]

Replace white with transparent:

Set Variable [$BigImageRef; Value:MBS("GMImage.NewFromContainer"; Test::BigImage)]
# Set type to RGBA
Set Variable [$Result; Value:MBS("GMImage.SetType"; $BigImageRef; 7)]
# Replace white with transparent
Set Variable [$Result; Value:MBS("GMImage.ReplaceColor"; $BigImageRef; "white"; "transparent"; 10)]
# save as PNG
Set Field [Test::Result; MBS( "GMImage.WriteToPNGContainer"; $BigImageRef )]
Set Variable [$Error; Value:MBS("GMImage.Destroy";$BigImageRef)]

Trims space around image and make transparent:

Set Variable [$BigImageRef; Value:MBS("GMImage.NewFromContainer"; Test::BigImage)]
Set Variable [$Result; Value:MBS( "GMImage.SetBackgroundColor"; $BigImageRef; "RGB 1 0 0" )]
Set Variable [$Result; Value:MBS("GMImage.Trim"; $BigImageRef)]
Set Variable [$Result; Value:MBS( "GMImage.SetColorFuzz"; $BigImageRef; 5 )]
Set Variable [$Result; Value:MBS( "GMImage.SetMatte"; $BigImageRef; 1 )]
Set Variable [$farbe; Value:MBS( "GMImage.GetPixelColor"; $BigImageRef; 0; 0 )]
Set Variable [$Result; Value:MBS( "GMImage.ReplaceColor"; $BigImageRef; $farbe; "RGB 1 1 1 1"; 5)]
Set Field [Test::Result; MBS( "GMImage.WriteToPNGContainer"; $BigImageRef )]
Set Variable [$Error; Value:MBS("GMImage.Destroy";$BigImageRef)]

See also

Example Databases


GMImage.ReduceNoise   -   GMImage.Roll

Feedback: Report problem or ask question.




Links
MBS FileMaker tutorial videos