This article shows how you can edit multiple images with a single command using ImageMagick.
Convert Single Image
We can use the convert program to edit single image.
For example,
We can convert an image from one format to another:
convert input.png output.jpg
Or, we can resize any image:
convert input.png -resize 50% output.png
Convert Multiple Image
Now, if we want to convert multiple images then, we will use mogrify command.
mogrify command is used for batch processing of images.
1) Convert all .jpg
images of the current folder to .png
format
This command will save the output images in the same folder.
mogrify -format png *.jpg
2) Convert and save the output images in another folder
Create a new directory named new_folder
inside the directory where your images are:
mkdir new_folder
Convert and save the output images in the new_folder:
mogrify -format png -path ./new_folder *.jpg
3) Resize multiple images at once
This will save the output images in the same folder, i.e. the old images will be replaced by the new resized images.
mogrify -resize 50% *.jpg
4) Resize multiple images at once and save the output images in another folder
Create a new directory named new_folder
inside the directory where your images are:
mkdir new_folder
Resize and save the output images in the new_folder:
mogrify -resize 50% -path ./new_folder *.jpg
5) Resize and Convert Multiple Images
Now, we will do multiple operations with the mogrify command.
We will:
– resize all the images (resize 50%)
– convert all the images from one format to another (jpg to png)
– save the output images in another folder (new_folder)
Here’s the command to do so:
mogrify -format png -resize 50% -path ./new_folder *.jpg
Hope this helps. Thanks.