GMImage.SetResolutionUnits
--------------------------

Sets which units are used for image resolution.

| Component | Version | macOS | Windows | Linux | Server | iOS SDK |
|---|---|---|---|---|---|---|
| [GraphicsMagick](component_GraphicsMagick.md) | [2.0](newinversion20.md) | ✅ Yes | ✅ Yes | ✅ Yes | ✅ Yes | ✅ Yes |

MBS( "GMImage.SetResolutionUnits"; ImageRef; ResolutionType ) 

**MBS**( **"GMImage.SetResolutionUnits";** /\* Sets which units are used for image resolution. \*/  
**$ImageRef**; /\* The image reference number.e.g. 1 \*/   
**$ResolutionType**) /\* UndefinedResolution = 0, PixelsPerInchResolution = 1, PixelsPerCentimeterResolution = 2e.g. 1 \*/ 

### 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](GMImageNewFromContainer.md)"; SVG to PNG::InputFile ) \]   
Set Variable \[ $name ; Value: MBS ( "[Files.FileName](FilesFileName.md)"; 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](GMImageScale.md)"; $image ; "99999x" &amp; SVG to PNG::Target Height in Pixel &amp; "&gt;") \]   
 End If  
Else  
 If \[ IsEmpty ( SVG to PNG::Target Height in Pixel ) \]   
 Set Variable \[ $r ; Value: MBS ( "[GMImage.Scale](GMImageScale.md)"; $image ; SVG to PNG::Target Width in Pixel&amp; "&gt;" ) \]   
 Else  
 Set Variable \[ $r ; Value: MBS ( "[GMImage.Scale](GMImageScale.md)"; // function $image ; // pass in picture SVG to PNG::Target Width in Pixel &amp; // width "x" &amp; // by SVG to PNG::Target Height in Pixel &amp; // height "&gt;" // scale only if it will get smaller ) \]   
 End If  
End If  
\# If a resolution is defined, put it in   
If \[ 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](GMImageSetDensity.md)"; $image ; SVG to PNG::Resolution in DPI &amp; "x" &amp; SVG to PNG::Resolution in DPI) \]   
End If  
\# Output to container   
Set Field \[ SVG to PNG::OutputFile ; MBS ( "[GMImage.WriteToPNGContainer](GMImageWriteToPNGContainer.md)"; $image ; $name &amp; ".png") \]   
\# Cleanup   
Set Variable \[ $r ; Value: MBS ("[GMImage.Release](GMImageRelease.md)"; $image ) \]  
Standardize all images to a maximum of 800x800 points @ 144 dpi which is 1600x1600 pixels:

 Set Variable \[$ImageRef ; Value:MBS ("[GMImage.NewFromContainer](GMImageNewFromContainer.md)"; Test::BigImage )\]  
Set Variable \[$Result ; Value:MBS ("[GMImage.Scale](GMImageScale.md)"; $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](GMImageSetDensity.md)"; $ImageRef ; "144x144") // set the DPI value \]  
Set Variable \[$Result ; Value:MBS ("[GMImage.SetQuality](GMImageSetQuality.md)"; $ImageRef ; 90) // save as JPEG with 90% \]  
Set Field \[Test::Result ; MBS ( "[GMImage.WriteToJPEGContainer](GMImageWriteToJPEGContainer.md)"; $ImageRef )\]  
Set Variable \[$Error ; Value:MBS ("[GMImage.Release](GMImageRelease.md)";$ImageRef )\]  
### See also

- [Files.FileName](FilesFileName.md)
- [GMImage.GetResolutionUnits](GMImageGetResolutionUnits.md)
- [GMImage.New](GMImageNew.md)
- [GMImage.NewFromContainer](GMImageNewFromContainer.md)
- [GMImage.Release](GMImageRelease.md)
- [GMImage.Scale](GMImageScale.md)
- [GMImage.SetDensity](GMImageSetDensity.md)
- [GMImage.SetQuality](GMImageSetQuality.md)
- [GMImage.WriteToJPEGContainer](GMImageWriteToJPEGContainer.md)
- [GMImage.WriteToPNGContainer](GMImageWriteToPNGContainer.md)

### Example Databases

- [GraphicsMagick/Apply Mask](https://www.mbsplugins.eu/MBS-FileMaker-Plugin-Examples/GraphicsMagick/Apply%20Mask.shtml#1ScriptAnchor_)
- [GraphicsMagick/SVG to PNG](https://www.mbsplugins.eu/MBS-FileMaker-Plugin-Examples/GraphicsMagick/SVG%20to%20PNG.shtml#1ScriptAnchor_)

This function checks for a license.

Created 18th August 2014 , last changed 5th September 2025

  
[GMImage.SetRenderingIntent](GMImageSetRenderingIntent.md) - [GMImage.SetScene](GMImageSetScene.md)

[HTML Version](GMImageSetResolutionUnits.shtml)