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.2   6.3   6.4   6.5   7.0   7.1   7.2   7.3   7.4   7.5    Statistic  

GMImage.Trim

Trim edges that are the background color from the image.

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

MBS( "GMImage.Trim"; ImageRef )

Parameters

Parameter Description Example value
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 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.

Examples

Trim a picture:

Set Variable [$BigImageRef; Value:MBS("GMImage.NewFromContainer"; Test::BigImage)]
Set Variable [$Result; Value:MBS( "GMImage.SetColorFuzz"; $BigImageRef; 100 )]
Set Variable [$Result; Value:MBS("GMImage.Trim"; $BigImageRef)]
Set Field [Test::Result; MBS( "GMImage.WriteToJPEGContainer"; $BigImageRef )]
Set Variable [$Error; Value:MBS("GMImage.Destroy";$BigImageRef)]

Trim white around picture:

Set Variable [$BigImageRef; Value:MBS("GMImage.NewFromContainer"; Test::BigImage)]
#set one white pixel to make sure it trims only white
Set Variable [$Result; Value:MBS( "GMImage.SetPixelColor"; $BigImageRef; 0; 0; "white" )]
#allows up to 5 away into gray for comparing to white
Set Variable [$Result; Value:MBS( "GMImage.SetColorFuzz"; $BigImageRef; 5 )]
Set Variable [$Result; Value:MBS("GMImage.Trim"; $BigImageRef)]
Set Field [Test::Result; MBS( "GMImage.WriteToJPEGContainer"; $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.Transparent   -   GMImage.Unsharpmask

Feedback: Report problem or ask question.




Links
MBS Xojo Chart Plugins