简体   繁体   English

有没有办法将 HEIC 图像转换为 JPG 以在 Mac 上保留时间戳?

[英]Is there a way to convert HEIC images to JPG that keep timestamps on a mac?

I have a folder with a large number of.heic-files transferred from my iPhone that I need to have in JPG for compatibility reasons of another software that can't read HEIC.我有一个文件夹,其中包含从我的 iPhone 传输的大量 .heic 文件,出于与无法读取 HEIC 的其他软件的兼容性原因,我需要以 JPG 格式保存这些文件。 I've tried various methods and they all create new files that have their own timestamps that do not respect the original photos creation and modification times.我尝试了各种方法,它们都创建了新文件,这些文件有自己的时间戳,不尊重原始照片的创建和修改时间。

I would use the heif-convert cli utility found in libheif to do the converting, but any other implementation would do.我会使用 libheif 中的 heif-convert cli 实用程序来进行转换,但任何其他实现都可以。 Then, given the fact that all files case-sensitively end in exactly .heic , I would loop over the files in that folder (ie open the terminal and cd to the folder that contains the images to be converted).然后,考虑到所有文件都区分大小写地以.heic ,我将遍历该文件夹中的文件(即打开终端并 cd 到包含要转换的图像的文件夹)。 The loop would, for each file convert the heic into a jpg and after the conversion, read the btime from the original file and set that as the creation and modification date using for example SetTime.对于每个文件,循环会将 heic 转换为 jpg,并在转换后从原始文件中读取 btime,并使用例如 SetTime 将其设置为创建和修改日期。 You could also use touch instead of SetTime but that command takes it's input in another format.您也可以使用 touch 而不是 SetTime,但该命令采用另一种格式输入。

Here is a small snippet that I used to solve it.这是我用来解决它的一个小片段。

for file in *.heic; do 
  echo "Converting $file to ${file%%.heic}.jpg"
  heif-convert "$file" ${file%%.heic}.jpg

  echo "reading original creation date"
  date=$(stat -f "%SB" -t "%m/%d/%y %H:%M:%S" "$file")

  echo "writing original creation date as modification and creation date"
  SetFile -md "$date" ${file%%.heic}.jpg
done

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM