linux - 图像缩小脚本在 Linux 中创建更大尺寸的图像

标签 linux bash shell ubuntu wallpaper

我有以下名为 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/

相关文章:

linux - Perl 在远程机器上执行 bash 脚本的错误输出行为

linux - 阻止 MPlayer 在 Awesome WM 中使用 float

linux - BASH If [[ "$a"== *"$b"* ]] 始终为真,即使它不应该为真

string - Bash 脚本 - 检查文件是否包含特定行

linux - 用于安装 AWS CLI 工具的 Bash 脚本

java - 你怎么 'escape'一个用户名:password pair in a connection string?

linux - 如何拦截tcp数据包并在飞行中修改?

linux - getopts命令没有输入时如何回显

linux - Bash 脚本有效但在从 crontab 执行时无效

linux - Linux 命令中参数前的破折号有必要吗?