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.5   11.0   11.1   11.2   11.3   11.4   11.5   12.0   12.1   12.2    Statistic    FMM    Blog  

GMImage.Rotate

Rotate image by specified number of degrees.

Component Version macOS Windows Linux Server iOS SDK License
GraphicsMagick 2.0 ✅ Yes ✅ Yes ✅ Yes ✅ Yes ✅ Yes Paid
MBS( "GMImage.Rotate"; ImageRef; degrees )   More

Parameters

Parameter Description Example
ImageRef The image reference number. 1
degrees The angle in degrees. 90

Result

Returns "OK" on success.

Description

Rotate image by specified number of degrees.
Positive angles rotate the image in a clockwise direction while negative angles rotate counter-clockwise.

Examples

Rotates image by 90 degree to right

Let (
[
$Image = MBS("GMImage.NewFromContainer"; GraphicsMagick::image);
$RotateResult = MBS("GMImage.Rotate"; $Image; 90);
$Result = MBS("GMImage.WriteToPNGContainer"; $Image);
$DestroyResult = MBS("GMImage.Release";$Image)
];
$Result)

Custom function to rotate image:

/*
MBS_Image_Rotate (Picture; rotation)

Picture: Container 'MyTable::MyField"
rotation: Grad ° - numeric Value, positiv OR negative

Benjamin Fehr, EfficientBizz GmbH
http://www.efficientbizz.com
*/


Let (
[
$Image = MBS("GMImage.NewFromContainer"; Picture);
$RotateResult = MBS("GMImage.Rotate"; $Image; rotation);
$Result = MBS("GMImage.WriteToPNGContainer"; $Image);
$DestroyResult = MBS("GMImage.Release";$Image)
];

$Result)

Rotate with script and error checking:

# Read image into variable
Set Variable [ $image ; Value: LiveStream::Image ]
If [ IsEmpty ( $image ) ]
    # nothing to do
    Exit Script [ Text Result: ]
End If

# load image
Set Variable [ $ImageRef ; Value: MBS("GMImage.NewFromContainer"; $image) ]
If [ MBS("IsError") ]
    Show Custom Dialog [ "Failed to load image." ; $ImageRef ]
    Exit Script [ Text Result: ]
End If

# rotate it
Set Variable [ $RotationResult ; Value: MBS("GMImage.Rotate"; $ImageRef; 90) ]
If [ MBS("IsError") ]
    Set Variable [ $r ; Value: MBS("GMImage.Release";$ImageRef) ]
    Show Custom Dialog [ "Failed to rotate image." ; $RotationResult ]
    Exit Script [ Text Result: ]
End If

# write back
Set Variable [ $NewImage ; Value: MBS("GMImage.WriteToPNGContainer"; $ImageRef) ]
If [ MBS("IsError") ]
    Set Variable [ $r ; Value: MBS("GMImage.Release";$ImageRef) ]
    Show Custom Dialog [ "Failed to rotate image." ; $NewImage ]
    Exit Script [ Text Result: ]
End If

# if not error, put it back to record
Set Field [ LiveStream::Image ; $NewImage ]
Set Variable [ $r ; Value: MBS("GMImage.Release";$ImageRef) ]

See also

Example Databases

Blog Entries

Created 18th August 2014, last changed 24th February 2022


GMImage.Rollxy - GMImage.Rotating

Feedback: Report problem or ask question.


Start Chat