ImageMagick is a tool that allows you to convert and process images from the terminal. This article introduces ImageMagick’s installation method, basic command usage, and useful techniques.
Installation Method
First, install ImageMagick. On Ubuntu, execute the following command:
sudo apt-get install imagemagick
Basic Usage
ImageMagick supports many image formats and allows you to perform various operations from the command line.
General Options
1. Change Extension
To convert an image format, use the convert command.
convert image.jpg image.png
2. Resize
You can change the size of an image. You can specify by percentage or pixels.
- Resize by Percentage
convert -resize 50% image.jpg image.png
- Resize by Pixels
convert -resize 100x200 image.jpg image.png
3. Reduce Quality
You can reduce file size by lowering the image quality.
convert -quality 1 image.jpg _image.jpg
Rotate All .jpg Images in a Folder 90 Degrees and Save as New Files
To rotate all .jpg images in a folder by 90 degrees and save them with new filenames, use loop processing as follows.
for file in *.jpg; do convert $file -rotate 90 after-$file; done
Text Embedding
You can also embed text into images. Specify the position and content of the text.
convert -draw 'text 100,100 "IMAGE"' image.jpg _image.jpg