Skip to content

Instantly share code, notes, and snippets.

@bittercoder
Last active March 28, 2024 18:54
Show Gist options
  • Star 24 You must be signed in to star a gist
  • Fork 4 You must be signed in to fork a gist
  • Save bittercoder/f6601784ebe4f63e9b9e037e3344b960 to your computer and use it in GitHub Desktop.
Save bittercoder/f6601784ebe4f63e9b9e037e3344b960 to your computer and use it in GitHub Desktop.
Convert .heic files to .jpg on linux (coming from an iOS11 device over USB)
# download release from github: https://github.com/monostream/tifig/releases and install at ~/tools/tifig
# then run these commands in the folder (just to keep things simple we normalize the file extension case before proceeding).
for f in *.HEIC; do mv "$f" "`echo $f | sed s/.HEIC/.heic/`"; done
for file in *.heic; do echo "~/tools/tifig -v -p $file ${file/%.heic/.jpg}"; done
@MichaH
Copy link

MichaH commented Aug 31, 2018

@manderso7 That shell line above does not execute tifig but only creates a list of commands you have to execute. You could pipe the lines to a script and execute it.

$> for file in *.heic; do echo "~/tools/tifig -v -p $file ${file/%.heic/.jpg}"; done > do.sh
$> . do.sh

works for me

@ksvirsky
Copy link

Thanks for the script, but it has to be changed a little in case there are files with white spaces.

@Tigermatze
Copy link

To execute the tifig command directly I changed the script.

#!/bin/sh

# download release from github: https://github.com/monostream/tifig/releases and install at ~/tools/tifig
# then run these commands in the folder (just to keep things simple we normalize the file extension case before proceed$

for file in *.heic 
do 
  echo $file | xargs /home/josi/Downloads/tifig-static-0.2.2/tifig -v -p $file ${file%.heic}.jpg 
done

@avibrazil
Copy link

\ls *heic | while read f; do unexif/tifig -i "$f" -o "unexif/${f%.heic}.jpg"; done

@mrmcwake
Copy link

This is awesome, this tool saved my photo library.

Modified it a bit to execute the commands, operate recursively on a specified root directory, and skip any files that have already been converted. https://gist.github.com/mrmcwake/6d22eee12e8261e75743019c9219f4bc

Hooking it to a cron job to automatically convert any uploaded heics.

@LeonAzul
Copy link

LeonAzul commented Mar 1, 2019

@Tigermatze In two lines

# download release from github: https://github.com/monostream/tifig/releases and install at ~/Downloads/tifig-static-0.2.2/tifig

for f in *.HEIC; do mv "$f" "`echo $f | sed s/.HEIC/.heic/`"; done
for file in *.heic; do echo $file | xargs ~/Downloads/tifig-static-0.2.2/tifig -v -p $file ${file%.heic}.jpg; done

@avma
Copy link

avma commented Nov 5, 2020

for image in *.HEIC; do tifig -v -p $image basename \$image .HEIC.JPG; done

@tlh24
Copy link

tlh24 commented Jan 13, 2021

for f in *.HEIC; do convert "$f" "${f%.HEIC}.jpg"; touch "${f%.HEIC}.jpg" -r "$f"; done

Copy file modification times as well.

@buragwitmo
Copy link

how to use this?
im a noob.

@Ali-Raza-Arain
Copy link

The script will convert all HEIC files in the current directory to JPEG files. The first line of the script uses the mv command to rename all of the HEIC files to have a lowercase file extension. This is necessary because the tifig command only supports lowercase file extensions.

The second line of the script uses a for loop to iterate over all of the HEIC files in the current directory. For each file, the script echos the command that will be used to convert the file to JPEG. The command is:

~/tools/tifig -v -p $file ${file/%.heic/.jpg}

The ~/tools/tifig part of the command tells the script to use the tifig command that is installed in the ~/tools directory. The -v flag tells the tifig command to be verbose, so that it will print out more information about the conversion process. The -p flag tells the tifig command to preserve the EXIF metadata in the JPEG file. The $file part of the command tells the tifig command the name of the HEIC file to convert. The ${file/%.heic/.jpg} part of the command tells the tifig command to replace the file extension of the HEIC file with ".jpg".

To run the script, you can save it as a file called convert.sh and then run it from the command line. For example, if you are in the directory where the script is saved, you can run the script by typing the following command:

bash convert.sh

This will convert all of the HEIC files in the current directory to JPEG files.

@Ali-Raza-Arain
Copy link

The script will convert all HEIC files in the current directory to JPEG files. The first line of the script uses the mv command to rename all of the HEIC files to have a lowercase file extension. This is necessary because the tifig command only supports lowercase file extensions.

The second line of the script uses a for loop to iterate over all of the HEIC files in the current directory. For each file, the script echos the command that will be used to convert the file to JPEG. The command is:

~/tools/tifig -v -p $file ${file/%.heic/.jpg}

The ~/tools/tifig part of the command tells the script to use the tifig command that is installed in the ~/tools directory. The -v flag tells the tifig command to be verbose, so that it will print out more information about the conversion process. The -p flag tells the tifig command to preserve the EXIF metadata in the JPEG file. The $file part of the command tells the tifig command the name of the HEIC file to convert. The ${file/%.heic/.jpg} part of the command tells the tifig command to replace the file extension of the HEIC file with ".jpg".

To run the script, you can save it as a file called convert.sh and then run it from the command line. For example, if you are in the directory where the script is saved, you can run the script by typing the following command:

bash convert.sh

This will convert all of the HEIC files in the current directory to JPEG files.

@buragwitmo I believe this will be useful for you.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment