用于调整图像大小的Shell脚本

时间:2022-01-22 00:26:13

Is there a way to adjust all image sizes in a directory?

有没有办法调整目录中的所有图像大小?

If I set the max size to 800x600 it will make larger ones smaller and leave smaller ones at their original size.

如果我将最大尺寸设置为800x600,则会使较大的尺寸变小,并将较小的尺寸设置为原始尺寸。

3 个解决方案

#1


for img in *.png; do
    convert "$img" "800x600>" $(basename "$img" .png)_new.png
done

convert is from ImageMagick. ">" says it's only resized if larger. See here for its other options.

转换来自ImageMagick。 “>”它表示如果更大则仅重新调整大小。请参阅此处了解其他选项。

#2


image magick package needs to be installed: mogrify -resize 320x240 *.jpg where 320 = width, 240 = height

需要安装image magick包:mogrify -resize 320x240 * .jpg其中320 =宽度,240 =高度

or you can just leave width parameter: mogrify -resize 320 *.jpg and rest will be taken care of.

或者你可以留下宽度参数:mogrify -resize 320 * .jpg和休息将被处理。

#3


Various packages exist for command line or script driven manipulation of image files.

存在用于命令行或脚本驱动的图像文件操纵的各种包。

I'd suggest looking at netpbm, or ImageMagick. Personally I prefer the former as it's far simpler to use.

我建议看看netpbm,或ImageMagick。我个人更喜欢前者,因为它使用起来更简单。

#1


for img in *.png; do
    convert "$img" "800x600>" $(basename "$img" .png)_new.png
done

convert is from ImageMagick. ">" says it's only resized if larger. See here for its other options.

转换来自ImageMagick。 “>”它表示如果更大则仅重新调整大小。请参阅此处了解其他选项。

#2


image magick package needs to be installed: mogrify -resize 320x240 *.jpg where 320 = width, 240 = height

需要安装image magick包:mogrify -resize 320x240 * .jpg其中320 =宽度,240 =高度

or you can just leave width parameter: mogrify -resize 320 *.jpg and rest will be taken care of.

或者你可以留下宽度参数:mogrify -resize 320 * .jpg和休息将被处理。

#3


Various packages exist for command line or script driven manipulation of image files.

存在用于命令行或脚本驱动的图像文件操纵的各种包。

I'd suggest looking at netpbm, or ImageMagick. Personally I prefer the former as it's far simpler to use.

我建议看看netpbm,或ImageMagick。我个人更喜欢前者,因为它使用起来更简单。