1

I'm trying to convert heic to jpg. I use the official library on js. The problem is that I can decode a heic photo from the repository (callback returns an array of data), but I can't decode heic photos taken on the iPhone (In this case, the callback doesn't return anything at all).

Has anyone tried to convert a heic photo, that was made on an iPhone to jpg?

var reader = new HEIFReader('test/1.heic');
var decoder = new HevcDecoder();
var imgData = new ImageProvider(reader, decoder);

reader.requestFileInfo(function(payload) {
  if (payload.success !== true) {
    console.error("Could not read file:", url);
  } else {
    var fileInfo = payload;
    console.log("FileInfo contents:", fileInfo);

    if (fileInfo.rootLevelMetaBoxProperties) {
      var masterContextId = fileInfo.rootLevelMetaBoxProperties.contextId;
      var masterItemIds = [];
      var imageFeaturesMap = fileInfo.rootLevelMetaBoxProperties.imageFeaturesMap;

      for (i in imageFeaturesMap) {
        if (imageFeaturesMap.hasOwnProperty(i) && imageFeaturesMap[i].isMasterImage === true) {
          masterItemIds.push(parseInt(i));
        }
      }
      console.log("Master images in the file:", masterItemIds);

      imgData.requestImageData(masterContextId, masterItemIds, function(data) {
        console.log(data);
      });

    }

  }
});
Dmitriy
  • 111
  • 1
  • 2
  • 5

0 Answers0