Skip to main content

TrFile_CreateThumbnail (function reference)

Troi File Plug-in > Functions reference > TrFile_CreateThumbnail
Troi File Plug-in for FileMaker Pro

TrFile_CreateThumbnail

Creates a thumbnail (a small image of normally 80×80 pixels) from a graphics file and returns it.

SyntaxFunction badge

TrFile_CreateThumbnail ( switches ; filePath ; {thumbnailName} )

Parameters

switches these determine the properties of the thumbnail that is returned
filePath the path to the file from which to create a thumbnail
thumbnailName (optional) the (internal) name of the created thumbnail

Switches

Switches can be empty or one or more of the following:

-Size=80 (default) maximum size of the height or width is 80 pixels
-Size=xxxx maximum size of the height or width is xxxx pixels
-BitDepth=8 use 8 bits (=256 colors) instead of 16 bits (=65536 colors)
-BitDepth=32 use 32 bits instead of 16 bits

You can also add these switches:

-AntiAliasThumbnail creates bicubic antialiased thumbnails
-Square create square thumbnails (the extending parts of the wider side of the image are cropped)
-IgnoreAlphaChannel ignore the alpha channel (for transparency), treat it as completely opaque when creating the thumbnail
-CreatePNG creates a PNG thumbnail, with an alpha channel. It has the same transparent areas as the original

Obsolete switches:

-AllowAllThumbnailSizes (obsolete) has no longer any effect, was : this will make it possible to use ANY size for the -Size switch.
-NoDialog (obsolete) has no longer any effect, was: don’t show a progress dialog

Returned Result

Data type returned

Container

Result

The returned result is the thumbnail itself. If an error occurs an error code is returned. An error always starts with 2 dollars, followed by the error code. You should always check for errors. Returned error codes can be:

$$-2003 cantFindHandler no thumbnail could be created
$$-8994 noThumbnailFoundErr the file has no embedded thumbnail

Other errors may be returned.

Originated in

Troi File Plug-in 2.1

Compatibility

FileMaker Pro 16 to FileMaker Pro 2023

Considerations

The “-Square” switch will create square thumbnails. In this case the thumbnails will have the extending parts of the wider side of the image cropped (thus showing the middle square of the image). Also note that the image will be scaled proportionally up to a square, if one of the sides of the image is smaller than the requested size. This makes sure the result is always a square with the exact dimensions requested.

The optional thumbnailName is added to the created thumbnail image data and also when the thumbnail is stored in the container. This name is normally not visible, but will be used for example when you perform a Export Field Contents action later.

You can also use FileMaker styled paths, like “imagemac:/MacHD/folder/myImage.jpg”.
An error code $$-2003 is returned when you try to create a thumbnail for a file that has no graphics, for example a text file or a spreadsheet. It is no problem if you don’t know if a file has a thumbnail. Just try to create a thumbnail, if you get the error $$-2003 you know it is not possible.
Starting with v13.0 you can create thumbnails from PDFs, also on Windows (64-bit only).
Starting with v13.0 you can create thumbnails from a container field (or a variable with container data), for example a JPEG or PDF in a container field.
Starting with v13.1 you can specify any size of thumbnail up to 32767 x 32767 pixels. You no longer need to add the “-AllowAllThumbnailSizes” switch.
v14.0 added .heic and .heif support for Windows.
v15.0 added support for Digital Negative (DNG) files and Apple ProRAW files.

NOTE QuickTime is no longer required for this function.
The plug-in can sometimes return error code $$-8994 (noThumbnailFoundErr) instead of the expected $$-2003.

Example

Set Field [ container field ; TrFile_CreateThumbnail ( "-Unused" ; "Mac HD:photo.jpeg" ) ]

This will create a thumbnail and put it in a container field.

Example 2

Say you want to create the thumbnails of filepaths that are stored in a set of records. We assume that in your FileMaker file the following fields are defined:

  gErrorCode		Global, number
  filePath		text, contains the path to a file
  thumbnailField	container

filePath should contain the full path to existing files, for example “Mac HD:Aap.JPG” (Mac). In a script add the following script steps:

Go to Record [ first ]
Loop 
     Set Field [ thumbnailField ; TrFile_CreateThumbnail ( "-Unused" ; filePath ) ]
     Set Field [ gErrorCode ; GetAsText ( thumbnailField ) ]
     Exit Loop If [ Left ( gErrorCode  ; 2 )  = "$$" ) ]
     Go to Record [ next , exit after last ]
End Loop

This will try to create thumbnails for all files for the records of the found set.

Used in example file

Thumbnail.fmp12

Related functionFunction badge

TrFile_GetIcon

Related script stepScript step badge

Create Thumbnail

Related topics

Troi File Plug-in online help (overview)


Online Help Page for Troi File Plug-in for 16 to 2023 –> TrFile_CreateThumbnail (filep4284) 2023-0601 15:11:19