10

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).

20

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
  • 1
    sudo apt-get install imagemagick – tonka Jul 7 '18 at 12:15
  • I have read something about changing convert to magick. So if something goes wrong, try magick. – Sigur Jul 7 '18 at 21:10
2

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.

2

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.