![linux映像](https://i-blog.csdnimg.cn/blog_migrate/95f47ec5b07ea413b6bad6a1b5ed2ee8.png)
linux映像
![header imagemagick header imagemagick](https://i-blog.csdnimg.cn/blog_migrate/055e7dc4fcc6bd245c07d8eb8c0d6276.png)
ImageMagick is a suite of command-line utilities for modifying and working with images. ImageMagick can quickly perform operations on an image from a terminal, perform batch processing of many images, or be integrated into a bash script.
ImageMagick是一套用于修改和使用图像的命令行实用程序。 ImageMagick可以快速从终端对图像执行操作,对许多图像进行批处理,或者集成到bash脚本中。
ImageMagick can perform a wide variety of operations. This guide will introduce you to ImageMagick’s syntax and basic operations and show you how to combine operations and perform batch processing of many images.
ImageMagick可以执行多种操作。 本指南将向您介绍ImageMagick的语法和基本操作,并向您展示如何组合操作并执行许多图像的批处理。
安装 (Installation)
ImageMagick isn’t included in the default installations of Ubuntu and many other Linux distributions. To install it on Ubuntu, use the following command:
Ubuntu和许多其他Linux发行版的默认安装中未包含ImageMagick。 要将其安装在Ubuntu上,请使用以下命令:
sudo apt-get install imagemagick
在格式之间转换 (Converting Between Formats)
The convert command takes an image, performs actions on it, and saves the image with the file name you specify. One of the most basic things you can do with it is converting images between formats. The following command takes a PNG file named “howtogeek.png” in the current directory and creates a JPEG image from it:
convert命令获取图像,对其执行操作,然后使用您指定的文件名保存该图像。 您可以执行的最基本的操作之一就是在格式之间转换图像。 以下命令在当前目录中获取一个名为“ howtogeek.png”的PNG文件,并从中创建一个JPEG图像:
convert howtogeek.png howtogeek.jpg
![convert formats convert formats](https://i-blog.csdnimg.cn/blog_migrate/e5810547bf7abf180884b7c25779c114.png)
You can also specify a compression level for JPEG images:
您还可以为JPEG图像指定压缩级别:
convert howtogeek.png -quality 95 howtogeek.jpg
The number must be between 1 and 100. ImageMagick uses the quality level of the input image, if possible. If not, ImageMagick defaults to 92.
该数字必须在1到100之间。ImageMagick尽可能使用输入图像的质量等级。 如果不是,则ImageMagick默认为92。
调整图像大小 (Resizing Images)
The convert command can also quickly resize an image. The following command asks ImageMagick to resize an image to 200 pixels in width and 100 pixels in height:
convert命令还可以快速调整图像大小。 以下命令要求ImageMagick将图像调整为宽度200像素和高度100像素:
convert example.png -resize 200x100 example.png
We’ve used the same file name here, so ImageMagick will overwrite the original file.
我们在这里使用了相同的文件名,因此ImageMagick将覆盖原始文件。
![resize resize](https://i-blog.csdnimg.cn/blog_migrate/40c493e7140539055ae71bea39bfd8ed.png)
ImageMagick will try to preserve the aspect ratio if you use this command. It will alter the image to fit within a 200×100 area, but the image may not be exactly 200×100. If you want to force the image to become a specific size – even if it messes up the aspect ratio – add an exclamation point to the dimensions:
如果使用此命令,ImageMagick将尝试保留宽高比。 它将更改图像以适合200×100的区域,但是图像可能不完全是200×100。 如果要强制将图像变成特定的大小(即使它弄乱了宽高比),请在尺寸上添加一个感叹号:
convert example.png -resize 200x100! example.png
You can also specify a specific width or height and ImageMagick will resize the image to that width or height while preserving the aspect ratio. The following command will resize an image to a width of 200:
您还可以指定特定的宽度或高度,ImageMagick会在保留纵横比的同时将图像调整为该宽度或高度。 以下命令会将图像大小调整为200的宽度:
convert example.png -resize 200 example.png
The following command will resize an image to a height of 100:
以下命令将图像大小调整为100的高度:
convert example.png -resize x100 example.png
旋转影像 (Rotating an Image)
ImageMagick can quickly rotate an image. The following command takes an image named howtogeek.jpg, rotates it by 90 degrees and saves the rotated image as howtogeek-rotated.jpg:
ImageMagick可以快速旋转图像。 以下命令获取名为howtogeek.jpg的图像,将其旋转90度并将旋转后的图像另存为howtogeek-rotated.jpg:
convert howtogeek.jpg -rotate 90 howtogeek-rotated.jpg
If you specified the same file name, ImageMagick would save the rotated image over the original image file.
如果指定了相同的文件名,则ImageMagick会将旋转后的图像保存在原始图像文件上。
![rotate rotate](https://i-blog.csdnimg.cn/blog_migrate/33be6c4acd59a61514b0935089f3ca43.png)
应用效果 (Applying Effects)
ImageMagick can apply a variety of effects to an image. For example, the following command applies the “charcoal” effect to an image:
ImageMagick可以对图像应用各种效果。 例如,以下命令将“木炭”效果应用于图像:
convert howtogeek.jpg -charcoal 2 howtogeek-charcoal.jpg
![charcoal charcoal](https://i-blog.csdnimg.cn/blog_migrate/5f71de921477a90d7d358a4e99a8825d.png)
The charcoal command applies an artistic “charcoal” style effect to an image – the 2 in the command lets you control the strength of the effect.
木炭命令将艺术性的“木炭”样式效果应用于图像–命令中的2可让您控制效果的强度。
![howtogeek-charcoal howtogeek-charcoal](https://i-blog.csdnimg.cn/blog_migrate/4e7340aada08d6c04716af515d13c4f2.png)
The following command applies the “Implode” effect with a strength of 1:
以下命令应用强度为1的“放大”效果:
convert howtogeek.jpg -implode 1 howtogeek-imploded.jpg
![implode implode](https://i-blog.csdnimg.cn/blog_migrate/2eb0d2ed0f30bbc4e33f3e8650efa7c3.png)
The implode effect makes it appear as if there’s a black hole at the center of the image.
爆裂效果使其看起来好像图像中心有黑洞。
![howtogeek-imploded howtogeek-imploded](https://i-blog.csdnimg.cn/blog_migrate/a85fb1ad5724f6e7c8407d6d93fdab28.png)
合并作业 (Combining Operations)
All these operations can be combined. With a single command, you could resize an image, rotate it, apply an effect, and convert it to another format:
所有这些操作可以合并。 使用单个命令,您可以调整图像大小,旋转图像,应用效果并将其转换为另一种格式:
convert howtogeek.png -resize 400x400 -rotate 180 -charcoal 4 -quality 95 howtogeek.jpg
![howtogeek-complex howtogeek-complex](https://i-blog.csdnimg.cn/blog_migrate/7779dbf448e249cd268b2b913ecf2464.png)
This is just the start of what you can do with ImageMagick. There are many more operations you can combine.
这只是您使用ImageMagick可以做的开始。 您可以组合更多的操作。
批量处理 (Batch Processing)
You can take advantage of Bash to quickly do batch processing of many images. For example, the following command would take all PNG files in the current directory, rotate them, and save a new copy of each with “rotated-” added to the beginning of each file name.
您可以利用Bash快速处理许多图像。 例如,以下命令将获取当前目录中的所有PNG文件,对其进行旋转,然后使用每个文件名的开头添加“ rotated-”的形式保存每个文件的新副本。
for file in *.png; do convert $file -rotate 90 rotated-$file; done
![batch processing batch processing](https://i-blog.csdnimg.cn/blog_migrate/34ad3e38182f880b2e8193b4159db04e.png)
You can easily modify this command to perform other actions. You can also integrate batch processing commands into a Bash shell script to automate image-processing operations.
您可以轻松地修改此命令以执行其他操作。 您还可以将批处理命令集成到Bash Shell脚本中,以自动执行图像处理操作。
Any article on ImageMagick will omit a lot of what you can do with it – there are just too many options and commands. If you’re interested in doing more with ImageMagick, check out the official documentation on the ImageMagick website for a much more in-depth look at ImageMagick.
关于ImageMagick的任何文章都将忽略您可以做的很多事情-太多的选项和命令。 如果您有兴趣使用ImageMagick进行更多操作,请查看ImageMagick网站上的官方文档,以更深入地了解ImageMagick。
linux映像