ImageMagick convert command Daquan

Source: Internet
Author: User
Tags bmp image imagemagick
Powerful convert commands
The convert command can be used to convert the image format. jpg, BMP, PCX, GIF, PNG, Tiff, XPM, and xwd types are supported. The following is an example:
Convert xxx.jpg xxx.png convert jpeg to PNG file
Convert xxx.gif xxx.bmp convert GIF to BMP Image
Convert XXX. Tiff XXX. PCX convert tiff to PCX Image
You can also change the image size:
Convert-resize 1024x768 xxx.jpg xxx1.jpg change the image pixel to 1024*768. Note that the lowercase letter X is used between 1024 and 768.
Convert-sample 50% x50 % xxx.jpg xxx1.jpg: reduce the image size to 50% * 50%
Rotating image:
Convert-rotate 270 sky.jpg sky-final.jpg rotate the image 270 degrees clockwise
Use the-draw option to add text to the image:
Convert-fill black-pointsize 60-font Helvetica-draw 'text 10, 80 "Hello, world! "'Hello.jpg helloworld.jpg
Write Hello, world in the black Helvetica font at the 10th and 80th positions of the image!
Convert has many other interesting and powerful functions. You may try it.

Several simple applications.

 1. Batch image format conversion

If you want to convert all JPG files in a directory to PNG files, you only need to enter:

For % F in (*. jpg) Do convert "% F" "% ~ Nf.png"

  2. perform the same operation on all images

For example, to generate thumbnails of all PNG image files in a directory in batches (the size is 80 × 40 ):

For % F in (*. PNG) Do convert "% F"-sample 80 × 40 "% ~ Nf_sample.png"

Similarly, to rotate all PNG images in a directory 90 degrees:

For % F in (*. PNG) Do convert "% F"-Rotate 90 "% ~ Nf_rotate.png"

You can also batch crop, fade, jitter, carbonization, adding borders, rounded corners and a series of operations, specific can refer to: Linux/L-GRAF/index.html ">


 3. Add text instructions to the image

If you need to publish a large number of images, it is wise to add copyright notice to all images. Imgemagick can be easily implemented:

Convert 1.png-fill white-pointsize 13-draw "text 2006, 15 'lifesinger 100'" 2.png

You can use-font to specify the font, then you need to install ghostscript support: /~ Ghost/

You can also use the composite command to add watermarks to all images. For more information, see:




Convert image formats and sizes, blur, crop, remove stains, jitter, approaching, draw images on images, add new images, and generate thumbnails.


Describes the format and features of one or more image files.


Make an image of the specified size, blur, crop, and shake. Mogrify rewrite the original image file and then write it to a different image file.


Generate an image based on one or more images.


Create separate element images. Any decorative image containing element images, such as borders, structures, and image names.


Perform arithmetic and visual evaluations on different images and other transformed images.


If you have an X server system, it can display images in order.


Use X server to display animated images


Output image files in X server or any visible window. You can capture a single window, the entire screen or the rectangular part of any screen.


Explain the script written by MSL (magick scripting language.

Convert-sample 100 × 20 input.jpg output.jpg

The preceding command generates a 100x20 thumbnail.

A better way is to use proportional scaling to generate 1/4 thumbnails in a unified manner.

Convert-sample 25% x25 % input.jpg output.jpg

If you write a script, it looks like this.

For IMG in 'ls *. jpg'


Convert-sample 25% x25 % $ {IMG} THM $ {IMG}


Add Images

Convert-font fonts/font. TTF-stroke color-fill color-pointsize size

-Draw 'text 10, 10 "string" 'input.jpg output.jpg

-Font specifies the font, Because I add text,

-Color used for stroke,

-The color used for fill filling. here we can use none to draw hollow words,

-Pointsize: font size, number of bytes,

-Draw is used for painting. Here is the text. The position 10 and 10 are the coordinates of the source at the top left corner of the image.

Add text comments to images

Sometimes you need to add text comments to the image. For example, assume that your company has a standard business card image and you want to add the details of each employee to the business card before sending the business card to the printer. Another example is to generate a presentation certificate for users of online courses on your website ).

You can use the following command line to comment out some identification information for the graph:

Convert-font Helvetica-fill white-pointsize 36

-Draw 'text 2002, 50 "Floriade, Canberra, Australia "'

Floriade.jpg comment.jpg

So far, this is the most complex convert command line I have shown in this article, so I will spend some time explaining it.

-Font Helvetica: Set the annotation font to Helvetica. You can also specify the path of the font file here. This example adds a flag to the image so that the image cannot be used by other websites without permission, but it uses a font in a non-standard location to complete the task:

Convert-font fonts/1900805.ttf-fill white-pointsize 36

-Draw 'text 10,475 " "'

Floriade.jpg stillhq.jpg

-Fill white is filled with letters in white instead of Standard black.

-Pointsize 36: specify the size of letters in the unit of points. 1 inch equals to 72.

-Draw 'text 10, 50 "…" 'Is a set of drawing commands. In this example, move to position 10, 50, and draw the text in double quotation marks. The single quotation mark is used because if multiple words need to be drawn, double quotation marks must be used in the drawing command, and double quotation marks cannot be used in double quotation marks.

Execute multiple commands in one ImageMagick call

You have seen the example linking the command with the annotation example. However, you can link any ImageMagick command mentioned in this article. For example, we may want to create a thumbnail of an image and then apply the divergence to it. After divergence, we will apply the carbon pen effect:

Convert-sample 25% x25 %-spread 4

-Charcoal 4 input.jpg output.jpg

Use convert to add borders to images

Convert-raise 5 × 5 input.jpg output.jpg

Convert + raise 5 × 5 input.jpg output.jpg

The above commands use-, + edge color to process the edge respectively!

Convert-bordercolor red-border 5 × 5 input.jpg output.jpg

Simply add a red edge with 5 pixels wide!

Convertconvert, as its name implies, is used to convert the image format. It can also perform operations such as scaling, cropping, blurring, and inversion.

For example, converting foo.jpg to foo.png:

Convert foo.jpg foo.png if you want to convert all JPG files in the directory to gif, you can use the powerful functions of shell:

Find./-name "*. jpg"-exec convert {} {}.gif \; the converted GIF name is * .jpg.gif, which looks unnatural. It doesn't matter. Let's take another step:

Rename .jpg.gif. gif * contains an ugly name, but you don't know why. If you know it, tell me or you can use shell script to complete the above operations:

For I in *. jpg


Convert $ I 'basename $ I .jpg'.gif

Done we can also use mogrify to achieve the same effect:

The command above mogrify-format PNG *. jpg will convert all JPG files under the Directory into PNG format. Convert can also convert multiple photos into PDF format:

Convert *. jpg foodies size scaling. For example, if we want to make a thumbnail for a normal-sized image, we can

Convert-resize 100x100 foo.jpg thumbnail.jpg can also be used as a percentage, which is more intuitive:

Convert-resize 50% x50 % foo.jpg thumbnail.jpg convert will automatically consider the ratio of the Image Height to width when the image is scaled up, that is, the aspect ratio of the new image is the same as that of the original image. We can also generate thumbnails in batches:

Mogrify-sample 80x60 *. jpg note that this command will overwrite the original image, but you can back up your image before performing this operation.

You can use the-mattecolor parameter to add a border around a photo. For example, if a comrade sacrifices the border, we need to make a black border for him:

Convert-mattecolor "#000000"-frame 60x60 yourname.jpg rememberyou.png where "#000000" is the border color and the border size is 60x60. You can add a border as follows:

Convert-border 60x60-bordercolor "#000000" yourname.jpg rememberyou.png add text to the image

Convert-fill Green-pointsize 40-draw 'text 10, 50 "" 'foo.png bar.png above the command 10 × 50 from the upper left corner of the image, write in green, if you want to specify another font, you can use the-font parameter.

Fuzzy Gaussian Blur:

The convert-blur 80 foo.jpg foo.png-blur parameter can also be-blur 80 × 5. The 5 that follows represents the sigma value. This is an image term and I am not quite clear about it. In short, its value plays a key role in the blur effect.

Flip up/down flip:

Convert-flip foo.png bar.png:

Convert-flop foo.png bar.png:

Convert-negate foo.png bar.png convert the image into a black and white color in a monochrome manner:

Convert-monochrome foo.png bar.png + Noise

Convert-noise 3 foo.png bar.png this function can be used to convert an ordinary image into an oil painting.

Convert-paint 4 foo.png bar.png rotate an image at a certain angle:

30 on convert-rotate 30 foo.png bar.png indicates 30 degrees of rotation to the right. If you want to rotate to the left, the degree is negative.

Charcoal pen Effect

Convert-charcoal 2 foo.png bar.png to form a charcoal pen or pencil drawing.

Scattering glass effect:

The convert-spread 30 foo.png bar.png vortex uses the image center as a reference to reverse the image to form the vortex effect:

Convert-swirl 67 foo.png bar.png use-raise to create a convex edge:

After convert-raise 5x5 foo.png bar.png is executed, you will see a 5x5 side around the photo. If you want a concave side, change-raise to + raise. In fact, the difference between the convex side and the concave side is not very big.

Other functions are not commonly used. If you are interested, you can refer to its online documentation.

Importimport is a screen component. The following lists common functions. For other functions, refer to man.

Truncates any rectangular area of the screen.

Import foo.png after entering the preceding command, Your mouse will become a cross. At this time, you only need to draw a rectangle at the place you want to intercept.

Truncate the program window

Import-Pause 3-frame foo.png, press enter, and click on the window you want to intercept. The role of the parameter-frame is to tell the import that the external frame of the target window is taken. The parameter-pause is very important. You can try to remove it and compare it, you will find that the title bar of the target window is gray, and pause is to delay the import a little. It will only start when the focus of your target window is reached, so that the figure is more natural.

To intercept a skewed window and compare it with cool, you can intercept a skewed window as follows:

Import-rotate 30-Pause 3-frame foo.png captures the entire Screen

Import-Pause 3-window root screen.png Note: After being suspended for 3 seconds, you need to switch to the image to be captured within 3 seconds.

Displaydisplay should be the most frequently used image processing software.

Show Image

Display foo.png if you want to display multiple files, you can use wildcards

Display *. PNG slides

Display-delay 5 * display an image every 5 percent seconds

Shortcut Keys

Space: displays the next image.

Backspace: displays the previous image

H: horizontal flip

V: vertical flip

/: Rotate 90 degrees clockwise

\: Rotate 90 degrees counter-clockwise

>: Zoom in

<: Zoom out

F7: Blurred Image

Alt + S: rotate the pixels in the middle of the image

CTRL + S: Save the image

CTRL + D: delete an image

Q: Exit

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.