In this tutorial you will learn how to convert images on Linux from one format to another, let's say you have an ".jpeg" image, and want to convert it to ".png" format. To do that we'll need to use the convert command.
The convert Command allows you to do much more than just converting, it also allows you to resize images in terms of the image size and in scale.
How to Convert an Image from JPEG to PNG
The following command will convert the format of the image1 from .jpeg to png.
convert image1.jpeg image1.png
How to Convert an Image on Different Formats
The following command will convert jpeg to 3 different type of image formats, to gif,bmp and tif.
convert image1.jpeg image1.gif convert image1.jpeg image1.bmp convert image1.jpeg image1.tif
How to Resize an Image
To resize an image, you need to call convert and specify width and height you want.Let's say you want to give an width of 800px and height of 900px to the image. To do that, you need run the following command.
convert imageiwanttoresize.png -resize 800x900 resizedimage.png
How to Resize Only the Height of the Image
The command to do this is the same, but in this case you have to specify only the height of image not width. To do that run the following command.
convert imageiwanttoresize.png -resize x900 resizedimage.png
How to Resize Only the Width of the Image
Simply specify only the width, so in this case you can do this by running the following command below.
convert imageiwanttoresize.png -resize 900 resizedimage.png
How to Change the Physical Size of the Image
Changing the quality of the image, means making the image smaller in terms of the physical size of the image.
The following command below will change the quality to 90
convert image1.png -quality 80 image1.png
Changing the quality of the image, it's not the only way to reduce the physical size of the image, by changing the aspect ratio and the file format can reduce the size as well.
More Convert Commands
- -adjoin join images into a single multi-image file
- -affine matrix affine transform matrix
- -antialias remove pixel-aliasing
- -authenticate value decrypt image with this password
- -background color background color
- -bias value add bias when convolving an image
- use black point compensation
- -blue-primary point chromaticity blue primary point
- -bordercolor color border color
- -caption string assign a caption to an image
- -cdl filename color correct with a color decision list
- -channel type apply option to select image channels
- -colors value preferred number of colors in the image
- -colorspace type alternate image colorspace
- -comment string annotate image with comment
- -compose operator set image composite operator
- -compress type type of pixel compression when writing the image
- -decipher filename convert cipher pixels to plain pixels
- -define format:option
- define one or more image format options
- -delay value display the next image after pausing
- -density geometry horizontal and vertical density of the image
- -depth value image depth
- -display server get image or font from this X server
- -dispose method layer disposal method
- -dither method apply error diffusion to image
- -encipher filename convert plain pixels to cipher pixels
- -encoding type text encoding type
- -endian type endianness (MSB or LSB) of the image
- -family name render text with this font family
- -fill color color to use when filling a graphic primitive
- -filter type use this filter when resizing an image
- -flatten flatten a sequence of images
To get the full list of the commands, check the manual by running the following command.
In this tutorial you learned how to manipulate images on Linux by using the convert command.