55

What I want to do is very simple. I've a file.png, which I want to mirror, i.e. the result should be a "reflection" of the original image.

I know big tools like GIMP and InkScape can do that, but I'm hoping for a command-line utility, something like convert (which sadly doesn't seem to have such an option, or at least it's not mentioned in the man page).

Zanna
  • 72,312

3 Answers3

86

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
11

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
EA304GT
  • 210
5

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.