fuselibs icon indicating copy to clipboard operation
fuselibs copied to clipboard

HEIF file support in Image

Open eksperts opened this issue 7 years ago • 6 comments

Made aware of this on community: https://www.macworld.co.uk/feature/iphone/what-is-heic-3660408/

With iOS 11, Apple have started using a relatively new file format for images, which we currently don't support. Consequently, when trying to resize images with the .heic (.heif?) extension, Fuse fails with ImageSource error: ‘BundleFileImageSource-failed-conversion, which is not surprising at all.

We should either add support for that file format, or implement a workaround that converts the image to a supported format on-the-fly. The latter seems very wrong.

eksperts avatar Nov 01 '17 14:11 eksperts

I don't think this has anything to do with resizing, but with displaying the result. The reason for this is the ImageSource-part of the error-message. ImageTools (which does the resizing) does not use ImageSource.

kusma avatar Nov 01 '17 14:11 kusma

Is there a temporary workarround to support this kind of images within our app? Is it possible to convert the .heic img to jpg before showing of some kind.

ruudvanham avatar Nov 02 '17 13:11 ruudvanham

@ruudvanham: There might be. I would expect a round through ImageTools.getBase64FromImage() followed by ImageTools.getImageFromBase64() or something might solve the problem. The reason is that ImageTools seems to always save as JPEG, and it uses UIImage to load the data, which supports HEIF. But I haven't tried this.

kusma avatar Nov 02 '17 14:11 kusma

@kusma Seems to work, thanks!

ruudvanham avatar Nov 03 '17 12:11 ruudvanham

The simplest solution is to rename the resulting file with a JPEG extension instead of the provided HEIC extension.

In ImageHelper.m in the iOS part of FUSE the method saveImage converts PNG images to PNG and everything else to JPEG. This is ok and saves us from the HEIC problem. But the method misses renaming the extension from HEIC to JPEG - it just ends up returning the same path which won't work in Fuse. Here is our code that solves the problem from within JavaScript:


var FuseEnvironment = require('FuseJS/Environment');
var FileSystem = require("FuseJS/FileSystem");

if(!imagePath.toLowerCase().endsWith(".png") &&
     !imagePath.toLowerCase().endsWith(".jpg") && 
     !imagePath.toLowerCase().endsWith(".jpeg") && 
     FuseEnvironment.ios){

    // The image is now converted (in Camera Roll) to JPEG if it is not in JPEG or PNG 
    // Originally on the phone.
    // We'll just make sure the path is correct by renaming it to the correct extension which 
    // should be png.
    var newPath = imagePath.substr(0, image.path.lastIndexOf(".")) + ".jpg";
    FileSystem.moveSync(imagePath, newPath);
}

chrfalch avatar Nov 03 '17 12:11 chrfalch

Indeed, the root cause of the issue is the code not renaming the resulting image. A fix for the ImageHelper.m file can be found here: https://github.com/eksperts/fuselibs-public/commit/41820927ab12c21c41a6039f5216d907e4d957ec

eksperts avatar Dec 03 '18 12:12 eksperts