GMImage.Trim
------------

Trim edges that are the background color from the image.

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

MBS( "GMImage.Trim"; ImageRef ) 

**MBS**( **"GMImage.Trim";** /\* Trim edges that are the background color from the image. \*/  
**$ImageRef**) /\* The image reference number.e.g. 1 \*/ 

### Parameters

| Parameter | Description | Example |
|---|---|---|
| ImageRef | The image reference number. | 1 |

### Result

Returns "OK" on success.

### Description

Trim edges that are the background color from the image.   
Use [GMImage.SetColorFuzz](GMImageSetColorFuzz.md) to set the fuzzy level.  
  
Trim looks on what pixel colors the edges have and checks if there is a smaller rectangle where all pixel outside have same color. See [GMImage.BoundingBox](GMImageBoundingBox.md) for the bounding box of content.  
### Examples

Trim a picture:

 Set Variable \[$BigImageRef ; Value:MBS ("[GMImage.NewFromContainer](GMImageNewFromContainer.md)"; Test::BigImage )\]  
Set Variable \[$Result ; Value:MBS ( "[GMImage.SetColorFuzz](GMImageSetColorFuzz.md)"; $BigImageRef ; 100 )\]  
Set Variable \[$Result ; Value:MBS ("GMImage.Trim"; $BigImageRef )\]  
Set Field \[Test::Result ; MBS ( "[GMImage.WriteToJPEGContainer](GMImageWriteToJPEGContainer.md)"; $BigImageRef )\]  
Set Variable \[$Error ; Value:MBS ("[GMImage.Release](GMImageRelease.md)";$BigImageRef )\]  
Trim white around picture:

 Set Variable \[$BigImageRef ; Value:MBS ("[GMImage.NewFromContainer](GMImageNewFromContainer.md)"; Test::BigImage )\]  
\#set one white pixel to make sure it trims only white   
Set Variable \[$Result ; Value:MBS ( "[GMImage.SetPixelColor](GMImageSetPixelColor.md)"; $BigImageRef ; 0; 0; "white" )\]  
\#allows up to 5 away into gray for comparing to white   
Set Variable \[$Result ; Value:MBS ( "[GMImage.SetColorFuzz](GMImageSetColorFuzz.md)"; $BigImageRef ; 5 )\]  
Set Variable \[$Result ; Value:MBS ("GMImage.Trim"; $BigImageRef )\]  
Set Field \[Test::Result ; MBS ( "[GMImage.WriteToJPEGContainer](GMImageWriteToJPEGContainer.md)"; $BigImageRef )\]  
Set Variable \[$Error ; Value:MBS ("[GMImage.Release](GMImageRelease.md)";$BigImageRef )\]  
Trims space around image and make transparent:

 Set Variable \[$BigImageRef ; Value:MBS ("[GMImage.NewFromContainer](GMImageNewFromContainer.md)"; Test::BigImage )\]  
Set Variable \[$Result ; Value:MBS ( "[GMImage.SetBackgroundColor](GMImageSetBackgroundColor.md)"; $BigImageRef ; "RGB 1 0 0" )\]  
Set Variable \[$Result ; Value:MBS ("GMImage.Trim"; $BigImageRef )\]  
Set Variable \[$Result ; Value:MBS ( "[GMImage.SetColorFuzz](GMImageSetColorFuzz.md)"; $BigImageRef ; 5 )\]  
Set Variable \[$Result ; Value:MBS ( "[GMImage.SetMatte](GMImageSetMatte.md)"; $BigImageRef ; 1 )\]  
Set Variable \[$farbe ; Value:MBS ( "[GMImage.GetPixelColor](GMImageGetPixelColor.md)"; $BigImageRef ; 0; 0 )\]  
Set Variable \[$Result ; Value:MBS ( "[GMImage.ReplaceColor](GMImageReplaceColor.md)"; $BigImageRef ; $farbe ; "RGB 1 1 1 1"; 5)\]  
Set Field \[Test::Result ; MBS ( "[GMImage.WriteToPNGContainer](GMImageWriteToPNGContainer.md)"; $BigImageRef )\]  
Set Variable \[$Error ; Value:MBS ("[GMImage.Release](GMImageRelease.md)";$BigImageRef )\]  
### See also

- [GMImage.Flip](GMImageFlip.md)
- [GMImage.Frame](GMImageFrame.md)
- [GMImage.NewFromContainer](GMImageNewFromContainer.md)
- [GMImage.SetColorFuzz](GMImageSetColorFuzz.md)
- [GMImage.SetMatte](GMImageSetMatte.md)
- [GMImage.SetPixelColor](GMImageSetPixelColor.md)
- [GMImage.Strip](GMImageStrip.md)
- [GMImage.WriteToJPEGContainer](GMImageWriteToJPEGContainer.md)
- [GMImage.WriteToPNGContainer](GMImageWriteToPNGContainer.md)
- [GMImage.Zoom](GMImageZoom.md)

### Example Databases

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

This function checks for a license.

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

  
[GMImage.Transparent](GMImageTransparent.md) - [GMImage.Unsharpmask](GMImageUnsharpmask.md)

[HTML Version](GMImageTrim.shtml)