I have the following script named wallpaperise.sh that takes an image and converts it to the the same own only this time with 16:9 resolution.
## 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
The problem is that the image it creates ( even if it doesn't change the image at all ) is of a bigger file size than the original?
What can I do to fix that?
When converting JPEG with ImageMagick's convert, you can choose your own file size with
-quality 1
(tiny) to-quality 100
(huge).As the flag name suggests, the file size is directly correlated to the image quality.
If you don't specify one, ImageMagick's documentation says it will try to guess the input's quality level, or default to 92 if it can't. In your case, it's conservatively choosing a higher quality setting and resulting in a larger file.
You can try e.g.
-quality 80
, see how it looks, and increase or decrease as you see fit.