【问题标题】:Image downsizing script creates image of bigger size in linux图像缩小脚本在linux中创建更大尺寸的图像
【发布时间】:2017-01-06 00:31:21
【问题描述】:

我有一个名为 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

问题在于它创建的图像(即使它根本没有改变图像)的文件大小比原始文件大?

我能做些什么来解决这个问题?

【问题讨论】:

    标签: linux bash shell ubuntu wallpaper


    【解决方案1】:

    使用 ImageMagick 的 convert 转换 JPEG 时,您可以选择自己的文件大小,将 -quality 1(小)到 -quality 100(大)。

    顾名思义,文件大小与图像质量直接相关。

    如果你不指定一个,ImageMagick's documentation 说它会尝试猜测输入的质量级别,如果不能,则默认为 92。在您的情况下,它保守地选择更高质量的设置并导致文件更大。

    你可以试试-quality 80,看看它的外观,并根据需要增加或减少。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2010-10-15
      • 1970-01-01
      • 2018-07-17
      • 2014-12-04
      • 1970-01-01
      • 2012-04-20
      • 1970-01-01
      • 2012-09-07
      相关资源
      最近更新 更多