Components | All | New | MacOS | Windows | Linux | iOS | ||||
Examples | Mac & Win | Server | Client | Guides | Statistic | FMM | Blog | Deprecated | Old |
GMImage.SetResolutionUnits
Sets which units are used for image resolution.
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 |
ResolutionType | UndefinedResolution = 0, PixelsPerInchResolution = 1, PixelsPerCentimeterResolution = 2 | 1 |
Result
Returns "OK" on success.
Description
Sets which units are used for image resolution.Examples
Convert and Scale:
# Load image from container
Set Variable [ $image ; Value: MBS( "GMImage.NewFromContainer"; SVG to PNG::InputFile ) ]
Set Variable [ $name ; Value: MBS( "Files.FileName"; LiesAlsText(SVG to PNG::InputFile) ) ]
# Scale if parameters are filled in fields
If [ IsEmpty ( SVG to PNG::Target Width in Pixel ) ]
If [ IsEmpty ( SVG to PNG::Target Height in Pixel ) ]
# both empty, do nothing
Else
Set Variable [ $r ; Value: MBS( "GMImage.Scale"; $image; "99999x" & SVG to PNG::Target Height in Pixel & ">") ]
End If
Else
If [ IsEmpty ( SVG to PNG::Target Height in Pixel ) ]
Set Variable [ $r ; Value: MBS( "GMImage.Scale"; $image; SVG to PNG::Target Width in Pixel& ">" ) ]
Else
Set Variable [ $r ; Value: MBS( "GMImage.Scale"; // function $image; // pass in picture SVG to PNG::Target Width in Pixel & // width "x" & // by SVG to PNG::Target Height in Pixel & // height ">" // scale only if it will get smaller ) ]
End If
End If
# If a resolution is defined, put it in
Wenn [ NOT IsEmpty ( SVG to PNG::Resolution in DPI ) ]
Set Variable [ $r ; Value: MBS( "GMImage.SetResolutionUnits"; $image; 1 /* pixel per inch */ ) ]
Set Variable [ $r ; Value: MBS( "GMImage.SetDensity"; $image; SVG to PNG::Resolution in DPI & "x" & SVG to PNG::Resolution in DPI) ]
End If
# Output to container
Set Field [ SVG to PNG::OutputFile ; MBS( "GMImage.WriteToPNGContainer"; $image; $name & ".png") ]
# Cleanup
Set Variable [ $r ; Value: MBS("GMImage.Release"; $image) ]
Standardize all images to a maximum of 800x800 points @ 144 dpi which is 1600x1600 pixels:
Set Variable [$ImageRef; Value:MBS("GMImage.NewFromContainer"; Test::BigImage)]
Set Variable [$Result; Value:MBS("GMImage.Scale"; $ImageRef; "1600x1600") // maximum size in pixels ]
Set Variable [$Result; Value:MBS("GMImage.SetResolutionUnits"; $ImageRef; 1) // resolution is in DPI ]
Set Variable [$Result; Value:MBS("GMImage.SetDensity"; $ImageRef; "144x144") // set the DPI value ]
Set Variable [$Result; Value:MBS("GMImage.SetQuality"; $ImageRef; 90) // save as JPEG with 90% ]
Set Field [Test::Result; MBS( "GMImage.WriteToJPEGContainer"; $ImageRef )]
Set Variable [$Error; Value:MBS("GMImage.Release";$ImageRef)]
See also
- Files.FileName
- GMImage.GetResolutionUnits
- GMImage.New
- GMImage.NewFromContainer
- GMImage.Release
- GMImage.Scale
- GMImage.SetDensity
- GMImage.SetQuality
- GMImage.WriteToJPEGContainer
- GMImage.WriteToPNGContainer
Example Databases
This function checks for a license.
Created 18th August 2014, last changed 17th February 2024