Resizing Images in FileMaker Pro 12


Sometimes it is the little things in an upgrade that take a while to percolate through to real world applications. FileMaker Pro 12 has its share of amazing marquee features, (Insert from URL, ExecuteSQL etc), but the humble GetThumbnail function didn’t cross my radar screen until recently.

I read an article by DB Services on using the GetThumbnail function in FileMaker to resize images in a container field. DB Services’ approach was to resize the file as it was being imported, employing an auto-enter calculation. The obvious benefit was to keep the database file size down and the image size consistent in the container field.

My client was interested in being able to store large files in their image assets database and have anyone on staff be able to export a smaller version for the web or print without having to fire up Photoshop. I thought I would share my demo with the FileMaker world because it is such a great feature and having a demo file can sometimes speed adoption of a technique.

More details on the GetThumbnail function are here on FileMaker’s Help pages.

Download Demo file here.

Image Resizing database

wpid3430-media_1373515085892.png

1) Downloads the Image container field to your desktop.
2) Resizes by Length or Width
3) Resizes by a percentage amount.

Resize by Dimensions

wpid3431-media_1373515228510.png

The function prevents you from upsizing an image, preventing pixelation. You also don’t need both Width and Height because the function will not distort an image, if you enter a wonky set of dimensions, it just picks the constraining axis and goes with that to resize.

Resize by Percentage

wpid3432-media_1373515248419.png

Enter a whole number to get a percentage, for example ’25’ for 25%.

Image Size, Width and Height calculation fields

media_1373518807703.png

Before I dive into how the Export script works, I wanted to point out three calculation fields in the demo. The fields are for calculating the image height, width and size.

Size is done by measuring the Length of the field and dividing by 1,000 to give a size in kilobytes. GetWidth and GetHeight will give the Width and Height in pixels.

These fields are useful, but if you really want to get the most information about an image file, have a look at Troi’s File plugin, which can pull EXIF and IPTC meta data from the image.

How this works: The Export and Resize Script

wpid-screen_shot_2013-07-10_at_8-58-18_pm.png

The Function that is being employed here is GetThumbnail(field;width;height). According to the Help page on the function, “Returns an image that’s stored in a container field according to specified values for width and height. The thumbnail image always maintains the proportions of the original image.”

Script details

wpid-screen_shot_2013-07-10_at_8-58-23_pm.png

Export Image Resize|Raw
Set Field [ Images::ImageResizeWidth; “” ]
Set Field [ Images::ImageResizeHeight; “” ]

If [ Get(ScriptParameter)=”Resize” ]
Show Custom Dialog [ Title: “Resize Image”; Message: “Enter the size in pixels you want to resize to. You don’t need to enter both values, just a constraining size either Height or Width. FileMaker will NEVER distort your image. You CANNOT MAKE the image LARGER than its current size.¶¶The current size is W: ” & Images::Image Width & ” H: ” & Images::Image Height; Default Button: “OK”, Commit: “Yes”; Button 2: “Cancel”, Commit: “No”; Input #1: Images::ImageResizeWidth, “Width”; Input #2: Images::ImageResizeHeight, “Height” ]

If [ Get(LastMessageChoice)=1 ]
Set Variable [ $DesktopPath; Value:Get(DesktopPath) ]
Set Variable [ $FileName; Value:”Resized-“&Substitute(Get(CurrentTimeStamp); “:”;”-“)&Images::File Name ]
Set Field [ Images::ExportImage; GetThumbnail( Images::Image;
If(IsEmpty(Images::ImageResizeWidth); Images::Image Width; Images::ImageResizeWidth) ; If(IsEmpty(Images::ImageResizeHeight); Images::Image Height; Images::ImageResizeHeight) )]
Export Field Contents [ Images::ExportImage; “$DesktopPath/$FileName” ] End If
End If

If [ Get(ScriptParameter)=”Resize by Percent” ]
Show Custom Dialog [ Title: “Resize Image by Percentage”; Message: “Enter a percentage reduction. Enter the number with no decimal places, for example ’25’ for 25%. ¶¶ FileMaker will NEVER distort your image. You CANNOT MAKE the image LARGER than its current size.¶¶The current size is W: ” & Images::Image Width & ” H: ” & Images::Image Height; Default Button: “OK”, Commit: “Yes”; Button 2: “Cancel”, Commit: “No”; Input #1: Images::ImageResizeWidth, “Percentage” ]

If [ Get(LastMessageChoice)=1 ]
Set Field [ Images::ImageResizeWidth; Filter(Images::ImageResizeWidth; “1234567890”) ]
Set Variable [ $DesktopPath; Value:Get(DesktopPath) ]
Set Variable [ $FileName; Value:”Resized-“&Substitute(Get(CurrentTimeStamp); “:”;”-“)&”-“&Images:: ImageResizeWidth&”%-“&Images::File Name ]
Set Field [ Images::ExportImage; GetThumbnail( Images::Image;
If(IsEmpty(Images::ImageResizeWidth); Images::Image Width; Images::Image Width*(Images:: ImageResizeWidth/100)) ;
Images::Image Height
)]
Export Field Contents [ Images::ExportImage; “$DesktopPath/$FileName” ] End If
End If

If [ Get(ScriptParameter)=”Export Raw File” ]
Set Variable [ $DesktopPath; Value:Get(DesktopPath) ]
Set Variable [ $FileName; Value:Images::File Name ]
Export Field Contents [ Images::Image; “$DesktopPath/$FileName” ]
End If

Export results

wpid-screen_shot_2013-07-10_at_8-59-07_pm.png

The first image is a straight up export, no resizing involved. The second item is the resized by 50% item

Exported images

wpid3433-media_1373515315788.png

Image resizing using the GetThumbnail function is turning out to be a very useful feature in FileMaker 12. Thanks again to DB Services for pointing it out.

Advertisements

6 Responses to “Resizing Images in FileMaker Pro 12”

  1. This is exactly the info I was looking for. Well written and clearly explained. Thanks.

  2. I see two problems with your example above.

    1) when converting to kilobytes from bytes, you must divide by 1024, not 1000.
    2) when rescaling the image to “25%” you cannot use 0.25 as a multiplier on one side. You’ll need to take the square root of .25, (in this case 0.5) and multiply that times the width or height in pixels.

    • Branmuffin:

      1) True. 1,000 was close enough for me, but if precision is required then 1,024 is the way to go.

      2) in my calc script, I am inverting it…25/100

      Try the demo, I think you will find it works.

Trackbacks/Pingbacks

  1. Bilder in FileMaker 12 stufenlos skalieren ohne FileMaker-Plugin - July 11, 2013

    […] Mit Hilfe weniger FileMaker-Scripte wurde die Größenanpassung des Bildes realisiert, die im englischsprachigen Artikel ausführlich beschrieben werden. Eine kleine Einschränkung besitzt diese Methode; so können […]

  2. Resizing Images in FileMaker Pro 12 | HomeBase Software | Filemaker Info - July 12, 2013

    […] See on hbase.net […]

  3. Resizing Images in FileMaker Pro 12 | HomeBase Software - FileMaker Pro Gurus - July 14, 2013

    […] via Resizing Images in FileMaker Pro 12 | HomeBase Software. […]

%d bloggers like this: