Command-line lore: Convert Images Using ImageMagick
Another series, command-line lore. It will primarily document some quick command-line tricks.
In this particular post, we’ll discuss various quick stuff that can be done through ImageMagick. ImageMagick is used to create, edit, compose or convert digital images. It has both GUI and CLI applications.
On Debian/Ubuntu systems, just do the following to grab the package:
sudo apt install imagemagick
ImageMagick includes a number of command-line utilities, but we mainly require convert
from the suite.
Note - ImageMagick is moving towards v7 which doesn’t have convert
and other utilities available in v6 (legacy), so the following stuff won’t work in v7.
Table of Content
Append images together
- Append images vertically together:
convert image1.png image2.png -append output.png
- Append images horizontally together:
convert image1.png image2.png +append output.png
Rotate image
- Rotate by specifying the angle for rotation, moving towards right:
convert image.png -rotate {90|180|270} output.png
Convert image to different format
- Convert image between image formats:
convert image.jpg output.png
- Convert an image to PDF format:
convert image.jpg output.pdf
Note - ImageMagick started blocking image to PDF conversion due to a security issue. You can read more and how to enable it back on Stack OverFlow.
- Combine multiple images and make a PDF:
convert image1.jpg image2.jpg output.pdf
Crop or resize image
- Scale an image to a defined size:
convert image.jpg -resize 50% output.jpg
- Scale an image to a defined pixel size:
convert image.jpg -resize 32x32 output.jpg