GMImage.Scale
-------------

Resize image by using simple ratio algorithm.

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

MBS( "GMImage.Scale"; ImageRef; Geometry ) 

**MBS**( **"GMImage.Scale";** /\* Resize image by using simple ratio algorithm. \*/  
**$ImageRef**; /\* The image reference number.e.g. 1 \*/   
**$Geometry**) /\* The new size. Geometry is specified as a width and height "100x200".e.g. "300x200" \*/ 

### Parameters

| Parameter | Description | Example |
|---|---|---|
| ImageRef | The image reference number. | 1 |
| Geometry | The new size. Geometry is specified as a width and height "100x200". | "300x200" |

### Result

Returns "OK" on success.

### Description

Resize image by using simple ratio algorithm.  
  
GraphicsMagick has added a number of qualifiers to the standard geometry string for use when resizing images. The form of an extended geometry string is "&lt;width&gt;x&lt;height&gt;{+-}&lt;xoffset&gt;{+-}&lt;yoffset&gt;{%}{!}{&lt;}{&gt;}". Extended geometry strings should only be used when resizing an image. Using an extended geometry string for other applications may cause the API call to fail. The available qualifiers are shown in the following table:  
  
| Qualifier | Description |
|---|---|
| % | Interpret width and height as a percentage of the current size. |
| ! | Resize to width and height exactly, loosing original aspect ratio. |
| &lt; | Resize only if the image is smaller than the geometry specification. |
| &gt; | Resize only if the image is greater than the geometry specification. |

  
See [GMImage.SetDensity](GMImageSetDensity.md) and [GMImage.SetResolutionUnits](GMImageSetResolutionUnits.md) to set the resolution in DPI.  
See also [GMImage.SetFilterType](GMImageSetFilterType.md) to pick algorithm.  
### Examples

Scales the image to 50% with calculating ourself

 Let ( \[   
$Image = MBS ("[GMImage.NewFromContainer](GMImageNewFromContainer.md)"; GraphicsMagick::image );   
$Width = MBS ("[GMImage.GetWidth](GMImageGetWidth.md)";$Image );   
$Height = MBS ("[GMImage.GetHeight](GMImageGetHeight.md)";$Image );   
$Width = $Width /2;  
$Height = $Height /2;  
$ScaleResult = MBS ("GMImage.Scale";$Image ; $Width &amp; "x" &amp; $Height );   
$Result = MBS ("[GMImage.WriteToPNGContainer](GMImageWriteToPNGContainer.md)"; $Image );   
$Error = MBS ("[GMImage.Release](GMImageRelease.md)";$Image )  
\];   
$Result )  
Scales the image to 50% easily

 Let ( \[   
$Image = MBS ("[GMImage.NewFromContainer](GMImageNewFromContainer.md)"; GraphicsMagick::image );   
$ScaleResult = MBS ("GMImage.Scale";$Image ; "50%");   
$Result = MBS ("[GMImage.WriteToPNGContainer](GMImageWriteToPNGContainer.md)"; $Image );   
$Error = MBS ("[GMImage.Release](GMImageRelease.md)";$Image )  
\];   
$Result )  
Scales the image down to 640 pixel width, if it is bigger

 Let ( \[   
$Image = MBS ("[GMImage.NewFromContainer](GMImageNewFromContainer.md)"; GraphicsMagick::image );   
$ScaleResult = MBS ("GMImage.Scale";$Image ; "640&gt;");   
$Result = MBS ("[GMImage.WriteToPNGContainer](GMImageWriteToPNGContainer.md)"; $Image );   
$Error = MBS ("[GMImage.Release](GMImageRelease.md)";$Image )  
\];   
$Result )  
Scale as script:

 Set Variable \[$Image ; Value:MBS ("[GMImage.NewFromContainer](GMImageNewFromContainer.md)"; Image Scaling::InputImage )\]  
Set Variable \[$r ; Value:MBS ("GMImage.Scale"; $Image ; "800x600")\]  
Set Field \[Image Scaling::Result ; MBS ("[GMImage.WriteToPNGContainer](GMImageWriteToPNGContainer.md)"; $Image )\]  
Set Variable \[$r ; Value: MBS ("[GMImage.Release](GMImageRelease.md)"; $Image )\]  
Download picture and scale it down:

 Set Variable \[ $curl ; Value: MBS ("[CURL.New](CURLNew.md)") \]   
Set Variable \[ $r ; Value: MBS ("[CURL.SetOptionURL](CURLSetOptionURL.md)"; $curl ; MIX::URL ) \]   
Set Variable \[ $r ; Value: MBS ("[CURL.SetOptionFollowLocation](CURLSetOptionFollowLocation.md)"; $curl ; 1) \]   
Set Variable \[ $r ; Value: MBS ("[CURL.SetOptionMaxRedirs](CURLSetOptionMaxRedirs.md)"; $curl ; 3) \]   
Set Variable \[ $result ; Value: MBS ("[CURL.Perform](CURLPerform.md)"; $curl ) \]   
Set Variable \[ $debug ; Value: MBS ( "[CURL.GetDebugMessages](CURLGetDebugMessages.md)"; $curl ) \]   
If \[ $result = "OK" \]   
 Set Variable \[ $Image ; Value: MBS ( "[CURL.GetResultAsContainer](CURLGetResultAsContainer.md)"; $curl ) \]   
 Set Variable \[ $ImageRef ; Value: MBS ("[GMImage.NewFromContainer](GMImageNewFromContainer.md)"; $image ) \]   
 If \[ MBS ("IsError") = 0 \]   
 Set Variable \[ $r ; Value: MBS ("GMImage.Scale";$ImageRef ; "256x256&gt;") \]   
 Set Variable \[ $ScaledImage ; Value: MBS ("[GMImage.WriteToJPEGContainer](GMImageWriteToJPEGContainer.md)"; $ImageRef ) \]   
 If \[ MBS ("IsError") = 0 \]   
 Set Field \[ MIX::Image ; $ScaledImage \]   
 End If  
 Set Variable \[ $r ; Value: MBS ("[GMImage.Release](GMImageRelease.md)";$ImageRef ) \]   
 End If  
End If  
Set Variable \[ $r ; Value: MBS ("[CURL.Release](CURLRelease.md)"; $curl ) \]  
Scale with error checking:

 Let ( \[   
Image = MBS ("[GMImage.NewFromContainer](GMImageNewFromContainer.md)"; MyContainer);   
// did loading work?  
Error = MBS ("IsError");  
// don't scale if it failed  
ScaleResult = If(Error; ""; MBS ("GMImage.Scale"; Image; "500&gt;"));   
NewName = "Preview.png" ;  
// pass through old container, if we can't load it.  
NewImage = If(Error; MyContainer; MBS ("[GMImage.WriteToPNGContainer](GMImageWriteToPNGContainer.md)"; Image; NewName));  
  
ReleaseResult = MBS ("[GMImage.Release](GMImageRelease.md)"; Image)  
\];   
NewImage)  
Read image and scale down for preview:

 Set Variable \[ $image ; Value: MBS ( "[GMImage.NewFromContainer](GMImageNewFromContainer.md)"; $input ) \]   
If \[ MBS ("IsError") = 0 \]   
 # limit size  
 Set Variable \[ $scale ; Value: MBS ("GMImage.Scale";$Image ; "1000&gt;") \]   
 # remove metadata  
 Set Variable \[ $r ; Value: MBS ( "[GMImage.SetProfile](GMImageSetProfile.md)"; $image ; "IPTC"; "" ) \]   
 Set Variable \[ $r ; Value: MBS ( "[GMImage.SetProfile](GMImageSetProfile.md)"; $image ; "EXIF"; "" ) \]   
 Set Variable \[ $r ; Value: MBS ( "[GMImage.SetProfile](GMImageSetProfile.md)"; $image ; "XMP"; "" ) \]   
 # save  
 Set Variable \[ $NewImage ; Value: MBS ("[GMImage.WriteToJPEGContainer](GMImageWriteToJPEGContainer.md)"; $Image ) \]   
 If \[ MBS ("IsError") = 0 \]   
 Set Field \[ Get Preview::Preview ; $NewImage \]   
 Set Field \[ Get Preview::Made using ; "GraphicsMagick" \]   
 Set Variable \[ $r ; Value: MBS ("[GMImage.Release](GMImageRelease.md)";$Image ) \]   
 Exit Script \[ Text Result: \]   
 End If  
 Set Variable \[ $r ; Value: MBS ("[GMImage.Release](GMImageRelease.md)";$Image ) \]   
End If  
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"; $ImageRef ; "1600x1600") // maximum size in pixels \]  
Set Variable \[$Result ; Value:MBS ("[GMImage.SetResolutionUnits](GMImageSetResolutionUnits.md)"; $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

- [GMImage.Erase](GMImageErase.md)
- [GMImage.Frame](GMImageFrame.md)
- [GMImage.Sample](GMImageSample.md)
- [GMImage.Scaling](GMImageScaling.md)
- [GMImage.SetProfile](GMImageSetProfile.md)
- [GMImage.SetResolutionUnits](GMImageSetResolutionUnits.md)
- [GMImage.SetSize](GMImageSetSize.md)
- [GMImage.TransformScale](GMImageTransformScale.md)
- [GMImage.WriteToJPEGContainer](GMImageWriteToJPEGContainer.md)
- [GMImage.WriteToPNGContainer](GMImageWriteToPNGContainer.md)

### Release notes

- **Version 14.5**
    - Added a check to [GMImage.Scale](https://www.mbsplugins.eu/GMImageScale.shtml) to return an error if width or height is &gt; 99999.

### Example Databases

- [Barcode/Swiss QR-Code for invoices/Swiss QR-Code for invoices ISO 20022](https://www.mbsplugins.eu/MBS-FileMaker-Plugin-Examples/Barcode/Swiss%20QR-Code%20for%20invoices/Swiss%20QR-Code%20for%20invoices%20ISO%2020022.shtml#11ScriptAnchor_)
- [Containers/Create Container Preview](https://www.mbsplugins.eu/MBS-FileMaker-Plugin-Examples/Containers/Create%20Container%20Preview.shtml#1ScriptAnchor_)
- [GraphicsMagick/Clip Image](https://www.mbsplugins.eu/MBS-FileMaker-Plugin-Examples/GraphicsMagick/Clip%20Image.shtml#1ScriptAnchor_)
- [GraphicsMagick/Create GIF](https://www.mbsplugins.eu/MBS-FileMaker-Plugin-Examples/GraphicsMagick/Create%20GIF.shtml#2ScriptAnchor_)
- [GraphicsMagick/GraphicsMagick Sample](https://www.mbsplugins.eu/MBS-FileMaker-Plugin-Examples/GraphicsMagick/GraphicsMagick%20Sample.shtml#2ScriptAnchor_)
- [GraphicsMagick/Image Scaling](https://www.mbsplugins.eu/MBS-FileMaker-Plugin-Examples/GraphicsMagick/Image%20Scaling.shtml#1ScriptAnchor_)
- [GraphicsMagick/Reduce Image](https://www.mbsplugins.eu/MBS-FileMaker-Plugin-Examples/GraphicsMagick/Reduce%20Image.shtml#1ScriptAnchor_)
- [GraphicsMagick/SVG to PNG](https://www.mbsplugins.eu/MBS-FileMaker-Plugin-Examples/GraphicsMagick/SVG%20to%20PNG.shtml#2ScriptAnchor_)
- [Mac and iOS/Machine Learning/Core ML Photos](https://www.mbsplugins.eu/MBS-FileMaker-Plugin-Examples/Mac%20and%20iOS/Machine%20Learning/Core%20ML%20Photos.shtml#7ScriptAnchor_)

### Blog Entries

- [MBS FileMaker Plugin, version 14.5pr5](https://www.mbsplugins.de/archive/2024-10-28/MBS_FileMaker_Plugin_version_1/monkeybreadsoftware_blog_filemaker)
- [Create thumbnail with GraphicsMagick](https://www.mbsplugins.de/archive/2023-04-15/Create_thumbnail_with_Graphics/monkeybreadsoftware_blog_filemaker)
- [GraphicsMagick in FileMaker, part 5](https://www.mbsplugins.de/archive/2022-12-05/GraphicsMagick_in_FileMaker_pa/monkeybreadsoftware_blog_filemaker)
- [Seven things to add to your FileMaker solution today with MBS Plugin](https://www.mbsplugins.de/archive/2021-03-21/Seven_things_to_add_to_your_Fi/monkeybreadsoftware_blog_filemaker)
- [Circle crop images in FileMaker with MBS Plugin](https://www.mbsplugins.de/archive/2018-01-18/Circle_crop_images_in_FileMake/monkeybreadsoftware_blog_filemaker)
- [QR Codes for Invoices in Switzerland](https://www.mbsplugins.de/archive/2017-12-20/QR_Codes_for_Invoices_in_Switz/monkeybreadsoftware_blog_filemaker)
- [Filemaker Magazine](https://www.mbsplugins.de/archive/2012-01-05/Filemaker_Magazine/monkeybreadsoftware_blog_filemaker)
- [Filemaker Notes](https://www.mbsplugins.de/archive/2011-11-18/Filemaker_Notes/monkeybreadsoftware_blog_filemaker)

### FileMaker Magazin

- [Ausgabe 5/2022, Seite 27](https://filemaker-magazin.de/neuigkeit/4196-Appetithappen-FMM_202205)
- [Ausgabe 6/2020, Seite 38](https://filemaker-magazin.de/neuigkeit/4118-Appetithappen-FMM_202006)
- [Ausgabe 5/2018, Seite 29](https://filemaker-magazin.de/neuigkeit/4011-Appetithappen-FMM_201805)
- [Ausgabe 5/2011, Seite 32 bis 33](https://filemaker-magazin.de/neuigkeit/3506-Appetithappen-FMM_201105-06)

This function checks for a license.

Created 18th August 2014 , last changed 17th February 2024

  
[GMImage.Sample](GMImageSample.md) - [GMImage.Scaling](GMImageScaling.md)

[HTML Version](GMImageScale.shtml)