当前位置: 首页>>技术教程>>正文


如何通过命令行轻松调整图像大小?

, , , ,

问题描述

我想知道如何在Ubuntu中调整图像大小。最简单的工具是什么?

最佳解决思路

你想要简单吗?

运行sudo apt-get install nautilus-image-converter,或单击nautilus-image-converter

command-line,images,resize,image-processing,ubuntu

它在nautlius中添加两个上下文菜单项,以便您可以右键单击并选择”Resize Image”。 (另一个是”Rotate Image”)。

如果你喜欢,你可以一次完成一个完整的图像目录,你甚至不需要打开一个应用程序来这样做。

您需要重新启动nautilus才能查看新的上下文菜单,运行nautilus -q,然后单击主文件夹图标以使用新的plug-in重新加载nautilus。

次佳解决思路

首先通过以下方式安装ImageMagick

sudo apt-get install imagemagick

打开一个终端并运行以下命令:

convert  -resize 50% source.png dest.jpg

它会缩小50%

您还可以指定大小:

convert -resize 1024X768  source.png dest.jpg

您也可以使用:mogrify 命令行工具来自同一个软件包。

第三种解决思路

sudo apt-get install imagemagick

命令mogrify用改变后的图像覆盖原始文件:

mogrify -resize 50% *.png      # keep image aspect ratio
mogrify -resize 320x240 *.png  # keep image aspect ratio
mogrify -resize 320x240! *.png # don't keep image aspect ratio
mogrify -resize x240 *.png     # don't keep image aspect ratio
mogrify -resize 320x *.png     # don't keep image aspect ratio

注意:您可以添加-auto-orient以自动定向转换的图像。

第四种思路

如果你只是做了几个图像,Ubuntu中的大多数图像编辑器(Gimp,F-Spot等)将允许你做一个基本的调整大小。

如果你想编辑数十,数百或数千的图像,我更喜欢Phatch。 Phatch是一款GUI-based批量照片编辑器,可让您对图像执行全部的转换工作。 sudo apt-get install phatch

ImageMagick很好,但如果你不知道事物的设置名称,那么它有点乏味。你可以通过点击四处快速学习Phatch。

第五种思路

GIMP可能是最简单的方法,因为它对于这样的常见任务有相当简单的用户界面。您只需打开图像并转到图像→图像大小,然后相应地进行更改。还有一些方法可以使用GIMP进行批量调整大小,但我不太了解它们。

第六种思路

ImageMagick是你想要的软件包。它包含许多用于此目的的有用的命令行工具。

Here’s一个简单的教程,解释如何批量调整图像尺寸: –

mogrify -resize 320x240 *.jpg

After this command is completed, all of the images will be replaced with resized version of themselves. Notice that in an effort to preserve the image aspect ratio, mogrify may not be produce images that are exactly 320×240. To force this to happen, modify the original command to by placing an exclamation point at the end of the desired resolution:

mogrify -resize 320x240! *.jpg

第七种思路

目前nautilus-image-converter在Ubuntu 13.10中不起作用。因此,我在命令行上使用imagemagick,这是非常好的解决方法(至少对我而言)。

sudo apt-get install imagemagick

请记住difference between these imagemagick tools

  • Mogrify在相同的图像上进行处理,它读取文件修改文件并将输出写入相同的文件。

  • 转换意味着在单独的图像上工作,读取文件并修改并写入不同的文件/格式。您也可以使用convert命令来使用与输入文件相同的输出文件。

我经常使用mogrify来调整多个图像的大小并覆盖原始文件。 I. e。此命令会将所有JPG文件的尺寸缩小到原始尺寸的40%:

mogrify -verbose -resize '40%' *.JPG

第八种思路

不需要安装任何新软件就可以做到这一点

convert -resize 50% myfigure.png myfigure.jpg

要么

convert myfigure.png -resize 200x100 myfigure.jpg

第九种思路

安装gthumb。简单和容易的基本图像处理和编辑功能 – 查看器,调整大小,裁剪,旋转,翻转,灰度等与选项保存在JPEG,PNG,TIFF,TGA格式。

安装gthumb:

  • 打开你的终端

  • 键入sudo apt-get install gthumb

  • 接受更改

第十种思路

对于GUI来说,Phatch“点击一次就能胜过千张照片”对于如此快速的工作来说是最好的选择。它已经在Ubuntu存储库中。它具有许多动作和选项,如imagemagick

sudo apt-get install phatch

参考资料

本文由Ubuntu问答整理, 博文地址: https://ubuntuqa.com/article/258.html,未经允许,请勿转载。