Recently a client contacted us for a problem they have. A solution hosted via FileMaker Server with Web Direct shows a layout with a container. Users can click on a button to upload an image, which uses Insert from Device script step. But if the user has an iPhone, the uploaded image may be an HEIF one. The High Efficiency Image File Format is great to preserve images in high quality, but other tools may not be able to read it. And we run into the problem, that the container is marked to be of type JPEG, which confuses other scripts (see Container.GetTypes function).
Here is a script to look on the inserted image and convert it to PNG with our Container.ReadImage function:
# let user take a picture Insert from Device [ Contacts::Photo Container ; Type: Camera ; Camera: Back; Resolution: Full ] # # check filename Set Variable [ $name ; Value: GetAsText(Contacts::Photo Container) ] Set Variable [ $extension ; Value: Right ( $name ; 5 ) ] If [ $extension = ".heif" or $extension = ".heic" ] # we got a HEIF image # # get new file name Set Variable [ $name ; Value: Substitute($name; ".heif"; ".png") ] Set Variable [ $name ; Value: Substitute($name; ".heic"; ".png") ] # # now convert to PNG Set Variable [ $image ; Value: MBS( "Container.ReadImage"; Contacts::Photo Container; "PNG"; $name ) ] If [ MBS("IsError") = 0 ] # save on success to container Set Field [ Contacts::Photo Container ; $name ] Else Show Custom Dialog [ "Read Image Failed?" ; $image ] End If End If
As you see we also rename the name for the container, so it matches the content. You can decide if you prefer JPEG (smaller, no alpha channel), PNG (higher quality and alpha channel possible) or another type.
This script can be used on FileMaker Server on macOS where our plugin can use the built-in system functions. Otherwise you can run it in FileMaker Pro or in your iOS app based on the FileMaker iOS SDK.