forked from nashcom/notes-dbicons-carbon
-
Notifications
You must be signed in to change notification settings - Fork 0
/
convert_images.sh
47 lines (34 loc) · 961 Bytes
/
convert_images.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#!/bin/bash
if [ -z "$CARBON_ICONS_SVG" ]; then
CARBON_ICONS_SVG=/tmp/carbon-design-system/carbon/tree/main/packages/icons/src/svg/32
fi
if [ -z "$IMAGE_DIR" ]; then
IMAGE_DIR=/tmp/carbon-png
fi
convert_image()
{
local FILE=$(basename "$1" .svg)
local TARGET_DIR=$IMAGE_DIR/$COLOR/$SIZE
local TARGET_FILE=$TARGET_DIR/$FILE.png
echo "Converting $FILE to ${TARGET_FILE}..."
if [ ! -e "$TARGET_DIR" ]; then
mkdir -p "$TARGET_DIR"
fi
if [ -e "$TARGET_FILE" ]; then
return 0
fi
sed "s/viewBox/fill=\"#$COLOR\" viewBox/g" $1 | convert -background transparent -size ${SIZE}x${SIZE} - "$TARGET_FILE" &
}
export -f convert_image
convert_all_images()
{
export COLOR=$1
export SIZE=$2
find "$CARBON_ICONS_SVG" -name "*.svg" -exec bash -c 'convert_image $0' {} \;
}
export IMAGE_DIR
export CARBON_ICONS_SVG
convert_all_images F7F7F7 24
convert_all_images F7F7F7 48
convert_all_images 313131 48
convert_all_images 0066B3 32