Post

Commands to manipulate images | LinuxGist

This article will provide details on how images can be manipulated in Linux.

Here are several Linux commands that can be used to manipulate images, including cropping and changing formats:

1. ImageMagick

ImageMagick is a powerful suite of tools for image manipulation.

Basic Usage:

  • Install ImageMagick:

    1
    2
    
    sudo apt-get install imagemagick  # For Debian-based systems
    sudo yum install ImageMagick      # For Red Hat-based systems
    
  • Crop an image:

    1
    
    convert input.jpg -crop widthxheight+x+y output.jpg
    

    Example:

    1
    
    convert example.jpg -crop 200x300+50+75 output.jpg
    
  • Change the format of an image:

    1
    
    convert input.jpg output.png
    

2. GIMP

GIMP (GNU Image Manipulation Program) is a free, open-source image editor.

Basic Usage:

While GIMP is primarily a graphical tool, you can use it from the command line using the GIMP CLI:

  • Install GIMP:

    1
    2
    
    sudo apt-get install gimp  # For Debian-based systems
    sudo yum install gimp      # For Red Hat-based systems
    
  • Open an image in GIMP:

    1
    
    gimp input.jpg
    

3. GraphicsMagick

GraphicsMagick is a free, open-source software suite to create, edit, and compose bitmap images.

Basic Usage:

  • Install GraphicsMagick:

    1
    2
    
    sudo apt-get install graphicsmagick  # For Debian-based systems
    sudo yum install GraphicsMagick      # For Red Hat-based systems
    
  • Crop an image:

    1
    
    gm convert input.jpg -crop widthxheight+x+y output.jpg
    

    Example:

    1
    
    gm convert example.jpg -crop 200x300+50+75 output.jpg
    
  • Change the format of an image:

    1
    
    gm convert input.jpg output.png
    

4. sips

sips is a command-line tool for manipulating images, available on macOS.

Basic Usage:

  • Install sips (macOS):

    1
    
    xcode-select --install
    
  • Crop an image:

    1
    
    sips -z width height input.jpg --out output.jpg
    

    Example:

    1
    
    sips -z 200 300 example.jpg --out output.jpg
    
  • Change the format of an image:

    1
    
    sips -s format png input.jpg --out output.png
    

5. ffmpeg

ffmpeg can also be used to handle images, especially for batch processing.

Basic Usage:

  • Install ffmpeg:

    1
    2
    
    sudo apt-get install ffmpeg  # For Debian-based systems
    sudo yum install ffmpeg      # For Red Hat-based systems
    
  • Crop an image (using ffmpeg):

    1
    
    ffmpeg -i input.jpg -vf "crop=width:height:x:y" output.jpg
    

    Example:

    1
    
    ffmpeg -i example.jpg -vf "crop=200:300:50:75" output.jpg
    
  • Change the format of an image (using ffmpeg):

    1
    
    ffmpeg -i input.jpg -c:v libpng output.png
    

These commands provide a variety of ways to manipulate images using command-line tools in Linux. Each tool has its own set of features and capabilities, so you can choose the one that best suits your needs.

This post is licensed under CC BY 4.0 by the author.