Installation and Use of GraphicsMagick

Source: Internet
Author: User

This article focuses on Linux compilation and installation. If you want to install the version of the Windows platform, you can directly download the compiled binary version on the official website.


First download the source code, you can go to the official website to download the image FTP:

This article uses 1.3.16. Download The wget command, decompress it, and then use it. /configure, and then make & make install can complete the installation. Do not delete the source code installation directory, because it will be used to uninstall later. If you want to download it later, you can execute make uninstall to uninstall. If you want to clear the compilation files left by the installation directory, run make clean. If you want to clear the configuration file, run make distclean.



Now you can use gm to process images.

gm convert input.jpg -thumbnail '100x100' \-background gray -gravity center -extent 100x100 output_4.jpg

This command is to first convert input.jpg to X using the thumbnail algorithm, and automatically center the image with a gray background to supplement the entire image. If the resolution of the image is not of the same length and width, a x error cannot be returned. pixel image, so use extent to specify the size of X, use other colors to supplement the deficiencies, and use the above-specified colors to use commands that can also include sample, scale, resize, geometry you can also specify the conversion quality, use the-quality 50 parameter to specify the quality as 50% of the original, but in my personal experience, the converted geometry image quality is good, not so many rough the transition between the local and edge areas is relatively smooth, the comparison is like a bit of polishing through Photoshop, while the sample and thumbnail are like a sharpening process,


Here if the processing jpg program is not supported, said you need to download the corresponding jpg library, on the jpg library can be downloaded here:

Download the libjpg library, decompress it ,. /configure and make & make install. Then, reconfigure and install GraphicsMagick. When the installer checks that a jpg library already exists, it will automatically add jpg file format support during compilation. similarly, if the png format file is not supported, download the corresponding library file, compile and install it, And then reconfigure and install GraphicsMagick.



Another note of this gm tool is that its command parameters are stream processing and the order of parameters is considered. That is to say, the following two commands are different.

gm convert ori1.jpg -geometry 500x500 -gravity center -crop 400x400+0+0 -background white -extent 400x400 test.jpg


gm convert ori1.jpg -gravity center -crop 400x400+0+0 -  -geometry 500x500 background white -extent 400x400 test.jpg

The former is first scaled before cropping, and the latter is first cropped before scaling. Due to the order of parameters, gm is quite flexible in image processing.








Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.