Single Command Convert You Photos (WebP, RAW, HEIF/HEIC, etc) to JPG / PNG in Linux

Want to convert your photos into common image file formats, e.g., JPEG and PNG? Just a single command can do the job in Linux.

For just a few picture images or photos with same file format, converting them via Linux command may be more effective than an image editor.

And here are the command examples to convert images via ImageMagick and HEIF file format decoder.

1.) Convert Between Image Formats via ImageMagick

ImageMagick is a free and open-source software suite for displaying, creating, converting, and editing raster images.

The powerful tool can read and write over 200 image file formats. Some Linux Distros, e.g., Linux Mint and Manjaro, have it installed out-of-the-box.

Supported file formats include: APNG, ARW, CIP, CRW, DCR/DCX, DNG, EXR, HEIC (v7.0.7+), JNG, JPEG, PDF, PNG, TIFF, and tons more.

a.) Install ImageMagick

Some Linux Distros may not have the tool pre-installed. It is however easy to install via a Linux command.

Firstly search for and open a terminal window from your system app launcher:

Then run command to install ImageMagick for your system:

  • For Ubuntu / Debian based systems run command:
    sudo apt install imagemagick
  • For Fedora, openSUSE, run:
    sudo yum install ImageMagick
  • Arch Linux based system can run command:
    sudo pacman -S imagemagick

b.) Use convert command:

Before converting the photo images, you may first navigate to the folder that stores the files. To do so, either run cd command (e.g., cd ~/Pictures to go to user’s Pictures folder), or open file manager and select ‘Open in Terminal‘ from context menu.

Next convert an image via command (e.g., DNG to JPEG):

convert input_filename.DNG output_filename.JPEG
1. NOTE: Linux commands are case sensitive! Your photos may have lowercase file extension, so the command can be convert input_filename.dng output_filename.jpg

2. And you can change the file extension to whatever that ImageMagick supports. Run identify -list format command to check out.

Specify the compression level while converting (e.g., WebP to PNG with 85 quality):

convert input_filename.webp -quality 85 output_filename.png

The value of -quality can be 1 (lowest) to 100 (best). For JPEG it’s 92 by default, and PNG defaults to 75.

Convert all HEIC photos to JPEG in current folder:

convert *.HEIC -quality 85 *.JPEG
HEIF/HEIC needs ImageMagick 7.0.7+. Some popular Linux Distros still have old versions. Run convert -version to check out your software version. Or use command in step 2.)

c.) other convert command usage

Besides converting between image formats, the command can also resize an image, blur, crop, despeckle, dither, join, re-sample, and much more.

  • For instance, convert a png file to jpg as well resize to 50%:
    convert input_file.png -resize 50% output_file.jpg
  • Resize photo width to 1920 and keep aspect ratio:
    convert input_file.JPEG -resize 1920 output_file.JPEG
  • Resize photo height to 768 and keep aspect ratio:
    convert input_file.jpg -resize x768 output_file.jpg
  • Force photo to 1000×500 without keeping aspect ratio:
    convert input_file.jpg -resize 1000x500! output_file.jpg
  • Crop photo from top-left to 600×400 image:
    convert input_file.jpg -crop 600x400+0+0 output_file.jpg
  • Crop photo from center to 600×400 image:
    convert input_file.jpg -gravity center -crop 600x400+0+0 output_file.jpg
  • Transform photo to black and white:
    convert input_file.JPEG -monochrome output_file.JPEG

And there are 200+ other command options! However, a graphical image editor will be more straightforward.

2.) Convert HEIF/HEIC to JPEG, PNG

Since ImageMagick needs version 7.07+ to get support for Apple iOS HEIF/HEIC photo formats, libheif is here as an alternative.

To install libheif in Ubuntu / Debian based system, open terminal and run command:

sudo apt install libheif-examples

To install libheif in Fedora, run command:

sudo dnf install libheif

Finally, go to the folder that contains your photos, and run command to convert HEIC file:

heif-convert input_file.heic output_file.jpg

The output file formats can be JPEG, PNG, and Y4M. And you can specify quality level via -q option.

Suppose that your photos have file extension in upper-case, use this command to batch convert all the HEIC files into JPEG:

for file in *.HEIC; do heif-convert -q 85 $file ${file/%.HEIC/.JPG}; done
heif-convert command so far doesn't support * wildcard in output file. This is a 'for' loop to repeat heif-conert command for all HEIC files in current directory.


Converting between image formats is quite easy via convert command in Linux via ImageMagick. And it support more than 200 image file formats. Just run convert input_file output_file, and specify output file extension (.png, .jpg, etc) will do the job.

Since HEIF/HEIC need version 7.07+, libheif library is here for those still have an old package version. And it supports for converting the photo formats to JPEG, PNG, Y4M.

Exit mobile version