web-dev-qa-db-ja.com

Mac OSXのターミナルを使用して画像のサイズを変更する方法は?

必要に応じて、画像のサイズを変更してバッチジョブを実行するためのシンプルで無料の方法が必要です。無料の画像操作ソフトウェアは、本来あるべきものよりも使用するのが面倒です。

52
Marcel

LifeHackerが指摘したように、次のコマンドはこれを非常に簡単に行います。

sips -Z 640 *.jpg

彼らの説明を引用するには:

「それで何が起こっているのでしょうか?さて、「sips」は使用されているコマンドであり、-Zは画像のアスペクト比を維持するように指示します。「640」は使用される最大の高さと幅、 .jpgで終わるすべての画像。これは本当にシンプルで、画像を非常に高速に縮小します。より大きなサイズを保持したい場合は、まずコピーを作成してください。」

ソース: http://lifehacker.com/5962420/batch-resize-images-quickly-in-the-os-x-terminal

106
Marcel

imagemagick 役立ちます:

$ convert foo.jpg -resize 50% bar.jpg

フォーマット間の変換、エフェクトの適用、トリミング、色付けなど、さらに多くのことができます。

13
L3viathan

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"
5
Pedro Lopes

以前の回答は正しいですが、mogrifyも使用できます。たとえば、ディレクトリ内の多くの画像のサイズを60%縮小したい場合は、次のコマンドを使用できます。

もちろん、このコマンドで遊ぶ前に、常に別のディレクトリに画像のバックアップを作成してください。

mogrify -resize 60% *
3
grepit

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
3
user3682947