我需要一个简单且免费的方法来调整图像大小并进行批量处理(如果有必要)。 免费的图像处理软件比应该更容易使用。
sips -Z 640 *.jpg
Lifehacker解释:
sips
是使用的命令,-Z告诉它保持图像的纵横比。"640"是要使用的最大高度和宽度,"*.jpg"指示您的计算机缩小每个以.jpg结尾的图像。这非常简单且能快速缩小您的图像。如果您想保留它们较大的尺寸,请务必先制作副本。
这里有一个示例,我们保留原始图像并将调整大小后的图像发送到名为resized
的子目录中:
mkdir -p resized && sips -Z 640 *.jpg --out resized/
homebrew install imagemagick
安装了这个。 - Oliver Pearmainconda install -c conda-forge imagemagick
。 - philshem这里有一段脚本,它使用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"
之前的回答是正确的,你也可以使用mogrify。例如,如果你想将一个目录中许多图像的大小减少60%,那么可以使用以下命令:
当然,在执行此命令之前,一定要将图像备份到另一个目录中。
mogrify -resize 60% *
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
magick mogrify -resize 60% *
你需要安装ImageMagick,最简单的方法是使用Homebrew:
brew install imagemagick
brew install imagemagick
magick mogrify -path out -resize 1280x1080\> *
-resize
实现(从官方网站复制),
大小 | 常规描述(实际行为可能因不同选项和设置而有所不同) |
---|---|
scale% | 高度和宽度均按指定百分比缩放。 |
scale-x%xscale-y% | 高度和宽度分别按指定百分比缩放。(只需要一个%符号。) |
width | 指定宽度,自动选择高度以保持纵横比。 |
xheight | 指定高度,自动选择宽度以保持纵横比。 |
widthxheight | 指定高度和宽度的最大值,保持纵横比。 |
widthxheight^ | 指定宽度和高度的最小值,保持纵横比。 |
widthxheight! | 强制指定宽度和高度,忽略原始纵横比。 |
widthxheight> | 缩小具有比相应宽度和/或高度参数更大的尺寸的图像。 |
widthxheight< | 放大具有比相应宽度和/或高度参数更小的尺寸的图像。 |
area@ | 将图像调整为具有指定像素面积。保持纵横比。 |
x:y | 这里的x和y表示一个纵横比(例如3:2 = 1.5)。 |
x:y^ | 删除行或列以实现给定的纵横比。 |
x:y# | 添加行或列以实现给定的纵横比。 |
{size}{offset} | 指定偏移量(默认为+0+0)。下面,{size}是上述任何一种形式。 |
{size}{+-}x{+-}y | 水平和垂直偏移量x和y,以像素为单位指定。正负号对于两者都是必需的。偏移受-gravity设置的影响。偏移不受%或其他大小运算符的影响。请注意,除“中心”外,所有-gravity选项的正X和Y偏移量都朝向图像中心的内部方向。对于东方,+X是左边。对于南方,+Y是上面的。对于东南方,+X是左边和+Y是上面。对于中心,使用正常的X和Y方向约定(+X是右边,+Y是下面)。 |