I’ve already written about ImageMagick in previous notes (e.g. this
one about image resizing). Yesterday I
used convert
to color and rotate
an image and I would like to show how simple it is here. Note that in order to
show what the different command lines yield, I’ve used the PNG file of the
GitHub Octocat (Octocat.png
) available at https://github.com/logos.

To fill Octocat.png
with black, I’ve used the following command line:
|
|
that created Octocat_black.png

the option -fill
accept all color format listed at https://imagemagick.org/script/color.php. For instance I can use #80cbc3
|
|

Note that the %
after 100 is optional. Using a value lower that 100, say 80 o4 40, tints the image with the desired color!
|
|

|
|

Using a value above 100 yield funky results (I did not check whether this is expected)
|
|

It is also pretty straight forward to add a background to the image as explain in this article available at codeyarns.com
|
|

Note that -flatten
is required otherwise it would not add the background layer required.
As explained in the documentation flatten
does the following :
Create a canvas the size of the first images virtual canvas using the current -background color, and -compose each image in turn onto that canvas. Images falling outside that canvas is clipped. Final image will have a zero virtual canvas offset.
Rotating an image is even more simple, is only requires to use the roate
option (see the list of options available for convert
at https://imagemagick.org/script/convert.php)
|
|

Finally, all the step above can be combined is one line to do multiple transformations at once !
|
|

To conclude this note, I’d like to mention that I’m currently using ImageMagick 6
|
|
even thought there have been a major release in 2015, ImageMagick 7 (not available in Debian Sid yet), which I still need to try. That said, ImageMagick 6 should be supported and enhanced at least until 2025 and the command line above should work for ImageMagick 7 just as fine.