Convert Images Between Formats via the Command Line in Ubuntu

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

Installing ImageMagick

ImageMagick may already be installed. You can check in the Synaptic Package Manager. Select Administration | Synaptic Package Manager from the System menu.

Accessing the Synaptic Package Manager

In the Quick search edit box on the Synaptic Package Manager window, enter imagemagick. The results of the search start to display as you type your search term. If ImageMagick is already installed, the check box next to the program name will be filled in green, and you can skip to the Converting an Image Using ImageMagick section below.

Searching for ImageMagick

If ImageMagick is not already installed, click on the check box to open a pop-up menu. Select the Mark for Installation option from the menu.

Marking ImageMagick for installation

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

Apply all marked changes

A Summary screen displays listing all the changes that will be made. Click the Apply button.

Summary of the changes to be applied

The installation progress displays.

Applying changes

The Changes applied dialog box displays when the installation is finished. Click the Close button.

Changes applied

Select Quit from the File menu to close the Synaptic Package Manager.

Closing the Synaptic Package Manager

Converting an Image Using ImageMagick

Once ImageMagick is installed, simply use the convert command in a terminal window. For example, the following command will convert a PNG file to a JPEG file.

$ convert sample.png sample.jpg

However, converting an image into a JPEG sacrifices image quality for file size. There is a command switch, –quality, that allows you to specify the quality of the resulting .jpg file. You can set a value between 0 (poorest quality) to 100 (highest quality). Remember that the better the quality (the higher the number), the bigger the file size. Generally, a value between 60 and 80 is good enough for most uses.

The following command converts sample.png into a JPEG image with a quality of 80.

$ convert –quality 80 sample.png sample.jpg

Converting a .png file to a .jpg file

A JPEG file called sample.jpg is created in the same directory as the original .png file. There is a quick way to view the converted image. The default image viewer in Ubuntu is called Eye of Gnome. Using Eye 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 run Eye of Gnome from the command line, simply type eog. So, to view the converted image file type the following command:

$ eog sample.jpg

Command for viewing an image

The viewer opens displaying the specified image.

Viewing an image in Eye of Gnome

To close Eye of Gnome, select Close from the File menu.

Closing Eye of Gnome

If you prefer using the command line to perform tasks, click here to access a web page that provides a set of examples using ImageMagick from the command line.

by Lori Kaufman

More posts from the Linux Tips Category

01GNOME_3_Desktop.jpg

Try Out GNOME 3.4 Without Installing It To Your Hard Drive

Enable Transparent Label Text Background On The Xfce Desktop

Install Komodo Edit Code Editor In Linux

Edit ID3 Tags in Linux With EasyTAG

Popular Posts This Month

event id

Fix Windows 8 App Opens Then Closes

runas command

5 Windows Alternatives to the Linux sudo Command

5 Utilities for Changing DNS Servers in Windows Reviewed

windows defender

Windows Defender vs. Security Essentials vs Safety Scanner

Comments [2]

  1. dexter_greycells says:

    For everyone's reference –

    There is a tool called Phatch (aka Photo Batch Processor) which I stumbled upon while trying to find a way to insert the date & time stamp into all my photos (my Sony digicam stores that info. as EXIF data but is not smart enough to imprint it on the bottom right hand corner of the image). The tool is geeky but extremely powerful. And like most Ubuntu/Linux softwares, it is free. All the Windows options to do that were paid.

  2. dexter_greycells says:

    Also, wrt the above post – that's exactly why they call the terminal 'sexy' – It is simple yet powerful. Only thing is that you need to remember the darn commands [:p]

Leave a Reply