首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何在Mac上使用终端调整图像大小?

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

Stack Overflow用户
提问于 2015-02-12 23:22:26
回答 6查看 54.6K关注 0票数 104

我需要一个简单和免费的方式来调整图像大小和做批处理,如果必要的话。自由图像处理软件的使用比它应该使用的要复杂得多。

EN

回答 6

Stack Overflow用户

回答已采纳

发布于 2015-02-12 23:22:26

正如LifeHacker所指出的,下面的命令将非常容易地做到这一点:

代码语言:javascript
复制
sips -Z 640 *.jpg

引用他们的解释:

"sips是正在使用的命令,-Z告诉它保持图像的纵横比。"640“是要使用的最大高度和宽度,"*.jpg”指示计算机缩小以.jpg结尾的每幅图像的大小。它非常简单,而且缩小图像的速度非常快。如果您想要保留它们更大的大小,请务必先复制它们。“

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

票数 237
EN

Stack Overflow用户

发布于 2015-02-12 23:33:42

影象帮助:

代码语言:javascript
复制
$ convert foo.jpg -resize 50% bar.jpg

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

票数 24
EN

Stack Overflow用户

发布于 2015-12-22 18:53:19

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

代码语言:javascript
复制
#!/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"
票数 12
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/28489793

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档