[Translated] 20141208 Linux FAQs with Answers--How to crop an image from the command line on Linux.md

This commit is contained in:
GOLinux 2014-12-10 09:04:38 +08:00
parent 0559d98356
commit 5389dfc5aa
2 changed files with 44 additions and 45 deletions

View File

@ -1,45 +0,0 @@
Translating by GOLinux!
Linux FAQs with Answers--How to crop an image from the command line on Linux
================================================================================
> **Question**: I would like to get rid of white margins of an image file. Is there an easy way to crop an image file from the command line on Linux?
When it comes to converting or editing images files on Linux, ImageMagick is undoubtedly one of the best known all-in-one image software. It boasts of a suite of command-line tools to display, convert, or manipulate more than 200 types of raster or vector image files, all from the command line. ImageMagick can be used for a variety of image editing tasks, such as converting file format, adding special effects, adding text, and transforming (resize, rotate, flip, crop) images.
If you want to crop an image to trim its margins, you can use two command-line utilities that come with ImageMagick. If you haven't installed ImageMagick, follow [this guideline][1] to install it.
In this tutorial, let's crop the following PNG image. We want to get rid of the right and bottom margins of the image, so that the chart will be centered.
![](https://farm8.staticflickr.com/7562/15688242319_ed19aca3a2_z.jpg)
First, identify the dimension (width and height) of the image file. You can use identify command for that.
$ identify chart.png
----------
chart.png PNG 1500x1000 1500x1000+0+0 8-bit DirectClass 31.7KB 0.000u 0:00.000
As shown above, the input image is 1500x1000px.
Next, determine two things for image cropping: (1) the position at which the cropped image will start, and (2) the size of the cropped rectangle.
In this example, let's assume that the cropped image starts at top left corner, more specifically at x=20px and y=10px, and that the size of a cropped image will be 1200x700px.
The utility used to crop an image is convert. With "-crop" option, the convert command cuts out a rectangular region of an input image.
$ convert chart.png -crop 1200x700+20+10 chart-cropped.png
Given the input image chart.png, the convert command will store the cropped image as chart-cropped.png.
![](https://farm8.staticflickr.com/7527/15872271461_401276e072_z.jpg)
--------------------------------------------------------------------------------
via: http://ask.xmodulo.com/crop-image-command-line-linux.html
译者:[译者ID](https://github.com/译者ID)
校对:[校对者ID](https://github.com/校对者ID)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创翻译,[Linux中国](http://linux.cn/) 荣誉推出
[1]:http://ask.xmodulo.com/install-imagemagick-linux.html

View File

@ -0,0 +1,44 @@
Linux有问必答——如何在Linux命令行中剪裁图像
================================================================================
> **问题**我想要去除图像文件中的白色空白有没有什么便捷的方法能在Linux命令行中对图像文件进行剪裁
当涉及到在Linux中转换或编辑图像文件时ImageMagick毫无疑问是最为熟知的一体化软件之一。它包含了一整套命令行工具用以显示、转换或复制超过200中类型的光栅或矢量图像文件所有这一切都在命令行下完成。ImageMagick可以用于多样化的图像编辑工作如转换文件格式添加特殊效果添加文本以及改变图像调整大小、旋转、翻转、剪裁
如果你想要剪裁映像以剪除空白你可以使用ImageMagick自带的两个命令行工具。如果你还没有安装ImageMagick请遵循[本指南][1]来安装。
在本教程中让我们来剪裁以下PNG图像。我们想要去除图像右边和底部的空白以便让图标居中。
![](https://farm8.staticflickr.com/7562/15688242319_ed19aca3a2_z.jpg)
首先鉴定图像文件的尺寸宽度和高度。你可以使用identity命令来完成此事。
$ identify chart.png
----------
chart.png PNG 1500x1000 1500x1000+0+0 8-bit DirectClass 31.7KB 0.000u 0:00.000
就像上面显示的那样输入的图像是1500x1000px。
接下来确定图像剪裁要做的两件事1剪裁图像开始的位置2剪裁矩形区域的大小。
在本例中让我们假定图像剪裁从左上角开始更精确点是在x=20px和y=10px那样的话剪裁后的图像尺寸为1200x700px。
用于剪裁图像的工具是convert。使用“-crop”选项后convert命令会在输入图像中剪裁出一个矩形区域。
$ convert chart.png -crop 1200x700+20+10 chart-cropped.png
指定输入图像为chart.pngconvert命令会将剪裁后的图像存储为chart-cropped.png。
![](https://farm8.staticflickr.com/7527/15872271461_401276e072_z.jpg)
--------------------------------------------------------------------------------
via: http://ask.xmodulo.com/crop-image-command-line-linux.html
译者:[GOLinux](https://github.com/GOLinux)
校对:[校对者ID](https://github.com/校对者ID)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创翻译,[Linux中国](http://linux.cn/) 荣誉推出
[1]:http://ask.xmodulo.com/install-imagemagick-linux.html