GMImage.WriteToFile
-------------------

Write single image frame to a file.

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

MBS( "GMImage.WriteToFile"; ImageRef; Path ) 

**MBS**( **"GMImage.WriteToFile";** /\* Write single image frame to a file. \*/  
**$ImageRef**; /\* The image reference number.e.g. 1 \*/   
**$Path**) /\* A platform specific filepath where to write the image.e.g. "C:\\Test.jpg" \*/ 

### Parameters

| Parameter | Description | Example |
|---|---|---|
| ImageRef | The image reference number. | 1 |
| Path | A platform specific filepath where to write the image. | "C:\\Test.jpg" |

### Result

Returns "OK" on success.

### Description

Write single image frame to a file.  
See also [GMImage.WriteToPNGContainer](GMImageWriteToPNGContainer.md), [GMImage.WriteToBMPContainer](GMImageWriteToBMPContainer.md), [GMImage.WriteToTiffContainer](GMImageWriteToTiffContainer.md), [GMImage.WriteToJPEGContainer](GMImageWriteToJPEGContainer.md) and [GMImage.WriteToGIFContainer](GMImageWriteToGIFContainer.md).  
  
On Windows the file APIs in GraphicsMagick only do ANSI file paths. MacOS and Linux can do full Unicode.  
  
This function requires a native path. Use [Path.FileMakerPathToNativePath](PathFileMakerPathToNativePath.md) to convert a FileMaker path to a native path if required. If you like to have the user choose the path, you can use [FileDialog](component_FileDialog.md) functions.  
For Server be aware that server has limited permissions and may not be able to access all files on a computer.  
### Examples

Save file to Bob's desktop as GIF file on macOS:

 MBS ( "GMImage.WriteToFile"; $BigImageRef ; "/Users/Bob/Desktop/test.gif" )  
Save file to Bob's desktop as JPG file on Windows:

 MBS ( "GMImage.WriteToFile"; $BigImageRef ; "C:\\Data\\logo.jpg" )  
Convert image to 1 bit TIFF:

 # Load from container   
Set Variable \[ $Image ; Value: MBS ("[GMImage.NewFromContainer](GMImageNewFromContainer.md)"; GraphicsMagick::image ); \]  
  
\# make black and white with threshold   
Set Variable \[ $Result ; Value: MBS ("[GMImage.Threshold](GMImageThreshold.md)";$Image ; 127); \]  
  
\# mark as monochrome image   
Set Variable \[ $Result ; Value: MBS ("[GMImage.SetMonochrome](GMImageSetMonochrome.md)";$Image ; 1); \]  
  
\# set type to 1 for black/white   
Set Variable \[ $Result ; Value: MBS ("[GMImage.SetType](GMImageSetType.md)";$Image ; 1); \]  
  
\# set to use TIFF for compression   
Set Variable \[ $Result ; Value: MBS ("[GMImage.SetMagick](GMImageSetMagick.md)";$Image ; "TIFF"); \]  
  
\# set to use CCITT 4 Fax compression   
Set Variable \[ $Result ; Value: MBS ("[GMImage.SetCompressType](GMImageSetCompressType.md)";$Image ; 4); \]  
  
\# and write to a file   
Set Variable \[ $Result ; Value: MBS ("GMImage.WriteToFile"; $Image ; "/tmp/test.tif"); \]  
  
\# cleanup   
Set Variable \[ $Error ; Value: MBS ("[GMImage.Release](GMImageRelease.md)";$Image ) \]  
Loads from file and writes to other file:

 Set Variable \[$img ; Value:MBS ("[GMImage.NewImagesFromFile](GMImageNewImagesFromFile.md)"; "/Users/cs/Desktop/test.jpg")\]  
If \[MBS ("IsError") = 0\]  
 Set Variable \[$r ; Value:MBS ( "GMImage.WriteToFile"; $img ; "/Users/cs/Desktop/test.tif" )\]  
 Set Variable \[$r ; Value:MBS ( "[GMImage.Release](GMImageRelease.md)"; $img )\]  
End If  
Draw something and write to file on desktop:

 # New Image   
Set Variable \[$img ; Value:MBS ("[GMImage.New](GMImageNew.md)"; "300x200"; "RGB 1 1 1")\]  
\# Set colors and line width   
Set Variable \[$r ; Value:MBS ("[GMImage.SetStrokeColor](GMImageSetStrokeColor.md)"; $img ; "RGB 1 0 0")\]  
Set Variable \[$r ; Value:MBS ("[GMImage.SetFillColor](GMImageSetFillColor.md)"; $img ; "RGB 0 0 1")\]  
Set Variable \[$r ; Value:MBS ("[GMImage.SetLineWidth](GMImageSetLineWidth.md)"; $img ; 5)\]  
\# draw a rectangle   
Set Variable \[$r ; Value:MBS ("[GMImage.DrawRectangle](GMImageDrawRectangle.md)"; $img ; 50; 50; 250; 150)\]  
\# save to test.png on desktop:   
Set Variable \[$DesktopPath ; Value:MBS ( "[Folders.UserDesktop](FoldersUserDesktop.md)" )\]  
Set Variable \[$path ; Value:MBS ( "[Path.AddPathComponent](PathAddPathComponent.md)"; $DesktopPath ; "test.png")\]  
Set Variable \[$r ; Value:MBS ("GMImage.WriteToFile"; $img ; $path )\]  
\# cleanup   
Set Variable \[$r ; Value:MBS ("[GMImage.Release](GMImageRelease.md)"; $img )\]  
### See also

- [GMImage.SetProfile](GMImageSetProfile.md)
- [GMImage.SetType](GMImageSetType.md)
- [GMImage.Threshold](GMImageThreshold.md)
- [GMImage.WriteToGIFContainer](GMImageWriteToGIFContainer.md)
- [GMImage.WriteToJPEGContainer](GMImageWriteToJPEGContainer.md)
- [GMImage.WriteToPDFContainer](GMImageWriteToPDFContainer.md)
- [GMImage.WriteToPNGContainer](GMImageWriteToPNGContainer.md)
- [GMImage.WriteToTiffContainer](GMImageWriteToTiffContainer.md)
- [IsError](IsError.md)
- [Path.AddPathComponent](PathAddPathComponent.md)

### 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#18ScriptAnchor_)
- [GraphicsMagick/Export Images](https://www.mbsplugins.eu/MBS-FileMaker-Plugin-Examples/GraphicsMagick/Export%20Images.shtml#1ScriptAnchor_)

### Blog Entries

- [MBS FileMaker Advent calendar - Door 15 - vCard QR](https://www.mbsplugins.de/archive/2024-12-15/MBS_FileMaker_Advent_calendar_/monkeybreadsoftware_blog_filemaker)
- [GraphicsMagick in FileMaker, part 3](https://www.mbsplugins.de/archive/2022-12-03/GraphicsMagick_in_FileMaker_pa/monkeybreadsoftware_blog_filemaker)
- [MBS Filemaker Plugin, version 4.4pr7](https://www.mbsplugins.de/archive/2014-10-27/MBS_Filemaker_Plugin_version_4/monkeybreadsoftware_blog_filemaker)

### FileMaker Magazin

- [Ausgabe 5/2011, Seite 33](https://filemaker-magazin.de/neuigkeit/3506-Appetithappen-FMM_201105-06)

This function checks for a license.

Created 18th August 2014 , last changed 25th February 2026

  
[GMImage.WriteToContainer](GMImageWriteToContainer.md) - [GMImage.WriteToGIFContainer](GMImageWriteToGIFContainer.md)

[HTML Version](GMImageWriteToFile.shtml)