Components All New MacOS Windows Linux iOS
Examples Mac & Win Server Client Guides Statistic FMM Blog Deprecated Old

GMImage.Rotate

Rotate image by specified number of degrees.

Component Version macOS Windows Linux Server iOS SDK
GraphicsMagick 2.0 ✅ Yes ✅ Yes ✅ Yes ✅ Yes ✅ Yes
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

This function checks for a license.

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


GMImage.Rollxy - GMImage.Rotating