Convert an image file from one format to another using ImageMagick
|Debian (Etch, Lenny, Squeeze)|
|Ubuntu (Lucid, Maverick, Natty, Precise, Trusty)|
To convert an image file from one format to another using ImageMagick
Suppose that the file
input.png contains a PNG-format image. You wish to convert it to a JFIF-format image called
output.jpeg using ImageMagick.
The method described here uses ImageMagick to convert the image. On Debian-based systems, the command-line interface to ImageMagick is provided by the package
apt-get install imagemagick
Conversion is performed using the
convert input.png output.jpeg
- The input format is deduced from the file content if it begins with a recognised signature. Failing that, the format is determined by the filename extension if there is one.
- The output format is chosen to match the filename extension if there is one.
Either or both of these choices can be overridden by specifying the file format explicitly:
convert png:input.png jpeg:output.jpeg
ImageMagick supports a large number of file formats, including BMP, GIF, JPEG, PNM, PNG and TIFF. A full list can be obtained using the
identify -list format
Note that some formats require additional information to be specified such as the number of bits per pixel. Also, some of the less common formats can be read but not written, or written but not read.
You can check the format of an image using the
The first two fields of the output are the filename and the image format:
output.jpeg JPEG 641x481 641x481+0+0 DirectClass 8-bit 45.627kb