我有以下名为 wallpaperise.sh 的脚本,它拍摄图像并将其转换为相同的图像,但这次只有 16:9 的分辨率。
## Usage: ./wallpaperise.sh <imagename.jpg>
aw=16 #desired aspect ratio width...
ah=9 #and height
in="$1"
out="wallpaperised_$1"
wid=`convert "$in" -format "%[w]" info:`
hei=`convert "$in" -format "%[h]" info:`
tarar=`echo $aw/$ah | bc -l`
imgar=`convert "$in" -format "%[fx:w/h]" info:`
if (( $(bc <<< "$tarar > $imgar") ))
then
nhei=`echo $wid/$tarar | bc`
convert "$in" -gravity center -crop ${wid}x${nhei}+0+0 "$out"
elif (( $(bc <<< "$tarar < $imgar") ))
then
nwid=`echo $hei*$tarar | bc`
convert "$in" -gravity center -crop ${nwid}x${hei}+0+0 "$out"
else
cp "$in" "$out"
fi
问题是它创建的图像(即使它根本不改变图像)的文件大小比原始文件大吗?
我该怎么做才能解决这个问题?
最佳答案
当使用 ImageMagick 的 convert 转换 JPEG 时,您可以选择自己的文件大小,-quality 1
(小)到 -quality 100
(大)。
顾名思义,文件大小与图像质量直接相关。
如果不指定,ImageMagick's documentation表示它将尝试猜测输入的质量级别,如果不能,则默认为 92。在您的情况下,它会保守地选择更高质量的设置并生成更大的文件。
您可以尝试例如-quality 80
,看看它的外观,并根据需要增加或减少。
关于linux - 图像缩小脚本在 Linux 中创建更大尺寸的图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41497113/