Flip image using command line

Its convenient to flip an image vertically or horizontally from Terminal. In general, modifying an image in any way including cropping, flipping, rotating, etc. is a lossy process if the image compression algorithm used is lossy such as JPEG. Lossless compression formats such as PNG will remain lossless with this operation.

Here are examples using ImageMagick or IrfanView. Assume the input image is named “in.png” and the modified image is written to “out.png”.

ImageMagick

ImageMagick is available on most operating systems via their package managers.

  • Windows: winget install ImageMagick.ImageMagick WinGet auto adds “magick” to PATH after restarting Terminal
  • macOS: brew install imagemagick
  • Linux: apt install imagemagick

The order of the options is very important in ImageMagick.

Vertical flip the image by:

magick in.png -flip out.png

Horizontal flip the image by:

magick in.png -flop out.png

IrfanView

IrfanView has been popular for decades on Windows and WINE as a no-cost (not open source) image viewing and simple modification program that handles many formats. IrfanView can also be used from the command line. Install IrfanView directly, not via the Microsoft App Store:

winget install IrfanSkiljan.IrfanView

The order of the commands is important. These commands do not open the IrfanView GUI–they are “headless” operations. If there are spaces in the file paths, they must be enclosed in quotes like "c:/data pics/in.png"

Vertical flip the image by:

& $Env:ProgramFiles\IrfanView\i_view64 in.png /vflip /convert=out.png

Horizontal flip the image by:

& $Env:ProgramFiles\IrfanView\i_view64 in.png /hflip /convert=out.png