Americas

  • United States
sandra_henrystocker
Unix Dweeb

Converting and manipulating image files on the Linux command line

How-To
Jul 16, 20185 mins
Linux

Using the convert command, you can modify image files without having to open an image editor.

sandra henry stocker
Credit: Sandra Henry-Stocker

Most of us probably know how wonderful a tool Gimp is for editing images, but have you ever thought about manipulating image files on the command line? If not, let me introduce you to the convert command. It easily coverts files from one image format to another and allows you to perform many other image manipulation tasks, as well — and in a lot less time than it would take to make these changes uses desktop tools.

Let’s look at some simple examples of how you can make it work for you.

Converting files by image type

Coverting an image from one format to another is extremely easy with the convert command. Just use a convert command like the one in this example:

$ convert arrow.jpg arrow.png

The arrow.png image should look the same as the original arrow.jpg file, but the file will have the specified file extension and be different in size. The convert command will use the file name you provide (in this case, arrow.png) to determine what type of file you want to end up with and reformat the image accordingly. If you doubt that the proper conversion could possibly happen as quickly and easily as it does, you can always use the od command to examine the beginning of each of your files.

od -bc arrow.jpg | head -6
0000000 377 330 377 340 000 020 112 106 111 106 000 001 001 000 000 001
        377 330 377 340  
sandra_henrystocker
Unix Dweeb

Sandra Henry-Stocker has been administering Unix systems for more than 30 years. She describes herself as "USL" (Unix as a second language) but remembers enough English to write books and buy groceries. She lives in the mountains in Virginia where, when not working with or writing about Unix, she's chasing the bears away from her bird feeders.

The opinions expressed in this blog are those of Sandra Henry-Stocker and do not necessarily represent those of IDG Communications, Inc., its parent, subsidiary or affiliated companies.