Topics   All   MacOS (Only)   Windows (Only)   Linux (Only, Not)   iOS (Only, Not)  
Components   Crossplatform Mac & Win   Server   Client   Old   Deprecated   Guides   Examples   Videos
New in version: 9.5   10.0   10.1   10.2   10.3   10.4   10.5   11.0   11.1   11.2    Statistic    FMM    Blog  

GMImage.Quantize

Quantize image (reduce number of colors).

Component Version macOS Windows Linux Server iOS SDK
GraphicsMagick 2.0 ✅ Yes ✅ Yes ✅ Yes ✅ Yes ✅ Yes
MBS( "GMImage.Quantize"; ImageRef { ; measureError } )   More

Parameters

Parameter Description Example Flags
ImageRef The image reference number. 1
measureError Optionally, a boolean value. 0 Optional

Result

Returns "OK" on success.

Description

Quantize image (reduce number of colors).
See GMImage.SetQuantizeColorSpace, GMImage.SetQuantizeColors, GMImage.SetQuantizeDither and GMImage.SetQuantizeTreeDepth for options.

Examples

Quantize picture:

Set Variable [ $BigImageRef ; Value: MBS("GMImage.NewFromContainer"; Test::BigImage) ]
# reduce to 20 colors, so we see the effect. Normally 256
Set Variable [ $Result ; Value: MBS( "GMImage.SetQuantizeColors"; $BigImageRef; 20) // 256 ) ]
# Enable dithering, turn off to really see the effect
Set Variable [ $Result ; Value: MBS( "GMImage.SetQuantizeDither"; $BigImageRef; 1 ) ]
# Quantize to palette colors
Set Variable [ $Result ; Value: MBS( "GMImage.SetQuantizeColorSpace"; $BigImageRef; 4 /* palette */ ) ]
# Do it!
Set Variable [ $Result ; Value: MBS("GMImage.Quantize"; $BigImageRef) ]
# Type should now be 4 for palette
Set Variable [ $Result ; Value: MBS("GMImage.GetType"; $BigImageRef) ]
# save as GIF
Set Field [ Test::Result ; MBS( "GMImage.WriteToGIFContainer"; $BigImageRef ) ]
Set Variable [ $Error ; Value: MBS("GMImage.Release";$BigImageRef) ]

See also

Created 18th August 2014, last changed 21st December 2018


GMImage.PushClipPath - GMImage.QuantumDepth

Feedback: Report problem or ask question.