summaryrefslogtreecommitdiff
path: root/tools/apbuild/make-icons
blob: 32c0c600633d0738f4259a69996e9fabbee02033 (plain)
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
48
49
50
51
52
53
54
55
56
57
58
#!/bin/sh

#
# This script generates a directory and an automake fragment from an SVG
# file. It's useful when you have an SVG and want to pre-render icons of
# various sizes from it, then install them into the users icon theme.
#
# For autopackage users, put the following line in your specfile:
#
#   installIcon share/icons/hicolor
#
# It uses rsvg to render the icons

if [[ "$1" == "" ]] || [[ "$2" == "" ]] || [[ "$1" == "--help" ]] || [[ "$1" == "-h" ]]; then
    echo "Usage: make-icons myprogram.svg type"
    echo
    echo "Generates a subdirectory called icons with an icon theme tree"
    echo "in it. Also outputs some automake code you can copy/paste".
    echo ""
    echo "type is the type of icon and should be one of the following:"
    echo "apps, mimetypes, actions, devices, filesystems"
    echo "See FDO spec for details--you most likely want apps or mimetypes"
    exit 0
fi

if ! which rsvg >/dev/null; then
    # a part of librsvg
    echo "make-icons: this script needs the rsvg program installed"
    exit 1
fi

if [ ! -e $1 ]; then
    echo "make-icons: the given file does not exist"
    exit 1
fi

if [[ "$2" != "apps" && "$2" != "mimetypes" && "$2" != "actions" && "$2" != "devices" && "$2" != "filesystems" ]]; then
    echo "make-icons: $2 is not a valid icon type. type should be one of these:"
    echo "apps, mimetypes, actions, devices, filesystems"
    echo "See FDO spec for details--you most likely want apps or mimetypes"
    exit 1
fi
mkdir -p icons/scalable/$2
cp $1 icons/scalable/$2

newname="`basename $1`"
echo "iconSVGdir = \$(datadir)/icons/hicolor/scalable/$2"
echo "iconSVG_DATA = icons/scalable/$2/$newname"

newname="${newname/.svg/}.png"


for size in 128 64 48 24 16; do
    mkdir -p icons/${size}x${size}/$2
    rsvg --width=$size --height=$size $1 icons/${size}x${size}/$2/$newname
    echo "icon${size}dir = \$(datadir)/icons/hicolor/${size}x${size}/$2"
    echo "icon${size}_DATA = icons/${size}x${size}/$2/$newname"
done