This example shows how to use the CNSImage_Convert function. It allows you to change the format, resolution, bit-depth, and quality of an image. Note, some parameters only work for certain image types.
Download Example File
Access the Plug-in
When using plug-ins (not just ours), they do not add new script steps, but instead add new functions that are available in the calculation engine.
The “Specify Calculation” window as shown in the image above is found in many different places in FileMaker. The most common places to use the plug-in is within the "Set Field or “Set Variable” script/button steps.
In FileMaker’s “Specify Calculation” window, the plug-in is accessed using the “CNSImage_FunctionName” functions. To find a list of these in FileMaker, click “View” menu in the top right corner of a “Specify Calculation” window, select “External Functions”, and then scroll through the list until you find the plug-in name. There are many functions available that allow you to do a variety of different things. For a complete listing of the functions and help for each one, see the Functions tab of the CNS Image Knowledge Base.
To understand how this example works, open ScriptMaker/Manage Scripts and edit the Convert script.
Set Field[Image::Edited; CNSImage_Convert( Image::Original; Image::Format; Image::Resolution…
The script uses the Set Field script step to set the “Image::Edited” field with the new image that is returned from the plug-in. Select the Set Field and click the “Calculated result:” Specify button in the bottom left corner.
CNSImage_Convert( Image::Original; Image::Format; Image::Resolution; Image::Depth; Image::Quality )
The CNSImage_Convert function allows you to change the Type, Resolution, Depth, and Quality of an image. The function has separate parameters for setting each of these properties and in this example, each value is specified in a field and then the field is passed to the function. To understand what the above code is doing, take a look at the prototype of the function:
CNSImage_Convert ( Image ; Type ; Resolution ; Depth ; Quality )
The first parameter is the source image you want to convert. In the example database, the image is in the “Image::Original” field, so that field is passed to the plug-in as the first parameter. The second parameter is the Type you want to convert to, so the “Image::Format” field is passed as the second parameter. The same is true for the remaining parameters. Note, using fields for these values are not required as you can use hard coded values if you want (or even a combination of both). For example:
CNSImage_Convert ( Image::Original; “PNG” ; “300” )
This example would convert the image in the “Image::Original” field to a PNG with a resolution of 300.
For more information about this function, see the CNSImage_Convert function in the Function Reference.
How to recreate in your solution
After you have gone over the example databases, learned how they work and how the plug-in works, you can integrate the plug-in into your own solutions. There are many ways this can be done, but here are a few of the most common ways.Note, to properly integrate the plug-in into your own solution you need to be proficient at FileMaker scripting and calculations. While our documentation tries to provide some tips, teaching all the ins and outs of FileMaker scripting and calculations is beyond what we do. FileMaker offers many training options to help you further your FileMaker developing skills. If you are looking for a professional developer to integrate the plug-in into your solution, you can search for one on FileMaker's Consultants site.
Import example script
This is the easiest way to go, but can be the most frustrating at the same time. When importing a script, you will have to go back over the imported script with a fine tooth comb. Field references will be different between the example database and your own database, so you will have to touch every script step to make sure all field references are correct. This will mainly deal with the Set Field script step (but check all the script steps to make sure they are correct for your database). Select the Set Field step and check the “Specify target field” button to make sure that field is correct. Then check the “Calculated result” button and make sure any field (and table names) are correct. If you find /* */ at the beginning and end of the calculation, FileMaker has commented out the code because of incorrect field references. You will need to fix all field references, and then remove the /* */ from the beginning and the end.
Re-create example script
Print out or view the example script and re-create it in your own database. Since you will be creating the script as you go, you are less likely to overlook an incorrect field reference as you would with Importing an example script. This method helps you to better understand what your script is doing since you are actually creating the script yourself.
Create script from scratch
If you went over all the example databases, you should have a pretty good idea what a script would look like. Using the function browser to give you more information about the functions, you can create a script to send an email exactly as you need it. Click the “Functions” tab to open the function browser. Remember to build error checking into your scripts. This is very important and will save much frustration later when something stops working and you have no idea why and no errors to go by.
Be sure to check out the Coding Considerations section for some helpful tips on working with the plug-in functions and writing scripts.