我想基于源图像制作大量图像!
显然,我可以在Adobe Photoshop中手动执行此操作......这需要花费大量的手动时间。
你是对的。让计算机轻松重复工作; 这就是他们擅长的。正如Tom Ruh的回答所说,你可以使用ImageMagick
它。
但是,有一个问题:
幸运的是,图像分辨率为4:3,适用于所有具有相同高度和宽度的分辨率,即80x80px 100x100px等。
(强调我的)
目前尚不清楚你想要什么样的分辨率 - 如前所述的4:3,或暗示的1:1。
然而,根据您的要求最小73px和最大1000个像素和分辨率的hundereds ; 我写了一个小脚本,它应该涵盖大多数可能性(包括你想要的机会调整大小)可以通过改变一些变量来设置。
脚本,也可以从pastebin这里获得,以便于复制:
#!/bin/bash
# resizer.sh - resize target image between two resolutions
# accepts file as either first argument or by setting FILEPATH variable
# SETTINGS
SMALLEST_WIDTH=73 # px
LARGEST_WIDTH=1000 # px
FILEPATH= # set if you don't want to pass in image as argument
NUM_OF_RESOLUTIONS=100 # number of images generated; will generate between
# $SMALLEST_WIDTH and $LARGEST_WIDTH
RATIO= # set if you want to specify width/height
# (eg 1/1, 4/3, 16/9), blank is preserve current ratio
# NOTE: resizing to other aspect ratios may be slow/distorty:
# as per http://www.imagemagick.org/Usage/resize/#noaspect
# Seamless resizing (default) may be preferred, see:
# http://www.imagemagick.org/Usage/resize/#liquid-rescale
# but note it is slower, particularly as images get larger
LIQUID=0
# SCRIPT BELOW
# silent by default; uncomment "printf" lines for a description of what is happening
die() { printf "$@\n" 1>&2 ; exit 1; }
if [ -z "$FILEPATH" ]; then
if [ -z "$1" ]; then die "Need to supply file to work on either as argument or by setting FILEPATH!";
else FILE="$1";
fi
else
FILE="$FILEPATH"
fi
# check file exists and is regular file
if [ ! -e "$FILE" ]; then die "$FILE does not exist!"; fi
if [ ! -f "$FILE" ]; then die "$FILE is not a regular file!"; fi
i=0
step=$(echo "($LARGEST_WIDTH - $SMALLEST_WIDTH) / ($NUM_OF_RESOLUTIONS - 1)" | bc -l)
#printf "Resolution step is: %s\n-------------" "$step"
while [ $i -lt $NUM_OF_RESOLUTIONS ]; do
# handle ratio
WIDTH=$(echo "$SMALLEST_WIDTH+($step*$i)" | bc -l)
if [ -z "$RATIO" ]; then
#printf "convert %s -resize %s %s\n" "$FILE" "$WIDTH" "${FILE%.*}-${WIDTH%.*}px.${FILE##*.}"
convert "$FILE" -resize "$WIDTH" "${FILE%.*}-${WIDTH%.*}px.${FILE##*.}"
else
HEIGHT=$(echo "$WIDTH * $RATIO" | bc -l)
if [ "$LIQUID" -eq 0 ]; then
# Uncomment convert line for distorted ("squashed") resizing
#printf "convert %s -resize %sx%s\! %s\n" "$FILE" "$WIDTH" "$HEIGHT" "${FILE%.*}-${WIDTH%.*}px.${FILE##*.}"
convert "$FILE" -resize "$WIDTH"x"$HEIGHT"\! "${FILE%.*}-${WIDTH%.*}px.${FILE##*.}"
else
# Liquid resizing: http://www.imagemagick.org/Usage/resize/#liquid-rescale
# fast aspect ration resize first, then liquid
#printf "convert %s -resize %s %s\n" "$FILE" "$WIDTH" "${FILE%.*}-${WIDTH%.*}px.${FILE##*.}"
convert "$FILE" -resize "$WIDTH" "${FILE%.*}-${WIDTH%.*}px.${FILE##*.}"
#printf "%s details are now:\n %s\n" "${FILE%.*}-${WIDTH%.*}px.${FILE##*.}" "$(identify "${FILE%.*}-${WIDTH%.*}px.${FILE##*.}")"
#printf "convert %s -liquid-rescale %sx%s\! %s\n" "${FILE%.*}-${WIDTH%.*}px.${FILE##*.}" "$WIDTH" "$HEIGHT" "${FILE%.*}-${WIDTH%.*}px.${FILE##*.}"
convert "${FILE%.*}-${WIDTH%.*}px.${FILE##*.}" -liquid-rescale "$WIDTH"x"$HEIGHT"\! "${FILE%.*}-${WIDTH%.*}px.${FILE##*.}"
fi
fi
(( i++ ))
done
注意:在计算值等的子壳上有点过分,但嘿嘿。如上所述,printf
可以取消注释这些行以了解正在发生的事情,否则默认情况下它将根据静默规则默默运行。有些图像的尺寸不会与计算的尺寸完全一致(例如193px vs 138.54545454545454545452px),因为您无法以有用的方式获得分数像素。