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.Crop

Crop image (subregion of original image).

Component Version macOS Windows Linux Server iOS SDK
GraphicsMagick 2.0 ✅ Yes ✅ Yes ✅ Yes ✅ Yes ✅ Yes
MBS( "GMImage.Crop"; ImageRef; geometry )   More

Parameters

Parameter Description Example
ImageRef The image reference number. 1
geometry The rectangle to crop.
Geometry is specified as a width and height "100x200". With an optional offset "100x200+10+20". For percent values, add a percent on the end, for % values add a %: "100x200%!"
"100x200"

Result

Returns "OK" on success.

Description

Crop image (subregion of original image).
You can add pixels with GMImage.Border function.

Examples

Crops the image:

Let ( [
$Image = MBS("GMImage.NewFromContainer"; GraphicsMagick::image);
$Width = MBS("GMImage.GetWidth";$Image);
$Height = MBS("GMImage.GetHeight";$Image);
$Width = $Width/2;
$Height = $Height/2;
$ScaleResult = MBS("GMImage.Crop";$Image; $Width & "x" & $Height);
$Result = MBS("GMImage.WriteToPNGContainer"; $Image);
$Error = MBS("GMImage.Release";$Image)
];
$Result)

Create barcode and crop it:

Set Field [ Barcode Generation::Image ; "" ]
Set Variable [ $img ; Value: MBS("Barcode.Generate"; Barcode Generation::Symbology; Barcode Generation::Text) ]
If [ MBS("IsError") = 0 ]
    Set Variable [ $ImageHeight ; Value: MBS("GMImage.GetHeight"; $img) ]
    Set Variable [ $ImageWidth ; Value: MBS("GMImage.GetWidth"; $img) ]
    # calculate the crop rectangle
    Set Variable [ $w ; Value: $ImageWidth ]
    Set Variable [ $h ; Value: $ImageHeight ]
    Set Variable [ $x ; Value: 0 ]
    Set Variable [ $y ; Value: $ImageHeight - 50 ]
    # crop
    Set Variable [ $r ; Value: MBS("GMImage.Crop"; $img; $w & "x" & $h & "+" & $x & "+" & $y) ]
    Set Field [ Barcode Generation::Image ; MBS( "GMImage.WriteToPNGContainer"; $img; "barcode.png") ]
    Set Variable [ $r ; Value: MBS( "GMImage.Destroy"; $img ) ]
End If

Crop to square picture:

Set Variable [ $image ; Value: MBS("GMImage.NewFromContainer"; $imageFile) ]
Set Variable [ $Width ; Value: MBS("GMImage.GetWidth";$Image) ]
Set Variable [ $Height ; Value: MBS("GMImage.GetHeight";$Image) ]
If [ $width ≠ $height ]
Set Variable [ $Size ; Value: Min($width; $height) ]
Set Variable [ $r ; Value: MBS("GMImage.Crop";$Image; $Size & "x" & $Size & "+" & Int ( ($Width-$Size)/2) & "+" & Int ( ($Height-$Size)/2)) ]
Set Variable [ $imageFIle ; Value: MBS("GMImage.WriteToPNGContainer"; $Image) ]
End If
#
Set Variable [ $r ; Value: MBS("GMImage.Release";$Image) ]

See also

Example Databases

Blog Entries

Created 18th August 2014, last changed 30th December 2020


GMImage.CopyChannel - GMImage.CycleColormap

Feedback: Report problem or ask question.




Links
MBS Xojo Plugins

Start Chat