Skip to content

Instantly share code, notes, and snippets.

@Ali-Raza-Arain
Last active August 1, 2023 17:38
Show Gist options
  • Save Ali-Raza-Arain/a0928f1216794346ebd22d751fdb32bd to your computer and use it in GitHub Desktop.
Save Ali-Raza-Arain/a0928f1216794346ebd22d751fdb32bd to your computer and use it in GitHub Desktop.
Conversion from HEIC to JPEG

Convert HEIC to JPEG

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

Prerequisites

  • The libheif-examples command must be installed.

If you are on a Linux system, you can install the libheif-examples command by running the following command:

sudo apt install libheif-examples

If you are on a macOS system, you can install the libheif-examples command by running the following command:

brew install libheif-examples

Instructions

Once you have installed the libheif-examples command, you can run this command by pasting it into the terminal.

for file in *.heic; do heif-convert -q 92 $file ${file/%.heic/.jpg}; done

Here is a breakdown of the command line:

  • for - This keyword starts a for loop.
  • file - This variable is used to iterate over the files in the current directory.
  • in - This keyword is used to specify the range of files that the for loop will iterate over. In this case, the *.heic pattern matches all files that end in .heic.
  • do - This keyword marks the start of the code that will be executed for each file in the loop.
  • heif-convert - This command is used to convert HEIC files to other formats.
  • -q - This option specifies the quality of the output JPEG file.
  • 92 - This value specifies a quality of 92%, which is a good balance between quality and file size.
  • $file - This variable is used to reference the current file in the loop.
  • ${file/%.heic/.jpg} - This part of the line replaces the .heic extension of the current file with .jpg.
  • done - This keyword marks the end of the for loop.

Output

The script will create a new JPEG file for each HEIC file in the current directory. The new JPEG files will have the same name as the original HEIC files, but with the .jpg extension.

I sincerely hope this documentation is useful. Please let me know if you have any other questions.

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