如何在终端内递归地批量调整Ubuntu中的图像? [英] How to batch resize images in Ubuntu recursively within the terminal?

查看:146
本文介绍了如何在终端内递归地批量调整Ubuntu中的图像?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有多个图像存储在一组有组织的文件夹中。我需要从父目录中将这些图像重新调整为特定百分比递归。我正在运行Ubuntu 11.10,我更喜欢直接从终端学习如何做到这一点。

I have multiple images stored in a set of organized folders. I need to re-size those images to a specific percentage recursively from their parent directory. I am running Ubuntu 11.10 and i prefer learning how to do that directly from the terminal.

推荐答案

你可以使用 imagemagick 。例如,要将当前目录下的所有JPG图像调整为其原始大小的50%,您可以执行以下操作:

You could use imagemagick. For instance, for resizing all the JPG images under the current directory to 50% of their original size, you could do:

for f in `find . -name "*.jpg"`
do
    convert $f -resize 50% $f.resized.jpg
done

生成的文件名称中将包含两次.jpg。如果这是一个问题,您可以检查以下备选方案。

The resulting files will have ".jpg" twice in their names. If that is an issue, you can check the following alternatives.

要遍历/查找要调整大小的文件,可以使用 xargs 。示例:

For traversing/finding the files to resize, you can use xargs too. Example:

find . -name "*.jpg" | xargs convert -resize 50%

这将创建图像的副本。如果您只想将它​​们转换为,您可以使用:

This will create copies of the images. If you just want to convert them in place, you can use:

find . -name "*.jpg" | xargs mogrify -resize 50%

这篇关于如何在终端内递归地批量调整Ubuntu中的图像?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆