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:
10.1
10.2
10.3
10.4
10.5
11.0
11.1
11.2
11.3
11.4
Statistic
FMM
Blog
Resize image by using simple ratio algorithm.
Component | Version | macOS | Windows | Linux | Server | iOS SDK |
GraphicsMagick | 2.0 | ✅ Yes | ✅ Yes | ✅ Yes | ✅ Yes | ✅ Yes |
Parameter | Description | Example |
---|---|---|
ImageRef | The image reference number. | 1 |
Geometry | The rectangle. 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%!" | "300x200" |
Returns "OK" on success.
Qualifier | Description |
% | Interpret width and height as a percentage of the current size. |
! | Resize to width and height exactly, loosing original aspect ratio. |
< | Resize only if the image is smaller than the geometry specification. |
> | Resize only if the image is greater than the geometry specification. |
Scales the image to 50% with calculating ourself
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.Scale";$Image; $Width & "x" & $Height);
$Result = MBS("GMImage.WriteToPNGContainer"; $Image);
$Error = MBS("GMImage.Release";$Image)
];
$Result)
Scales the image to 50% easily
Let ( [
$Image = MBS("GMImage.NewFromContainer"; GraphicsMagick::image);
$ScaleResult = MBS("GMImage.Scale";$Image; "50%");
$Result = MBS("GMImage.WriteToPNGContainer"; $Image);
$Error = MBS("GMImage.Release";$Image)
];
$Result)
Scales the image down to 640 pixel width, if it is bigger
Let ( [
$Image = MBS("GMImage.NewFromContainer"; GraphicsMagick::image);
$ScaleResult = MBS("GMImage.Scale";$Image; "640>");
$Result = MBS("GMImage.WriteToPNGContainer"; $Image);
$Error = MBS("GMImage.Release";$Image)
];
$Result)
Scale as script:
Set Variable [$Image; Value:MBS("GMImage.NewFromContainer"; Image Scaling::InputImage)]
Set Variable [$r; Value:MBS("GMImage.Scale"; $Image; "800x600")]
Set Field [Image Scaling::Result; MBS("GMImage.WriteToPNGContainer"; $Image)]
Set Variable [$r; Value: MBS("GMImage.Release"; $Image)]
Download picture and scale it down:
Set Variable [ $curl ; Value: MBS("CURL.New") ]
Set Variable [ $r ; Value: MBS("CURL.SetOptionURL"; $curl; MIX::URL) ]
Set Variable [ $r ; Value: MBS("CURL.SetOptionFollowLocation"; $curl; 1) ]
Set Variable [ $r ; Value: MBS("CURL.SetOptionMaxRedirs"; $curl; 3) ]
Set Variable [ $result ; Value: MBS("CURL.Perform"; $curl) ]
Set Variable [ $debug ; Value: MBS( "CURL.GetDebugAsText"; $curl) ]
If [ $result = "OK" ]
Set Variable [ $Image ; Value: MBS( "CURL.GetResultAsContainer"; $curl) ]
Set Variable [ $ImageRef ; Value: MBS("GMImage.NewFromContainer"; $image) ]
If [ MBS("IsError") = 0 ]
Set Variable [ $r ; Value: MBS("GMImage.Scale";$ImageRef; "256x256>") ]
Set Variable [ $ScaledImage ; Value: MBS("GMImage.WriteToJPEGContainer"; $ImageRef) ]
If [ MBS("IsError") = 0 ]
Set Field [ MIX::Image ; $ScaledImage ]
End If
Set Variable [ $r ; Value: MBS("GMImage.Release";$ImageRef) ]
End If
End If
Set Variable [ $r ; Value: MBS("CURL.Release"; $curl) ]
Created 18th August 2014, last changed 19th April 2020
GMImage.Sample - GMImage.Scaling
Feedback: Report problem or ask question.