ImageMagick is an application that allows us to manipulate images through the command line and that is used for practically all formats. With it, it is also possible to automate the actions on the images contained in a folder (conversion, resizing, etc ...)
Let's see a list of useful ImageMagick commands:
Get information from an image.
identify -ping image.png
Get even more information.
identify -verbose image.png
Know the list of colors used in an image.
identify -list color image.png
Convert a PNG image to JPG
convert image.png image.jpg
Convert a PNG image to JPG indicating the conversion quality.
convert -quality 96 image.png image.jpg
Convert all PNG images to JPG contained in a folder
mogrify -format png *.jpg
Convert all images (* .jpg, * .png) to PDF
convert images*.* archivo.pdf
Resize an image
convert -resize 48×48 image.png image-mini.png
Resize all images in a folder
mogrify -resize 48×48 *.png
Resize an image by specifying the width
convert -resize 620x image.png image-620.png
Resize an image by specifying its height
convert -resize x100 image.png image-100.png
Create a Favicon
convert -colors 256 -resize 16×16 image.jpg favicon.ico
Convert a color image to black and white
convert -type image.jpg image-noir-blanc.jpg
Add a 1 pixel transparent border around an image
convert -bordercolor Transparent -border 1×1 image.png image-borde.png
Add a 10 pixel black border around an image
convert -bordercolor #000000 -border 10×10 image.png image-borde.png
Create a negative of an image
convert -negate image.png image-negate.png
Rotate an image vertically
convert -flip image.png image-inversee.png
Rotate an image from left to right
convert -flop image.png image-inversee.png
Use the ImageMagick GUI
display image.png
are you using mogrify ?? look at the example in the post.
Cheers! Paul.
Did you copy and paste?
It puts a letter 'x' instead of the sign for '×' that the text editor puts on the page.
regards
Ruben
Hello
I've been testing it and it's fine, but the command to create a favicon doesn't work for me, this is the error it gives me:
convert: invalid argument for option `-resize ': 16 × 16 @ error / convert.c / ConvertImageCommand / 2343.
regards
what is a terminal
Very good selection of commands and clarity in their syntax. Previously I had a lot of trouble trying to use convert to resize a batch of images and now that I use mogrify for the same purpose everything worked out fine. Thank you very much Pablo.
A small contribution to this brilliant post!
To convert to B&W:
convert -monochrome image.png image-bw.png
regards
Thanks for the contribution!
Hug! Paul
Hello, I have seen this information on many websites!
Question: How can I scale to another directory?
Example: convert -scale 50% -quality 80% * .jpg> scaling /
The example does not work, how should it be from a folder x to a subfolder x / scaled?
Beforehand thank you very much!
I made a script for it and the modified ones are saved in another folder.
I place the script inside the folder where I have all the images that I want to modify, and I execute it from the console (the file must have execution permission). The code that I am going to put next, you paste it in a file and give it the name you want (I put .sh at the end to know that it is a script just by reading the name of the file).
I copy and paste the code in case it helps you:
#! / Bin / bash
### Change the size of an image indicating the width and quality
# convert -quality 86 -resize 620x image.png image-620.png
### Change the size of an image indicating the height and quality
# convert -quality 86 -resize x100 image.png image-100.png
+ https://blog.desdelinux.net/como-manipular-imagenes-desde-el-terminal/
#
# =============================================== ==============
DIRECTORY =
pwd
cd $ DIRECTORY
resized_directory = »resized_img»
$ (mkdir "$ resized_directory" 2> / dev / null)
TEMP = »img_list» # internal temporary file
#
#list of directory images in a temporary file
ls * .png 2> / dev / null >> $ resized_directory / $ TEMP; ls * .PNG 2> / dev / null >> $ resized_directory / $ TEMP;
ls * .jpg 2> / dev / null >> $ resized_directory / $ TEMP; ls * .JPG 2> / dev / null >> $ resized_directory / $ TEMP;
ls * .jpeg 2> / dev / null >> $ resized_directory / $ TEMP; ls * .JPEG 2> / dev / null >> $ resized_directory / $ TEMP;
ls * .gif 2> / dev / null >> $ resized_directory / $ TEMP; ls * .GIF 2> / dev / null >> $ resized_directory / $ TEMP
#
#changing images within the directory
echo -n "Processing, please wait"
while read image
do
echo -n "."
convert -quality 90 -resize 1000x $ image $ resized_directory / $ image
done <$ resized_directory / $ TEMP
threw out ""
#
# delete the temporary file
rm $ resized_directory / $ TEMP
echo "completed successfully"
very good thank you