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

GMImage.GetWidth

Returns the Image width.

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

Parameters

Parameter Description Example
ImageRef The image reference number. 1

Result

Returns the Image width.

Description

Returns the Image width.

Examples

Show with and height

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

Query size of image into $h and $w:

Set Variable [ $Image ; Value: MBS( "GMImage.NewFromContainer"; ImageView::ImageContainer ) ]
Set Variable [ $w ; Value: MBS( "GMImage.GetWidth"; $Image ) ]
Set Variable [ $h ; Value: MBS( "GMImage.GetHeight"; $Image ) ]
Set Variable [ $r ; Value: MBS( "GMImage.Release"; $Image ) ]

Load image to check size:

If [ not IsEmpty ( Contacts::Photo ) ]
    Set Variable [ $Image ; Value: MBS( "GMImage.NewFromContainer"; Contacts::Photo ) ]
Else If [ not IsEmpty ( Contacts::FilePath ) ]
    Set Variable [ $Image ; Value: MBS( "GMImage.NewFromFile"; Contacts::FilePath ) ]
Else
    Exit Script [ Text Result: ]
End If
If [ MBS("IsError") ]
    Show Custom Dialog [ "Failed to open image file." ; $image ]
Else
    Set Variable [ $width ; Value: MBS( "GMImage.GetWidth"; $Image ) ]
    Set Variable [ $height ; Value: MBS( "GMImage.GetHeight"; $Image ) ]
    Set Variable [ $r ; Value: MBS( "GMImage.Release"; $Image ) ]
    Show Custom Dialog [ "Size" ; $width & " x " & $height ]
End If

Ping image to check size:

Set Variable [ $Image ; Value: MBS( "GMImage.New"; "16x16"; "white" ) ]
Set Variable [ $r ; Value: MBS( "GMImage.SetMagick"; $image; "jpeg") // set some codec to expect ]
#
If [ not IsEmpty ( Contacts::Photo ) ]
    Set Variable [ $r ; Value: MBS( "GMImage.PingContainer"; $image; Contacts::Photo ) ]
Else If [ not IsEmpty ( Contacts::FilePath ) ]
    Set Variable [ $r ; Value: MBS( "GMImage.Ping"; $image; Contacts::FilePath ) ]
Else
    Set Variable [ $r ; Value: MBS( "GMImage.Release"; $Image ) ]
    Exit Script [ Text Result: ]
End If
#
If [ MBS("IsError") ]
    Show Custom Dialog [ "Failed to open image file." ; $image ]
Else
    Set Variable [ $width ; Value: MBS( "GMImage.GetWidth"; $Image ) ]
    Set Variable [ $height ; Value: MBS( "GMImage.GetHeight"; $Image ) ]
    Show Custom Dialog [ "Size" ; $width & " x " & $height ]
End If
Set Variable [ $r ; Value: MBS( "GMImage.Release"; $Image ) ]

See also

Example Databases

Blog Entries

This function checks for a license.

Created 18th August 2014, last changed 16th October 2026


GMImage.GetView - GMImage.GetXMP


MarkDown version: GMImageGetWidth.md