Media_ConvertImage ( container ; type { ; depth ; hres ; vres ; targetBytes ; quality ; imageIndex; transcode ; packBits ; interlace } )
Media_ConvertImage converts an image to the specified type, resolution, image depth, and image quality.
Parameter | Description |
---|---|
container | The location of the source image. The container parameter can be:
|
type | The image type to convert the image to (JPEG, TIFF, etc.). |
depth | The bit depth of the converted image. |
hres | The horizontal resolution in pixels/inch. You must specify either both hres and vres or neither. |
vres | The vertical resolution in pixels/inch. You must specify either both hres and vres or neither. |
targetBytes | The size in bytes that the converted image should not exceed. Image quality is reduced as needed so this target is met. (Must be set to “-1” to set the quality parameter that follows.). |
quality | The image quality level.
Some image types do not implement all of these compression values. ConvertImage will default to the next larger allowable quality. When targetBytes is specified, this parameter is ignored. |
imageIndex | The number of the image layer from the source image to use for multi-image formats. (Default is 1.) TIFF and PhotoShop images can contain multiple image layers. MM cannot create multi-layer images. |
transcode | When set to “1”, the conversion is attempted directly from the source image, without first decompressing it. This can save processing time. |
packBits | (TIFF images only) When set to “1”, TIFF images are compressed using PackBits (lossless). When “0”, TIFF images are not compressed. |
interlace | (GIF and PNG images only) When set to “1”, GIF and PNG images will be interlaced (progressive display). |
With the above parameters, use “-1” to specify the default value for that setting. The default is usually the value from the source image.
Long and Short Parameter Options
You can use this function in either its short form where you specify only container and type, or in its long form with all ten of the above parameters. The short form, Media_ConvertImage( container ; type ) will re-use the same settings last used in the longer form.
Output Type Notes
MediaManager can only convert images to the output types listed by the Media_ListImageOutputTypes function (see below).
For output type, you can also pass a pipe separated list for the type parameter. If you do this, only the first element will be used as the output type. This is a convenience for using Media_ListImageOutputTypes in a popup menu.
You must convert MMIM type images to a standard type before they can be exported. (See the discussion of MMIM format and image output types above.)
Converting Without Changing Image Type
If you want to use Media_ConvertImage to change aspects of an image but not alter the image type, set the Type parameter to empty quotes (""). You can, for example, change image resolution while keeping the image a JPEG, TIFF, etc.
Converting Images in Demo Mode
When you convert an image with an unregistered copy of MediaManager, the resulting image will be marked with a white circle. This behavior disappears when you register MediaManager.
Parameters for Specific Image Types
The targetBytes, quality, transcode, packBits, and interlace do not apply to every image output type. They will be ignored when they do not apply to a particular conversion operation.
Returns
The converted image of the specified type.
Examples
To convert an image held in a container field named “Image 1” to JPEG format and place the result into a container field named “Image Converted”:
Set Field [ MyTable::Image Converted;
Media_ConvertImage (
MyTable::Image 1 ;
"JPEG" ) ]
To convert an image using a hardcoded filepath and name to PNG format:
Set Field [ MyTable::Image Converted;
Media_ConvertImage (
".A/image examples/logo.gif" ;
"PNGf" ) ]
To convert an image using a text field that holds the filepath and name to TIFF format:
Set Field [ MyTable::Image Converted;
Media_ConvertImage (
".A/image examples/logo.gif" ;
"TIFF" ) ]
To convert an image to JPEG with a resolution of 72 pixels per inch:
Set Field [ MyTable::Image Converted;
Media_ConvertImage (
MyTable::Image 1 ;
"JPEG" ;# type
"" ;# default depth
72 ; 72 ;# hres, vres
-1 ;# default targetBytes
"" ;# default image index
"" ;# default transcodex
"" ) ]# default interlacing