Use Linux Command Line to repair images-scale, edit, and convert formats

Source: Internet
Author: User

ImageMagick is a series of command line tools used to modify and process images. ImageMagick can quickly use the command line to operate images, batch process a large number of images, or integrate them into bash scripts.
ImageMagick can perform a considerable number of operations. This guide will guide you through the syntax and basic operations of ImageMagick and show you how to combine various operations and how to batch process multiple images.

Install

ImageMagick is not installed by default in Ubuntu and many Linux distributions. to install it on Ubuntu, run the following command:

Sudo apt-get install imagemagick

Format of the converted Image

The conversion Command performs an operation on an image and saves it with the name you specified. The most basic thing you can do with it is to convert your image to a variety of other formats. The following command converts a PNG file named "Upload howtogeek.png" from the current directory to a JPEG file.

Convert howtogeek.png howtogeek.jpg

You can also specify the compression level for JPEG images:

Convert howtogeek.png-quality 95 howtogeek.jpg

The number must be between 1 and 100. If not specified, ImageMagick uses the quality level of the original image. Otherwise, ImageMagick takes 92 as its default value.

Zoom Image

The conversion command can also easily adjust the size of an image. The following command instructs ImageMagick to adjust an image to 200 pixels in width and 100 pixels in height.

Convert example.png-resize 200 × 100 example.png

In this command, we use the same file name for the input and output, so that ImageMagick will overwrite the original file.

When using this command, ImageMagick tries its best to maintain the aspect ratio of the image. It will adjust the image to adapt to the 200x100 area, so that the image is not exactly 200x100. If you want to forcibly set the image to the specified size, even if this changes the aspect ratio of the image, you can add an exclamation mark after the size parameter.

Convert example.png-resize 200 × 100! Example.png

You can also specify only the specified width or height. ImageMagick scales the image to maintain the aspect ratio. The following command scales an image to 200 pixels in width:

Convert example.png-resize 200 example.png

The following command scales an image to 100 pixels high:

Convert example.png-resize x100 example.png

Rotating Images

ImageMagick can quickly rotate images. Parameters ":

Convert howtogeek.jpg-rotary 90 howtogeek-rotated.jpg

If you specify the same file name, ImageMagick overwrites the original image with the rotated image.

Application Special Effects

ImageMagick can make many special effects on an image. For example, the following command applies a charcoal effect to an image:

Convert howtogeek.jpg-charcoal 2 howtogeek-charcoal.jpg

This command will give your image an artistic carbon painting effect, and the 2 following the-charcoal option can control the effect intensity.

The following command produces the "implode" effect with a strength of 1:

Convert howtogeek.jpg-implode 1 howtogeek-imploded.jpg

The "internal explosion" effect makes a pair of images look like a black hole in the center.

Combine all operations!

All these commands can be used together. With this command, you can perform operations such as scaling, rotating, adding special effects, and format conversion on an image at the same time:

Convert howtogeek.png-resize 400 × 400-rotate 180-charcoal 4-quality 95 howtogeek.jpg

With ImageMagick, you can do more than that, and there are many commands you can use together!

Batch Processing

With Bash, you can easily batch process multiple image files. For example, the following command will rotate all the PNG files in the current directory and save them with a new file name consisting of the original file name and "-rotated.

For file in *. png; do convert $ file-rotate 90 rotated-$ file; done

You can use this command to do many other things. In addition, you can integrate batch processing commands into Bash scripts to automate the image processing process.

--------------------------------------------------------------------------------

Any article on ImageMagick will omit many things-because it has too many commands and options. If you are interested in other functions of ImageMagick, refer to the official ImageMagick documentation to learn more about ImageMagick.

For details about ImageMagick, click here
ImageMagick: click here

Use ImageMagick to draw a three-color schematic diagram

In Linux, PHP supports ImageMagick and MagicWandForPHP.

Image Magic with ImageMagick in Linux

Installation of ImageMagick and MagicWand For PHP in Linux

Install ImageMagick and JMagick in Linux

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: info-contact@alibabacloud.com 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.