from:linux a script to compress a photo or picture (ImageMagick, convert,import,display instance) with a command line
Before I know ImageMagick, I use the image browsing software is kuickshow, screenshot software is Ksnapshot, these two software are KDE software, use it is quite convenient. In an accidental opportunity, I met ImageMagick, only to find that Linux has so powerful image software.
You will find that most of the operation, you just move the keyboard at the end, so that you do not use the mouse point to point to.
Below, I do a simple introduction to the main functions of ImageMagick, which covers most of the people commonly used functions, if you want to fully understand its knowledge, you can look at its man handbook. Convert
Convert as the name implies is to transform the image, it is mainly used to transform the format of the image, but also to do scaling, shearing, blur, inversion and other operations.
Format Conversion
Like converting foo.jpg to FOO.PNG:C code convert foo.jpg foo.png
If you want to convert all the JPG files in the directory to GIF, we can use the power of the shell: C code Find./-name "*.jpg"-exec convert {} {}.gif \; Translated GIF name called *.jpg.gif, so that does not look natural, it does not matter, we can go another step: C code rename. Jpg.gif. gif *.jpg.gif Originally, I want to find in the time, with basename to get the filename without suffix, this The sample will not form. Jpg.gif this ugly name, but don't know why, just can't, if you know, tell me
Alternatively, you can do this by using shell script: C code for I-*.jpg do convert $i ' basename $i. jpg '. gif done
We can also use mogrify to accomplish the same effect: C code mogrify-format PNG *.jpg
The above command will convert all JPG files below the directory into PNG format.
Convert can also convert multiple photos into PDF format: C code convert *.jpg foo.pdf size Scaling
For example, we want to do a normal size of the picture to make a thumbnail, we can do so C code convert-resize 100x100 foo.jpg thumbnail.jpg You can also use a percentage, this more intuitive: C code convert-res ize 50%x50% foo.jpg thumbnail.jpg Convert automatically considers the ratio of the height of the image to the size of the image, which means the new image has the same aspect ratio as the original.
We can also batch-generate thumbnails: C code mogrify-sample 80x60 *.jpg Note that this command will overwrite the original image, but you can back up your picture before you operate. Add Border
In a photo surrounded by a border, you can use-mattecolor parameters, such as a comrade sacrifice, we need to make a black border of his portrait, you can: C code convert-mattecolor "#000000"-frame 60x60 yourname . jpg Rememberyou.png
Where, "#000000" is the color of the border, the size of the border is 60x60
You can also add a border: C code convert-border 60x60-bordercolor "#000000" Yourname.jpg rememberyou.png
add text to a picture C Code convert-fill green-pointsize 40-draw ' text 10,50 ' charry.org ' foo.png ' the command in the upper left corner of the picture bar.png position, with green words to write down C harry.org, if you want to specify a different font, you can use the-font parameter. Blurred
Gaussian Blur: C code convert-blur foo.jpg Foo.png-blur parameters can also be-blur 80x5. The latter 5 represents the value of sigma, which is an image term, and I'm not quite sure, in short, that its value plays a key role in blurring the effect. Flip
Flip down: C code convert-flip foo.png bar.png
Flip around: C code convert-flop foo.png bar.png
Anti-color
form a negative appearance: C code convert-negate foo.png bar.png
Monochrome
Turn the picture into Black-and-white color: C code convert-monochrome foo.png bar.png plus noise C code convert-noise 3 Foo.png
oil Painting effect
We can use this function to put an ordinary picture into an oil painting, the effect is very lifelike C code convert-paint 4 Foo.png bar.png
Rotate
Put a picture, rotate a certain angle: C code convert-rotate foo.png bar.png
The above 30, the right to rotate 30 degrees, if you want to rotate to the left, the degree is negative. Charcoal Effect C Code convert-charcoal 2 foo.png bar.png form a charcoal or pencil-drawing effect. scattering
Hair Glass Effect: C code convert-spread foo.png bar.png
Whirlpool
Take the center of the picture as a reference, twist the picture to form the effect of the Whirlpool: C code convert-swirl foo.png bar.png
Convex effect
Use-raise to create convex edges: C code convert-raise 5x5 foo.png bar.png
After execution, you will see that the photo will be surrounded by a 5x5 edge, if you want a concave edge, the-raise to +raise on it. In fact, the convex and concave edges do not look very much different. other
Other features are less commonly used, if you are interested, you can look at its online documentation Import
Import is a screen capture component, listed below are our common features, other features, you refer to its man good.
intercepts any rectangular area of the screen C Code Import foo.png after entering the above command, your mouse will become a cross, this time, you just want to intercept the place to draw a rectangle can be intercepting the program's window C code import-pause 3-frame foo. After PNG returns, use the mouse to click on the window you want to intercept. The role of the parameter-frame is to tell import, screenshots when the target window outside the frame band, parameter-pause role is very important, you can try to remove it, contrast, you will find that the target window of the title bar is gray, pause is to let import a little delay, Wait for your target window to get focus, only to start screenshots, such a diagram is more natural. to intercept a tilted window
If you want your screenshot to be cool, you can intercept a tilted window as follows: C code import-rotate 30-pause 3-frame foo.png
intercept the entire screen C code import-pause 3-window root Screen.png Note that 3 seconds have been paused, and you need to switch to the desired screen within 3 seconds. Display
Display should be we use the most frequent image processing software, after all, still see more
Show Pictures C Code Display Foo.png if you want to display multiple files, you can use the wildcard character C code display *.png slide C code display-delay 5 * Show one per 5 sec Picture some shortcut keys space (spaces): Show next picture backspace (delete key): Show previous picture h: Flip Horizontal V: Flip vertically/: Rotate clockwise 90 degrees: 90 degrees Counterclockwise: Zoom in: Zoom out F7: Blur picture alt+s: Image in the middle of the pixel rotation ctrl+s: Image save ctrl+d: Delete picture Q: exit other
ImageMagick also provides a rich programming interface, for example, you can use PHP to invoke it, using ImageMagick to generate code pictures, the effect is very good.
ImageMagick also has a gadget identify, which can be used to display Shishi information about a picture file, such as format, resolution, size, color depth, etc., which you could use to help you.
If you are not familiar with the command line, you can also click on the picture, you will find that through the mouse you can also complete the image editing.
ImageMagick's website: www.imagemagick.org. Here is an example of a imagemagick-processed picture.
Original: http://www.charry.org/docs/linux/ImageMagick/ImageMagick.html
Example:
convert command format: -resize widthxheight{%} {@} {!} {;} {} {^}
1. By default, width and height represent the ultimate need to convert the maximum size of the image, while convert controls the width and height of the picture, ensuring that the picture is scaled proportionally.
such as:convert-resize 600x600 src.jpg dst.jpg
The converted Dst.jpg picture size (width is 600, and height has been scaled to 450).
2. If you need to convert to 600x600, and the picture does not need to maintain the original proportions, you can add an exclamation point after the height!.
such as:convert-resize 600x600! src.jpg dst.jpg
3. Specify only the height, the picture will be converted to the specified height value, and the width will be converted to the original picture proportions.
such as:convert-resize src.jpg dst.jpg
The converted Dst.jpg's picture size (width is 400 and the height has been scaled to 300) is somewhat similar to the example 1.
4. The default is to use pixels as a unit, or you can use a percentage to image the scale of the picture.
such as:convert-resize 50%x100%! src.jpg dst.jpg or convert-resize 50%x100% src.jpg
This parameter will only be scaled to your scale, not to maintain the original proportions. (The result size is 100x150)
5. Use @ To create a picture of the number of pixels.
such as:convert-resize "10000@" Src.jpg dst.jpg
After this command executes, the dst.jpg picture size is (115x86) and the picture remains the original proportions (115x86= 9080 < 10000).
6. when the original file is larger than the specified width, the picture is enlarged and reduced, and the > command suffix can be used.
such as:convert-resize "100x50>" Src.jpg dst.jpg
After this command executes, the dst.jpg picture size is (67x50) and the picture remains in its original proportions.
such as:convert-resize "100x50>!" Src.jpg dst.jpg
After this command executes, the dst.jpg picture size is (100x50) and the picture does not maintain the original proportions.
7. when the original file is smaller than the specified width, the image amplification conversion, you can use the < command suffix.
such as:convert-resize "100x500<" src.jpg dst.jpg or convert-resize "100x100<!" src.jpg dst.jpg
After this command executes, the dst.jpg and src.jpg sizes are the same, because the original picture is wider than 100.
such as:convert-resize "600x600<" Src.jpg dst.jpg
After this command executes, the dst.jpg picture size is (600x450) and the picture remains in its original proportions.
such as:convert-resize "600x600<!" Src.jpg dst.jpg
After this command executes, the dst.jpg picture size is (600x600) and the picture does not maintain the original proportions.
8. Use the ^ command suffix to use the smaller value of the wide high school as the size
such as:convert-resize "300x300^" Src.jpg dst.jpg
After this command executes, the dst.jpg picture size is (400x300), the picture remains the original proportions, (300:300 < 200:150, select High as the minimum size).
such as:convert-resize "300x200^" Src.jpg dst.jpg
After this command executes, the dst.jpg picture size is (300x225), the picture remains the original proportions, (300:200 > 200:150, select Width as the minimum size).