How to mirror image files via command line?
From quick reading of this, apparently convert
calls this option -flop
for horizontal mirroring, and -flip
for vertical. All I needed to do was
convert -flop input.png output.png
If you want to overwrite in-place and you have a ton of image files in the same folder, mogrify
from the ImageMagick suite seems to be the easiest way to achieve this:
# mirror in the vertical axis:
mogrify -flip *.jpg
# mirror in the horizontal axis:
mogrify -flop *.jpg
For this particular task convert
is probably the best way to go, but for this kind of thing I often use the netpbm
library, which is installable (as you would expect) with apt install netpbm
. Then
pngtopnm input.png | pnmflip -lr \
| (other transformations if desired) \
| pnmtopng > output.png
For this task it's overkill, but I often find myself writing one-off scripts to transform or analyze PNM files in peculiar ways that wouldn't be available in convert
. This is relatively easy, because PNM is pretty much the simplest imaginable bitmap graphic format.