# Convert HEIF images if needed

**URL:** <https://the.fmsoup.org/t/convert-heif-images-if-needed/2236>\
**Category:** MBS Plugins\
**Tags:** scripting, webdirect, ios\
**Created:** [June 21, 2021, 7:36am UTC](https://the.fmsoup.org/t/convert-heif-images-if-needed/2236 "2021-06-21T07:36:15Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![MonkeybreadSoftware](https://yyz2.discourse-cdn.com/flex030/user_avatar/the.fmsoup.org/monkeybreadsoftware/32/361_2.png) [@MonkeybreadSoftware](https://the.fmsoup.org/u/MonkeybreadSoftware)\
**Post date:** [June 21, 2021, 7:36am UTC](https://the.fmsoup.org/t/convert-heif-images-if-needed/2236/1 "2021-06-21T07:36:15Z")

</div>

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](https://www.mbsplugins.eu/ContainerGetTypes.shtml) function).

Here is a script to look on the inserted image and convert it to PNG with our [Container.ReadImage](http://www.mbsplugins.eu/ContainerReadImage.shtml) function:

```auto
# 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.

---

<div class="post-metadata">

**Author:** ![harvest](https://yyz2.discourse-cdn.com/flex030/user_avatar/the.fmsoup.org/harvest/32/231_2.png) [@harvest](https://the.fmsoup.org/u/harvest)\
**Post date:** [June 21, 2021, 7:44am UTC](https://the.fmsoup.org/t/convert-heif-images-if-needed/2236/2 "2021-06-21T07:44:18Z")

</div>

> [@MonkeybreadSoftware](#):
>
> but other tools may not be able to read it

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

---

<div class="post-metadata">

**Author:** ![MonkeybreadSoftware](https://yyz2.discourse-cdn.com/flex030/user_avatar/the.fmsoup.org/monkeybreadsoftware/32/361_2.png) [@MonkeybreadSoftware](https://the.fmsoup.org/u/MonkeybreadSoftware)\
**Post date:** [June 21, 2021, 7:59am UTC](https://the.fmsoup.org/t/convert-heif-images-if-needed/2236/3 "2021-06-21T07:59:58Z")

</div>

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](https://www.mbsplugins.eu/GMImageScale.shtml) to resize the image.

---

<div class="post-metadata">

**Author:** ![steve\_ssh](https://yyz2.discourse-cdn.com/flex030/user_avatar/the.fmsoup.org/steve_ssh/32/160_2.png) [@steve\_ssh](https://the.fmsoup.org/u/steve_ssh)\
**Post date:** [June 21, 2021, 3:16pm UTC](https://the.fmsoup.org/t/convert-heif-images-if-needed/2236/4 "2021-06-21T15:16:51Z")

</div>

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