Q. How do I convert images from a shell prompt? For example convert an image in the JPEG format to PNG or vise versa?

A. You need to use the convert command which is a member of the ImageMagick suite of tools. Use it to convert between image formats as well as
=> Resize an image
=> Blur an image
=> Crop an image
=> Despeckle an image
=> Dither an image
=> Draw on an image
=> Flip an image
=> Join an image
=> Re-sample, and much more.

Task: Convert an image in the JPEG format to PNG

Type the command as follows:
$ convert input.jpg output.png

Task: Resize the image

Resize and convert an image in the JPEG format to PNG
$ convert -resize 50% input.jpg output.png

You can also create a complex effect such as:
$ convert -size 360x85 xc:transparent -font Bookman-DemiItalic -pointsize 72 -draw "text 25,60 'nixCraft'" -channel RGBA -gaussian 0x6 -fill YellowGreen -stroke RosyBrown -draw "text 20,55 'nixCraft'" nixCraft.png


🐧 Get the latest tutorials on Linux, Open Source & DevOps via RSS feed or Weekly email newsletter.

🐧 6 comments so far... add one

CategoryList of Unix and Linux commands
Disk space analyzersncdu pydf
File Managementcat
FirewallAlpine Awall CentOS 8 OpenSUSE RHEL 8 Ubuntu 16.04 Ubuntu 18.04 Ubuntu 20.04
Network UtilitiesNetHogs dig host ip nmap
OpenVPNCentOS 7 CentOS 8 Debian 10 Debian 8/9 Ubuntu 18.04 Ubuntu 20.04
Package Managerapk apt
Processes Managementbg chroot cron disown fg jobs killall kill pidof pstree pwdx time
Searchinggrep whereis which
User Informationgroups id lastcomm last lid/libuser-lid logname members users whoami who w
WireGuard VPNAlpine CentOS 8 Debian 10 Firewall Ubuntu 20.04
5 comments… add one
  • Dhaval Apr 18, 2008 @ 12:12

    This website is the best …website for linux users.

    Thanks to Nixcraft.

  • pear Dec 14, 2009 @ 17:30

    Hi ,

    I have converted *.bmp to *.ps, but the *.ps image appears to be small and displayed at the end of the page. How to delete the empty spaces and make it fit to the page with a full resolution.

    I had a similar problem with ps2pdf but i used ps2pdf -dEPSCrop *.ps , i got good result

    Similarly how to do with bmp to ps conversion? or is there any way to convert bmp to pdf directly with full size fit?

  • Dhavakumar Feb 1, 2010 @ 18:36

    How to convert dot format to jpeg format

  • elwoode Feb 28, 2013 @ 9:47

    how do you convert all the files in the folder from .jpg to .png BUT keep the same names apart from the different exstension.
    I tried
    convert *.jpg *.png
    but of course I get a lot of png files with no names just *-0.png etc

    • Lev Lafayette Nov 18, 2014 @ 5:35

      This response is a year old, but perhaps someone else might find this useful. The core concept is that you’re doing the same command over multiple files i.e., a for loop. It should look something like this.

      for file in *.jpg ; do convert "${file}" "${file/%jpg/png}" ; done

Leave a Reply

Your email address will not be published.

Use HTML <pre>...</pre> for code samples. Still have questions? Post it on our forum