Skip to content

Commit f2fe2a6

Browse files
committed
images: added --lowres & --widthlow options
--lowres is for (re)generate only the low resolution version of an image. --widthlow is to set a custom width for the low resolution version
1 parent b9f876d commit f2fe2a6

File tree

1 file changed

+25
-2
lines changed

1 file changed

+25
-2
lines changed

img-compress.sh

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,8 @@ else
4444
:
4545
fi
4646

47-
OPTIONS=ilpDd:
48-
LONGOPTIONS=identify,log,preserve,density,dpi:
47+
OPTIONS=ilpDd:Lw:
48+
LONGOPTIONS=identify,log,preserve,density,dpi:,lowres,widthlow:
4949

5050
PARSED=$(getopt --options=$OPTIONS --longoptions=$LONGOPTIONS --name "$0" -- "$@")
5151

@@ -102,6 +102,23 @@ while true; do
102102
fi
103103
shift 2
104104
;;
105+
-L|--lowres)
106+
lowresOnly=y
107+
shift
108+
;;
109+
-w|--widthlow)
110+
if [ "$2" -eq "$2" ] 2>/dev/null
111+
then
112+
# set a different resolution for low-res images
113+
lowwidth="$2"
114+
# set a very high parameter, since it will be managed by the width
115+
lowheight=1200
116+
else
117+
echo "ERROR: --widthlow must be an integer."
118+
exit 1
119+
fi
120+
shift 2
121+
;;
105122
--)
106123
shift
107124
break
@@ -260,6 +277,12 @@ else # we have a parameter: convert only specified file
260277
echo "${image}: setting density to $DENSITY"
261278
convert -units PixelsPerInch ${image} -density $DENSITY ${image}
262279
fi
280+
elif [ $lowresOnly ]; then
281+
# generate only low-res version
282+
if [ "${image}" != "${image%.${EXTJPG}}" ]; then
283+
convert ${image} -resize ${lowwidth}x${lowheight}\> ${image%.${EXTJPG}}.low.jpg
284+
echo "generated low-res version for ${image} with width: $lowwidth"
285+
fi
263286
else
264287
identifyimage
265288
backupimage

0 commit comments

Comments
 (0)