From 5389dfc5aad3a6bb9d0ab00b15145ad818f77f23 Mon Sep 17 00:00:00 2001 From: GOLinux Date: Wed, 10 Dec 2014 09:04:38 +0800 Subject: [PATCH] [Translated] 20141208 Linux FAQs with Answers--How to crop an image from the command line on Linux.md --- ...an image from the command line on Linux.md | 45 ------------------- ...an image from the command line on Linux.md | 44 ++++++++++++++++++ 2 files changed, 44 insertions(+), 45 deletions(-) delete mode 100644 sources/tech/20141208 Linux FAQs with Answers--How to crop an image from the command line on Linux.md create mode 100644 translated/tech/20141208 Linux FAQs with Answers--How to crop an image from the command line on Linux.md diff --git a/sources/tech/20141208 Linux FAQs with Answers--How to crop an image from the command line on Linux.md b/sources/tech/20141208 Linux FAQs with Answers--How to crop an image from the command line on Linux.md deleted file mode 100644 index 1ec7d0a491..0000000000 --- a/sources/tech/20141208 Linux FAQs with Answers--How to crop an image from the command line on Linux.md +++ /dev/null @@ -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 diff --git a/translated/tech/20141208 Linux FAQs with Answers--How to crop an image from the command line on Linux.md b/translated/tech/20141208 Linux FAQs with Answers--How to crop an image from the command line on Linux.md new file mode 100644 index 0000000000..d7683d12f3 --- /dev/null +++ b/translated/tech/20141208 Linux FAQs with Answers--How to crop an image from the command line on Linux.md @@ -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.png,convert命令会将剪裁后的图像存储为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