Skip to content

Commit 9ce1016

Browse files
committed
add png to ico converter shell script for multi-size ico files
1 parent 18b7dea commit 9ce1016

File tree

1 file changed

+44
-0
lines changed

1 file changed

+44
-0
lines changed

img/icoconv.sh

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
#!/bin/bash
2+
3+
# icoconv.sh
4+
# Copyright 2016 Christopher Simpkins
5+
# Adapted from shell script by Denilson Sá at https://superuser.com/questions/40623/icons-command-line-generator#40629
6+
# MIT License
7+
8+
# Dependencies:
9+
# 1. imagemagick (http://www.imagemagick.org/)
10+
# 2. icoutils (http://www.nongnu.org/icoutils/)
11+
12+
# Usage: ./icoconv.sh [png filepath]
13+
14+
if [[ -f "$1" ]]; then
15+
SOURCE="$1"
16+
BASE=`basename "${SOURCE}" .png`
17+
else
18+
echo "[iconconv.sh] ERROR: $1 does not appear to be a valid .png file"
19+
fi
20+
21+
# Resize png image to 16x16 through 256x256 for the ico file
22+
convert "${SOURCE}" -thumbnail 16x16 "${BASE}_16.png"
23+
convert "${SOURCE}" -thumbnail 32x32 "${BASE}_32.png"
24+
convert "${SOURCE}" -thumbnail 48x48 "${BASE}_48.png"
25+
convert "${SOURCE}" -thumbnail 64x64 "${BASE}_64.png"
26+
convert "${SOURCE}" -thumbnail 256x256 "${BASE}_256.png"
27+
28+
if [[ $? -eq 0 ]]; then
29+
echo "Image resizes completed successfully."
30+
else
31+
echo "Image resizes failed."
32+
exit 1
33+
fi
34+
35+
# compile all sizes into the ico file
36+
icotool -c -o "${BASE}.ico" "${BASE}"_{16,32,48,64,256}.png
37+
38+
if [[ $? -eq 0 ]]; then
39+
echo "Successful conversion of '$1' to '${BASE}.ico'"
40+
rm -f "${BASE}"_{16,32,48,64,256}.png
41+
else
42+
echo "Conversion to an ico file failed."
43+
exit 1
44+
fi

0 commit comments

Comments
 (0)