One of the simplest ways to modify images from terminal in Linux is with ImageMagick utilities. To install ImageMagick on debian/ubuntu, run sudo apt-get install imagemagick
.
ImageMagick tool can perform many operations on images. Here we will go over just a few:
Converting image format
One of the simplest things you can do with images is convert the format. Here we will modify a PNG image to a JPG.
|
|
Resizing
There are multiple ways to resize an image with ImageMagick like increase the image size by hight while keeping aspect ratio. One of the simplest ways is to pass a -resize
flag with the new dimension.
|
|
Rotating
To rotate an image by some degree, just pass the value with the -rotate
option.
|
|
Chaining multiple operations
convert
command can accept multiple operations at a time so we could convert image format, resize and rotate an image all in one command.
|
|
Notes:
- If the input file and output files are named the same, then the original file will be overwritten.
- Since we are working with Linux Terminal,
convert
utility can be used recursively on multiple images by going over images using afor
loop.