无法将 iPhone heic 照片转换为 jpg

问题描述 投票:0回答:1

我正在尝试将 heic 转换为 jpg。我在 js 上使用官方库。问题是我可以解码存储库中的 heic 照片(回调返回数据数组),但无法解码在 iPhone 上拍摄的 heic 照片(在这种情况下,回调根本不返回任何内容)。

有人尝试过将 iPhone 上制作的 heic 照片转换为 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);
      });

    }

  }
});

javascript image image-processing converters heif
1个回答
-1
投票

我写了这个Python脚本来转换

脚本片段:

from PIL import Image
from pathlib import Path
from pillow_heif import register_heif_opener
register_heif_opener()

files = list(Path(".").glob("*.heic")) + list(Path(".").glob("*.HEIC"))

for f in files:
    image = Image.open(str(f))
    image.convert('RGB').save(str(f.with_suffix('.jpg')))
    if params.delete:
        f.unlink()
© www.soinside.com 2019 - 2024. All rights reserved.