TrFile_CreateThumbnail (function reference)

By May 1, 2017 May 22nd, 2019 Online Help, Troi File Plug-in
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

switchesthese determine the properties of the thumbnail that is returned
filePaththe 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:

-NoDialogdon’t show a progress dialog
-Size=80(default) maximum size of the height or width is 80 pixels
-Size=128maximum size of the height or width is 128 pixels
-Size=256maximum size of the height or width is 256 pixels, more like a preview =)
-BitDepth=8use 8 bits (=256 colors) instead of 16 bits (=65536 colors)
-BitDepth=32use 32 bits instead of 16 bits

You can also add these switches:

-AllowAllThumbnailSizesthis will make it possible to use ANY size for the -Size switch. Use with care
-AntiAliasThumbnailcreates bicubic antialiased thumbnails
-Squarecreate square thumbnails (the extending parts of the wider side of the image are cropped)
-IgnoreAlphaChannelignore the alpha channel (for transparency), treat it as completely opaque when creating the thumbnail
-CreatePNGcreates a PNG thumbnail, with an alpha channel. It has the same transparent areas as the original

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:

$$-2003cantFindHandlerno thumbnail could be created
$$-8994noThumbnailFoundErrthe file has no embedded thumbnail

Other errors may be returned.

Originated in

Troi File Plug-in 2.1

Compatibility

FileMaker Pro 14 to 18

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.
NOTE QuickTime is no longer required for this function.

Currently 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.

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 14 to 18 –> TrFile_CreateThumbnail (filep4284) 2019-0522 16:34:43