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

1.7k views Asked by At

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

2

There are 2 answers

0
Paul Chris Jones On

With ImageMagick:

convert * %03d.jpg
6
Stefan Wallin On

I would use the heif-convert cli utility found in libheif to do the converting, but any other implementation would do. Then, given the fact that all files case-sensitively end in exactly .heic, I would loop over the files in that folder (i.e. open the terminal and cd to the folder that contains the images to be converted). 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. You could also use touch instead of SetTime but that command takes it's input in another format.

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