GraphicsMagick is a tool that allows to edit images from terminal. It claims to be a handy tool for those cases in which you have to do some quick image editing and don't want to open a heavy program such as Photoshop or GIMP.
This tool increases the productivity by not having to navigate through a GUI. It is based in commands instead, so all you have to do is to type a line and you'll have your image edited very quickly.
Features
This tools offers different options for editing your images:
- Resize
- Crop
- Change colors
- Animate
- Create montages
- Compare images
- Mirror
And a cool thing is that you can combine all this options, getting really interesting results.
Installation
Ubuntu
- Release: Xubuntu 17.10 (also tested in Ubuntu 16.04 LTS)
- Kernel: 4.13.9-300.fc27.x86_64
- Architecture: x86_64
$ sudo apt-get install graphicsmagick
Arch
- Release: 2017.11.01
- Kernel: 4.13.9
- Architecture: x86_64
$ sudo pacman -S graphicsmagick
Fedora
- Release: Fedora 27 Workstation
- Kernel: 4.13.9-300.fc27.x86_64
- Architecture: x86_64
$ sudo dnf install GraphicsMagick
Usage
GraphicsMagick has different image editing options. You can list them all by typing in a terminal:
$ gm
In this tutorial I'll show you how to use some of these options. We will use this image for the examples, original size is 600x333px:
Resize
There are several ways to resize an image with GraphicsMagic:
Specify a new width, and the height will scale proportionally: gm convert -resize <newWidth> <inputImage> <outputImage>
$ gm convert -resize 300 example-villa-traful.png example-resize-300.png
You can specify a width and a height, and the program will resize the image to that dimensions without changing the proportions: gm convert -resize <newWidth>x<newHeight> <inputImage> <outputImage>
$ gm convert -resize 150x100 example-villa-traful.png example-resize-150x100.png
Resize by using a percentage: gm convert -resisze <percentage>% <inputImage> <outputImage>
$ gm convert -resize 50% example-villa-traful.png example-resize-50%.png
You can also composite the image on a background color canvas image: gm convert -gravity center -extent <canvasWidth>x<canvasHeight> \-background black <inputImage> <outputImage>
$ gm convert -gravity center -extent 300x300 \-background black example-resize-50%.png example-composite.png
Crop
You can crop an image this way: gm convert -crop <newWidth>x<newHeight> <inputImage> <outputImage>
$ gm convert -crop 300x300 example-villa-traful.png example-crop-300x300.png
As you can see, the image is not centered. You can center it by specifying an offset in the crop dimensions: gm convert -crop <newWidth>x<newHeight>+<offset> \<inputImage> <outputImage>
$ gm convert -crop 300x300+150 \example-villa-traful.png example-crop-centered-300x300.png
You can also combine options, for example:
$ gm convert -crop 300x300 -resize 150 \example-villa-traful.png example-combined-options.png
Try your own combinations!
Mirror
You can mirror images in the horizontal axis: gm convert -flop <inputImage> <outputImage>
Or in the vertical axis: gm convert -flip <inputImage> <outputImage>
For example:
$ gm convert -flip example-villa-traful.png example-flip.png
Montage
You can combine a multiple images and create a montage. For example:
$ gm montage -geometry 600x333 \example-villa-traful.png example-flop.png example-montage.png
Convert to black and white
You can change an image to black and white: gm convert -monochrome <inputImage> <outputImage>
And also convert one to greyscale: gm convert -modulate 100,0 <inputImage> <outputImage>
Example:
$ gm convert -monochrome example-villa-traful.png example-monochrome.png
And thats all for today. After trying these options, read the official documentation and discover new features!
Conclusion
GraphicsMagick is a nice software with lots of features. It gives the user a very simple way to edit its images without using a GUI. Also, there are a lot of combinations possible using the different options of the tool, so if you edit images frequently, I recommend you to download and try it!