Convert HEIF images if needed

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


...and on other platforms there are problems as well...
thank you so much, I had users turn of heic-format on there iOS devices for certain usecases before, will try to implement as soon as possible :slight_smile:

1 Like

I just came back to this topic a few days ago because a client with Web Direct run into it.

Web Direct uploads can be HEIC/HEIF on iOS, so a script on server could post-process those.

On the same way you may use GMImage.Scale to resize the image.

Thanks for this @MonkeybreadSoftware. I have recently had to face this very problem.

1 Like