GMImage.Threshold
-----------------

Threshold image channels (below threshold becomes black, above threshold becomes white).

| Component | Version | macOS | Windows | Linux | Server | iOS SDK |
|---|---|---|---|---|---|---|
| [GraphicsMagick](component_GraphicsMagick.md) | [2.0](newinversion20.md) | ✅ Yes | ✅ Yes | ✅ Yes | ✅ Yes | ✅ Yes |

MBS( "GMImage.Threshold"; ImageRef { ; threshold } ) 

**MBS**( **"GMImage.Threshold";** /\* Threshold image channels (below threshold becomes black, above threshold becomes white). \*/  
**$ImageRef**; /\* The image reference number.e.g. 1 \*/   
**$threshold**) /\* Optional; The range of the threshold parameter is 0 to MaxRGB (65535).e.g. 127\*256 \*/ 

### Parameters

| Parameter | Description | Example | Flags |
|---|---|---|---|
| ImageRef | The image reference number. | 1 |  |
| threshold | The range of the threshold parameter is 0 to MaxRGB (65535). | 127\*256 | Optional |

### Result

Returns "OK" on success.

### Description

Threshold image channels (below threshold becomes black, above threshold becomes white).  
### Examples

Applies a threshold on the image:

 Let ( \[   
$Image = MBS ("[GMImage.NewFromContainer](GMImageNewFromContainer.md)"; GraphicsMagick::image );   
$Result = MBS ("GMImage.Threshold";$Image ; 127);   
$Result = MBS ("[GMImage.WriteToJPEGContainer](GMImageWriteToJPEGContainer.md)"; $Image );   
$Error = MBS ("[GMImage.Release](GMImageRelease.md)";$Image )  
\];   
$Result )  
Convert image to 1 bit TIFF:

 # Load from container   
Set Variable \[ $Image ; Value: MBS ("[GMImage.NewFromContainer](GMImageNewFromContainer.md)"; GraphicsMagick::image ); \]  
  
\# make black and white with threshold   
Set Variable \[ $Result ; Value: MBS ("GMImage.Threshold";$Image ; 127); \]  
  
\# mark as monochrome image   
Set Variable \[ $Result ; Value: MBS ("[GMImage.SetMonochrome](GMImageSetMonochrome.md)";$Image ; 1); \]  
  
\# set type to 1 for black/white   
Set Variable \[ $Result ; Value: MBS ("[GMImage.SetType](GMImageSetType.md)";$Image ; 1); \]  
  
\# set to use TIFF for compression   
Set Variable \[ $Result ; Value: MBS ("[GMImage.SetMagick](GMImageSetMagick.md)";$Image ; "TIFF"); \]  
  
\# set to use CCITT 4 Fax compression   
Set Variable \[ $Result ; Value: MBS ("[GMImage.SetCompressType](GMImageSetCompressType.md)";$Image ; 4); \]  
  
\# and write to a file   
Set Variable \[ $Result ; Value: MBS ("[GMImage.WriteToFile](GMImageWriteToFile.md)"; $Image ; "/tmp/test.tif"); \]  
  
\# cleanup   
Set Variable \[ $Error ; Value: MBS ("[GMImage.Release](GMImageRelease.md)";$Image ) \]  
Make a picture black and transparent:

 Set Variable \[$image ; Value:MBS ( "[GMImage.NewFromContainer](GMImageNewFromContainer.md)"; Test::BigImage )\]  
Set Variable \[$r ; Value:MBS ( "GMImage.Threshold"; $image ; 127)\]  
Set Variable \[$imagecolor ; Value:MBS ( "[GMImage.Transparent](GMImageTransparent.md)"; $image ; "white")\]  
Set Field \[Test::Result ; MBS ( "[GMImage.WriteToPNGContainer](GMImageWriteToPNGContainer.md)"; $image ;)\]  
Set Variable \[$Error ; Value:MBS ("[GMImage.Release](GMImageRelease.md)";$image )\]  
### See also

- [GMImage.New](GMImageNew.md)
- [GMImage.Release](GMImageRelease.md)
- [GMImage.SetCompressType](GMImageSetCompressType.md)
- [GMImage.SetMagick](GMImageSetMagick.md)
- [GMImage.SetType](GMImageSetType.md)
- [GMImage.Transparent](GMImageTransparent.md)
- [GMImage.WriteToFile](GMImageWriteToFile.md)
- [GMImage.WriteToJPEGContainer](GMImageWriteToJPEGContainer.md)
- [GMImage.WriteToPNGContainer](GMImageWriteToPNGContainer.md)
- [GMImage.WriteToTiffContainer](GMImageWriteToTiffContainer.md)

### Example Databases

- [GraphicsMagick/GraphicsMagick Sample](https://www.mbsplugins.eu/MBS-FileMaker-Plugin-Examples/GraphicsMagick/GraphicsMagick%20Sample.shtml#21ScriptAnchor_)

### Blog Entries

- [GraphicsMagick in FileMaker, part 9](https://www.mbsplugins.de/archive/2022-12-09/GraphicsMagick_in_FileMaker_pa/monkeybreadsoftware_blog_filemaker)
- [GraphicsMagick in FileMaker, part 8](https://www.mbsplugins.de/archive/2022-12-08/GraphicsMagick_in_FileMaker_pa/monkeybreadsoftware_blog_filemaker)

This function checks for a license.

Created 18th August 2014 , last changed 25th February 2026

  
[GMImage.Texture](GMImageTexture.md) - [GMImage.TotalColors](GMImageTotalColors.md)

[HTML Version](GMImageThreshold.shtml)