Marcio Cunha

How to convert HEIC to JPG via terminal on Linux

Learn how to batch convert hundreds of smartphone HEIC photos into JPG format using fast, native Linux terminal tools.

Marcio Cunha•4 min
Also available in:PortuguêsEspañol
Summary
  • The HEIC format optimizes mobile storage, but its incompatibility with older systems demands frequent conversion to JPG.
  • Command-line utilities like ImageMagick efficiently handle batch conversions across various Linux distributions.
  • Adjusting compression levels prevents excessive visual quality loss during bulk image processing tasks.
  • Simple shell scripts automate repetitive tasks, saving hours of manual file organization work.
  • Mastering terminal tools complements technical productivity routines and media manipulation workflows.

Why the HEIC format causes headaches on Linux

When you take photos with a modern smartphone, the operating system usually saves the images with the HEIC extension. This format is great because it compresses the file to the maximum while maintaining surprising image quality without taking up too much disk space. In practice, this means you can store twice as many memories in your pocket, but the problem arises when you try to open these photos on Linux computers or send them to legacy systems that simply do not recognize this proprietary structure.

For anyone who works with media organization or needs to publish content quickly, dealing with files that standard viewers refuse to open creates unnecessary friction. Just as we learned how to convert PNG to WebP via terminal on Linux to optimize web pages, we need to master the reverse workflow and turn mobile pictures into widely compatible files. Fortunately, the open-source ecosystem offers lightweight utilities that solve this incompatibility in seconds without requiring heavy graphic editing software.

Preparing the environment and installing necessary tools

Before running any magic command, we need to make sure your operating system has the correct libraries to decode the HEIC structure. Debian and Ubuntu-based distributions usually require the explicit installation of packages that handle this specific format. In practice, the primary tool we will use is ImageMagick, a robust suite for image manipulation directly from the command line, accompanied by auxiliary decoding libraries.

Open your favorite terminal and run the update and installation commands to prepare the ground on your machine. The installation is fast and ensures that the command interpreter understands the complex metadata embedded in pictures taken by recent mobile devices. For those who already have the habit of administering servers or workstations, managing packages via apt is a routine process that guarantees stability and automatically resolved dependencies.

sudo apt update
sudo apt install imagemagick libheif-examples -y

How to convert a single HEIC photo to JPG

With the tools properly installed, the first practical step is to understand how to process an isolated file. Imagine you transferred just one urgent photo from your phone to your computer's Downloads folder and need to upload it through a web form that rejects anything other than JPG. The heif-convert utility, coming from the example package we installed, does this job in a surgical and straightforward way.

In your terminal, navigate to the folder where the image is saved and run the command indicating the source file and the target file. In practice, the syntax is minimalist and does not require you to understand advanced mathematics or data compression. The program reads the internal structure of the HEIC, extracts the pixels, and reconstructs them into the traditional JPG format, keeping original colors and proportions without hassle.

heif-convert image.heic image.jpg

Converting hundreds of images in batch via terminal

The true power of the command line appears when you need to deal with hundreds or thousands of files at once, such as a complete backup of your phone camera. Doing this manually by opening a graphical interface would be an unacceptable test of patience. To automate this task, we can combine the conversion command with a simple loop in Bash, scanning all files in the current folder.

The script below iterates through each file with the HEIC extension, creates a copy with the same root, and replaces the final extension with JPG. While the script runs, you can monitor the data flow similarly to how to monitor Linux network traffic in real time with iftop, observing processor and hard drive activity. This batch approach turns a task that would take hours into something that consumes only a few seconds of processing time.

for img in *.HEIC; do
  magick "$img" "${img%.HEIC}.jpg"
done

Controlling the quality and size of generated files

A crucial detail when converting images is control over the compression rate and the final weight of the generated file. The JPG format uses lossy compression, which means that if you configure the program to crush the image too much, annoying smudges will appear around lines and texts. On the other hand, maintaining maximum quality can generate gigantic files that take up unnecessary disk space.

ImageMagick allows you to explicitly define the desired quality percentage using the -quality parameter. A value between 85 and 90 generally offers the perfect balance for smartphone camera photos, preserving visual sharpness while drastically reducing file size in bytes. Adjusting this parameter prevents unpleasant surprises when sharing converted images with clients or friends.

magick image.heic -quality 88 optimized_image.jpg

Final considerations on automation and workflow

Mastering command-line tools for everyday routine tasks transforms how we interact with our computers. What used to require heavy commercial software or sketchy websites on the internet is now solved with a few lines of code executed locally, ensuring total privacy for your personal photos. Besides saving time, this practice builds valuable logical reasoning to solve any other technical bottleneck that appears on your Linux workstation.