Components | All | New | MacOS | Windows | Linux | iOS | ||||
Examples | Mac & Win | Server | Client | Guides | Statistic | FMM | Blog | Deprecated | Old |
GMImage.Crop
Crop image (subregion of original image).
Component | Version | macOS | Windows | Linux | Server | iOS SDK |
GraphicsMagick | 2.0 | ✅ Yes | ✅ Yes | ✅ Yes | ✅ Yes | ✅ Yes |
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.Release"; $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
- GMImage.Flip
- GMImage.Flop
- GMImage.Free
- GMImage.GetWidth
- GMImage.Map
- GMImage.Release
- GMImage.Strip
- GMImage.Trim
- GMImage.WriteToPNGContainer
- GMImage.Zoom
Example Databases
- Barcode/Barcode Generation
- Barcode/Barcodes from Invoices
- Barcode/Swiss QR-Code for invoices/Swiss QR-Code for invoices ISO 20022
- GraphicsMagick/GraphicsMagick Sample
- GraphicsMagick/Image Croping
- WebViewer/MethodDraw SVG Editor/MethodDraw
Blog Entries
- Tips and tricks with MBS
- GraphicsMagick in FileMaker, part 24
- GraphicsMagick in FileMaker, part 7
- MBS Plugin Quiz
This function checks for a license.
Created 18th August 2014, last changed 30th December 2020
