Convert Images Between Formats via the Command Line in Ubuntu

Using a great free conversion tool

If you need to convert an image from one format to another you can useGIMPto do so, but there is an easier way. You can useImageMagick, which provides a way to convert images using the command line.

Installing ImageMagick

ImageMagickmay already be installed. You can check in theSynaptic Package Manager. SelectAdministration | Synaptic Package Managerfrom theSystemmenu.

In theQuick searchedit box on theSynaptic Package Managerwindow, enterimagemagick. The results of the search start to display as you type your search term. IfImageMagickis already installed, the check box next to the program name will be filled in green, and you can skip to theConverting an Image Using ImageMagicksection below.

IfImageMagickis not already installed, click on the check box to open a pop-up menu. Select theMark for Installationoption from the menu.

A yellow arrow displays over the check box next toimagemagick, indicating it is marked for installation. Click theApplybutton to continue with the installation.

ASummaryscreen displays listing all the changes that will be made. Click theApplybutton.

The installation progress displays.

TheChanges applieddialog box displays when the installation is finished. Click theClosebutton.

SelectQuitfrom theFilemenu to close theSynaptic Package Manager.

Converting an Image Using ImageMagick

OnceImageMagickis installed, simply use the convert command in a terminal window. For example, the following command will convert aPNGfile to aJPEGfile.

However, converting an image into aJPEGsacrifices image quality for file size. There is a command switch,–quality, that allows you to specify the quality of the resulting.jpgfile. You can set a value between0(poorest quality) to100(highest quality). Remember that the better the quality (the higher the number), the bigger the file size. Generally, a value between60and80is good enough for most uses.

The following command converts sample.png into aJPEGimage with a quality of80.

AJPEGfile calledsample.jpgis created in the same directory as the original.pngfile. There is a quick way to view the converted image. The default image viewer in Ubuntu is calledEye of Gnome. UsingEye of Gnome, you can quickly view the following images: ani, bmp, gif, ico, jpeg, pcx, png, pnm, ras, svg, tga, tiff, wbmp, xbm, and xpm.

To runEye of Gnomefrom the command line, simply typeeog. So, to view the converted image file type the following command:

The viewer opens displaying the specified image.

To closeEye of Gnome, selectClosefrom theFilemenu.

If you prefer using the command line to perform tasks, clickhereto access a web page that provides a set of examples usingImageMagickfrom the command line. Enjoy!

Founder of Help Desk Geek and managing editor. He began blogging in 2007 and quit his job in 2010 to blog full-time. He has over 15 years of industry experience in IT and holds several technical certifications.Read Aseem’s Full Bio

Welcome to Help Desk Geek- a blog full of tech tips from trusted tech experts. We have thousands of articles and guides to help you troubleshoot any issue. Our articles have been read over 150 million times since we launched in 2008.

HomeAbout UsEditorial StandardsContact UsTerms of Use

Copyright © 2008-2024 Help Desk Geek.com, LLC All Rights Reserved