I've been an ImageMagick user for a long time. As the web site says:
ImageMagick® is a software suite to create, edit, compose, or convert bitmap images. It can read and write images in a variety of formats (over 100) including DPX, EXR, GIF, JPEG, JPEG-2000, PDF, PNG, Postscript, SVG, and TIFF. Use ImageMagick to resize, flip, mirror, rotate, distort, shear and transform images, adjust image colors, apply various special effects, or draw text, lines, polygons, ellipses and Bézier curves.
This is the basic comand I use to resize a single image:
convert source.png -resize x720 output.png
It takes the source.png
, resizes it's height to 720px
, keeps the
proportions, and saves it as output.png
. You could also specify the desired
width instead of height with 1280x
, or specific dimensions with 1280x720
.
If I wanted to do the same for all images in the current directory, I would make use of the find command:
mkdir resized
find *.png -exec convert {} -resize x720 resized/{} \;
This will convert all png
files in the current directory and output them to
the resized/
subdirectory. The \;
part is a delimiter which tells find
where is the end of the command to execute.
To add the watermark to the bottom-right corner of an image you can use:
composite -gravity southeast -geometry +10+10 watermark.png source.png output.png
To resize the image and automatically add the watermark:
convert source.png -resize x720 miff:- | composite -gravity southeast -geometry +10+10 watermark.png miff:- output.png
Here we made use of the miff
, ImageMagick's intermediary file format which
enables image pipelining between multiple commands.
It's a bit more complicated to do pipes with the find command, so I created a
bash
script which does that:
The basic syntax is:
resize.sh <source image> <dimensions> <destination folder>
So to automatically scale the height of all images in current folder to
720px
, keep their proportions, and add watermarks we can use:
mkdir watermarked/
find *.png -exec /path/to/resize.sh {} x720 watermarked/ \;