convert command in Linux

Original: http://zlb1986.iteye.com/blog/778054
Reprinted:
Powerful convert command
convert command can be used to convert image formats, supports JPG, BMP, PCX, GIF, PNG, TIFF, XPM and XWD and other types, Here are a few examples:
  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 Size:
  convert -resize 1024x768 xxx.jpg xxx1.jpg Change the pixel of the image to 1024*768, note that between 1024 and 768 there are lowercase letters x
  convert -sample 50%x50% xxx.jpg xxx1.jpg Reduce the image to The original 50%*50%
rotated 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 60 point all black Helvetica at position 10,80 of the image !
convert has many other interesting and powerful functions, you may wish to try it.

To be edited. . .


A few simple applications.

  1. Batch image format conversion

  If you want to convert all jpg files in a directory to png files, just enter in command line mode:

  for %f in (*.jpg) do convert “%f” “%~nf.png 2. Perform the

  same operation on all images

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

  for %f in (*.png) do convert “%f” -sample 80× 40 Similar to “%~nf_sample.png”

  , the operation to rotate all PNG images in a directory by 90 degrees is:

  for %f in (*.png) do convert “%f” -rotate 90 “%~nf_rotate.png”

  You can also perform a series of operations such as batch cropping, lightening, dithering, carbonization, adding borders, rounding corners, etc. For details, please refer to: linux/l-graf/index.html">http://www.ibm.com/developerworks/ cn/linux/l-graf/index.html

  http://linux.chinaunix.net/docs/2006-12-15/3481.shtml

  3. Add text

  descriptions to images It's wise to add a copyright notice on all images. It's easy to do with ImgeMagick:

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

  can use -font To specify the font, you need to install Ghostscript support: http://www.cs.wisc.edu/~ghost/

  You can also use the composite command to add watermarks to all images. If you are interested, see here:

  http://www. imagemagick.org/script/composite.php

  —————————————————————————————————————————— –

  convert

  converts image formats and sizes, blurs, crops, removes blemishes, dithers, nears, draws images on top of images, adds new images, generates thumbnails, etc.

  identify

  describes the format and characteristics of one or more image files.

  mogrify

  makes an image at the specified size, blurring, cropping, dithering, etc. Mogrify overwrites the original image file and then writes to a different image file.

  composite

  generates images based on one image or a combination of multiple images.

  montage

  creates some separate feature images. Arbitrary decorative pictures in element images, such as borders, structures, picture names, etc.

  compare

  arithmetically and visually evaluates different pictures and other transformed pictures.

  display

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

  animate

  use X server to display animated pictures

  import

  export picture files on X server or any visible window. You can capture a single window, the entire screen or any rectangular portion of the screen.

  conjure

  interprets and executes scripts written in MSL (Magick Scripting Language).

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

  The above command generates a 100×20 thumbnail. A

  better way is to use equal scaling, like this, to uniformly generate 1/4 of the thumbnail

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

  If written as a script, it looks like this

  for img in `ls *.jpg`

  do

  convert -sample 25%x25% ${img} thm${img}

  done

  add image

  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 this way I add text, -stroke is the

  color for the stroke,

  -fill is the color for the fill, here Use none to draw hollow characters,

  -pointsize add the font size, the number of pixels,

  -draw is used to draw, here is the text, the following position 10, 10 is the upper left corner of the picture as the origin coordinate Add text

  to the image Notes

  Sometimes you need to add text notes to images. For example, let's say your company has a standard business card image and wants to add each employee's details to the business card before sending it to the printer. Another example is generating a presentation certificate for users who pass an online course on your website.

  You can annotate the figure with some identifying information using the following command line:

  convert -font helvetica -fill white -pointsize 36

  -draw 'text 10,50 "Floriade 2002, Canberra, Australia"'

  floriade.jpg comment.jpg

  This is by far the most complex convert command line I've shown in this article, so I'll take a moment to explain it.

  -font helvetica Set the font of comments to Helvetica. The path to the font file can also be specified here. This example tags an image so other sites can't use it without permission, but it does the job using a font in a non-standard location:

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

  -draw 'text 10,475 "stillhq.com"'

  floriade.jpg stillhq.jpg

  -fill white Fills the letters with white instead of the standard black.

  -pointsize 36 Specifies the size of letters in points. One inch is equal to 72 points.

  -draw 'text 10,50 "…"' is a set of drawing commands, in this case move to position 10, 50, then draw the text in double quotes. Single quotes are used because if you need to draw multiple words, double quotes are required in the drawing command, and you cannot use double quotes within double quotes.

  Execute multiple commands in one ImageMagick call

  You've seen an example of linking a command with an annotated example. However, it is possible to chain any of the ImageMagick commands mentioned in this article. For example, maybe we want to make a thumbnail of an image and then apply divergence to it. After the divergence occurs, we will apply the charcoal effect:

  convert -sample 25%x25% -spread 4

  -charcoal 4 input.jpg output.jpg

  Use convert to frame the image

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

  convert +raise 5×5 input.jpg output.jpg The

  above commands use -, + edge color respectively to achieve the effect of processing the edge!

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

  Simply add a 5 pixel wide red border!

  Convertconvert, as the name implies, is to convert images. It is mainly used to convert images to formats, and can also perform operations such as scaling, cropping, blurring, and inversion.

  Format conversion such as converting foo.jpg to foo.png:

  convert foo.jpg foo.png If we want to convert all jpg files in the directory to gif, we can use the powerful functions of the shell:

  find ./ -name " *.jpg" -exec convert {} {}.gif \; The converted gif is named *.jpg.gif, which doesn't look very natural, it doesn't matter, we can take another step:

  rename .jpg.gif .gif *.jpg.gif Originally, I wanted to use basename to get the file name without a suffix when I found it, so that the ugly name of .jpg.gif would not be formed. But don't know why, it just doesn't work, if you know, tell me or, you can also use shell script to do the above operation:

  for i in *.jpg

  do

  convert $i `basename $i .jpg`.gif

  done We also You can use mogrify to achieve the same effect:

  mogrify -format png *.jpg The above command will convert all jpg files in the directory to png format. convert can also convert multiple photos into pdf format:

  convert *.jpg foo.pdf size scaling For example, if we want to make a thumbnail for a normal size image, we can

  convert -resize 100x100 foo.jpg thumbnail.jpg You can also You can use a percentage, which is more intuitive:

  convert -resize 50%x50% foo.jpg thumbnail.jpgconvert will automatically consider the ratio of the image's height and width when scaling the image size, which means the new image's height and width The ratio is the same as the original image. We can also generate thumbnails in batches:

  mogrify -sample 80x60 *.jpg Note that this command will overwrite the original images, but you can back up your images before proceeding.

  Add a border to add a border around a photo. You can use the -mattecolor parameter. For example, if a comrade died, we need to make a black border portrait for him, you can do this:

  convert -mattecolor "#000000" -frame 60x60 yourname.jpg rememberyou.png where "#000000" is the color of the border, and the size of the border is 60×60. You can also add a border like this:

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

  convert -fill green -pointsize 40 -draw 'text 10,50 "charry.org"' foo.png bar.png The above command is 10×50 from the top left corner of the image If you want to specify another font, you can use the -font parameter.

  Blur Gaussian Blur:

  convert -blur 80 foo.jpg foo.png -blur The parameter can also be -blur 80×5. The latter 5 represents the value of Sigma, which is an image term, and I don't know much about it. In short, its value plays a key role in the blurring effect.

  Flip up and down:

  convert -flip foo.png bar.png Flip left and right:

  convert -flop foo.png bar.png Invert the color to form a negative:

  convert -negate foo.png bar.png Monochrome Change the image to black and white:

  convert -monochrome foo.png bar.png plus noise

  convert -noise 3 foo.png bar.png oil painting effect We can use this function to turn an ordinary picture into an oil painting, the effect is very realistic

  convert -paint 4 foo.png bar.png rotate a picture, Rotate a certain angle:

  convert -rotate 30 foo.png bar.png The 30 above means rotate 30 degrees to the right. If you want to rotate to the left, the degree is a negative number.

  Charcoal effect

  convert -charcoal 2 foo.png bar.png forms a charcoal or pencil drawing effect.

  Scattered frosted glass effect:

  convert -spread 30 foo.png bar.png The swirl takes the center of the image as a reference, and twists the image to form a swirl effect:

  convert -swirl 67 foo.png bar.png The raised effect uses -raise to create a convex effect Side:

  convert -raise 5x5 foo.png bar.png After executing, you will see that there will be a 5×5 side around the photo. If you want a concave side, change -raise to +raise. . In fact, the convex edge and the concave edge do not seem to be very different.

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

  . Importimport is a component used for screenshots. The following is a list of our commonly used functions. For other functions, you can refer to it. man okay.

  Capture any rectangular area of ​​the screen

  import foo.png After entering the above command, your mouse will turn into a cross. At this time, you only need to draw a rectangle at the place you want to intercept. The window of the

  interception program

  import -pause 3 -frame foo.png After pressing Enter, use the mouse to click on the window you want to cut. The function of the parameter -frame is to tell import to bring the outer frame of the target window when taking a screenshot. The function of the parameter -pause is very important. You can try to remove it. By comparison, you will find that the title bar of the target window is Gray, pause is to delay the import a little bit, wait for your target window to get the focus, and then start taking screenshots. This kind of picture is more natural.

  Capture a slanted window If you want your screenshot to be cooler, you can capture a slanted window as follows:

  import -rotate 30 -pause 3 -frame foo.png to capture the entire screen

  import -pause 3 -window root screen. png Note that after 3 seconds of pause, you need to switch to the screen to be captured within 3 seconds.

  displaydisplay should be the most frequently used image processing software. After all, we still see a lot.

  Display pictures

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

  display *.png slideshow

  display -delay 5 *each Display a picture every 5 hundredths of a second

  Some shortcut keys

  space (space): display the next picture

  backspace (backspace key): display the previous picture

  h: horizontal flip

  v: vertical flip

  /: rotate 90 degrees clockwise

  \: rotate 90 degrees counterclockwise

  >: zoom in

  <: zoom out

  F7: blur the picture

  Alt+s: rotate the pixels in the middle of the picture

  Ctrl+s: save the image as

  Ctrl +d: delete picture

  q: exit

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325370224&siteId=291194637