如何在Mac OSX上使用终端调整图像大小?

Mar*_*cel 58 macos terminal image

如果需要,我需要一种简单而自由的方式来调整图像大小并执行批处理作业.免费的图像处理软件比它应该使用起来更加棘手.

Mar*_*cel 115

正如LifeHacker所指出的,以下命令将非常容易地执行此操作:

sips -Z 640 *.jpg
Run Code Online (Sandbox Code Playgroud)

引用他们的解释:

"那么发生了什么?好吧,"sips"是正在使用的命令,-Z告诉它保持图像的宽高比."640"是要使用的最大高度和宽度,"*.jpg"指示您的计算机缩小尺寸每个以.jpg结尾的图像.它非常简单,可以非常快速地缩小图像.如果你想保留更大的尺寸,请务必先复制一份."

资料来源:http://lifehacker.com/5962420/batch-resize-images-quickly-in-the-os-x-terminal

  • 一个问题是,即使图像小于您指定的尺寸,它仍然会对图像进行重新采样。因此,如果您将所有图像都作为目标,它可能会增加许多图像的文件大小。我希望它会忽略该文件(如果它较小)。 (6认同)
  • add --out参数使其生成而不是直接修改输入文件 (5认同)

L3v*_*han 14

imagemagick帮助:

$ convert foo.jpg -resize 50% bar.jpg
Run Code Online (Sandbox Code Playgroud)

它可以做很多事情,包括格式之间的转换,应用效果,裁剪,着色等等.

  • 获胜者,请注意,我只是使用 `homebrew install imagemagick` 安装了它 (2认同)

小智 9

iTunesconnect 的魔术:)

    mkdir ./iPhone5-5-Portrait
    sips -z 2208 1242 *.jpg -s formatOptions 70 --out ./iPhone5-5-Portrait
    sips -z 2208 1242 *.png --out ./iPhone5-5-Portrait
Run Code Online (Sandbox Code Playgroud)


mip*_*nho 8

另外@grepit 回复

正确的语法是:

magick mogrify -resize 60% *
Run Code Online (Sandbox Code Playgroud)

你需要安装ImageMagick,最简单的方法是使用 homebrew:

brew install imagemagick
Run Code Online (Sandbox Code Playgroud)


Ped*_*pes 5

下面是sips用于递归调整给定文件夹(及其子文件夹)中所有图像的脚本,并将调整大小的图像放在与图像resized相同的树级别的文件夹中:https://gist.github.com/ lopespm/893f323a04fcc59466d7

#!/bin/bash
# This script resizes all the images it finds in a folder (and its subfolders) and resizes them
# The resized image is placed in the /resized folder which will reside in the same directory as the image
#
# Usage: > ./batch_resize.sh

initial_folder="/your/images/folder" # You can use "." to target the folder in which you are running the script for example
resized_folder_name="resized"

all_images=$(find -E $initial_folder -iregex ".*\.(jpg|gif|png|jpeg)")

while read -r image_full_path; do
    filename=$(basename "$image_full_path");
    source_folder=$(dirname "$image_full_path");
    destination_folder=$source_folder"/"$resized_folder_name"/";
    destination_full_path=$destination_folder$filename;

    if [ ! -z "$image_full_path" -a "$image_full_path" != " " ] &&
        # Do not resize images inside a folder that was already resized
        [ "$(basename "$source_folder")" != "$resized_folder_name" ]; then 

        mkdir "$destination_folder";
        sips -Z 700 "$image_full_path" --out "$destination_full_path";

    fi

done <<< "$all_images"
Run Code Online (Sandbox Code Playgroud)

  • 在运行脚本之前,您应该运行“chmod +x batch_resize.sh”以使脚本可执行。我将 700 个图像替换为 400 个图像,并且在不到 3 分钟的时间内调整了文件夹中 3000 个图像的大小。谢谢。 (2认同)

gre*_*pit 5

先前的答案是正确的,您也可以使用mogrify。例如,如果要将目录中许多图像的大小减少60%,则可以使用以下命令:

当然,在使用此命令之前,请务必将图像备份到另一个目录中。

mogrify -resize 60% *
Run Code Online (Sandbox Code Playgroud)