CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutSign UpSign In
hrydgard

CoCalc provides the best real-time collaborative environment for Jupyter Notebooks, LaTeX documents, and SageMath, scalable from individual users to large groups and classes!

GitHub Repository: hrydgard/ppsspp
Path: blob/master/icons/convert-to-png.sh
Views: 1401
1
# Copyright (C) 2014 Sergio Benjamim
2
3
# This program is free software; you can redistribute it and/or modify
4
# it under the terms of the GNU General Public License as published by
5
# the Free Software Foundation; either version 2, or (at your option)
6
# any later version.
7
8
# This program is distributed in the hope that it will be useful,
9
# but WITHOUT ANY WARRANTY; without even the implied warranty of
10
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11
# GNU General Public License for more details.
12
13
# You should have received a copy of the GNU General Public License
14
# along with this program; if not, write to the Free Software Foundation,
15
# Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
16
17
# Very simple bash script to convert svg to png files, you can choose inkscape or imagemagick ('convert' command) and the path to icons export.
18
# Only converts icons/icon-512.svg
19
# Needs improvement, yeah, i know, it is not so good... at least it work :)
20
21
22
#!/bin/bash
23
24
# Parameters:
25
# -s, --software inkscape | imagemagick --> "./convert-to-png.sh -s imagemagick" for example
26
# -d, --directory directory path --> "./convert-to-png.sh -d /usr/share/icons/hicolor/" or "./convert-to-png.sh -d ../../debian/ppsspp/usr/share/icons/hicolor/" for example
27
28
# Default options
29
software_option="inkscape" # sometimes imagemagick does not convert very well, so inkscape is default
30
path="icons" # i.e. icons/icons/
31
32
echo -e
33
34
while [ "$1" != "" ]; do
35
case $1 in
36
-s | --software ) shift
37
if [ "$1" == "inkscape" ] || [ "$1" == "imagemagick" ]; then
38
software_option=$1
39
echo -e "Using $1.\n"
40
else
41
software_option="inkscape"
42
echo -e "This parameter does not exist, inkscape or imagemagick are valids parameters. Using Inkscape.\n"
43
fi
44
;;
45
46
-d | --directory ) shift
47
path=$1
48
path=${path%"/"}
49
;;
50
51
* ) echo -e "Error with parameters.\n"
52
exit 1
53
;;
54
esac
55
shift
56
done
57
58
59
# Creating icons/icons/ if user does not choose any directory
60
if [ "$path" == "icons" ] && [ ! -d "$path" ]; then
61
mkdir icons/
62
fi
63
64
65
# Converting svg icons to png:
66
67
# 16 pixel icon use other icon, resize does not fit well for small icons
68
if [ "$software_option" == "inkscape" ]; then
69
if [ "$path" == "icons" ]; then
70
inkscape --export-area-page --file=icon-16.svg --export-png=$path/ppsspp_16.png
71
else
72
inkscape --export-area-page --file=icon-16.svg --export-png=$path/16x16/apps/ppsspp.png
73
fi
74
elif [ "$software_option" == "imagemagick" ]; then
75
if [ "$path" == "icons" ]; then
76
convert icon-16.svg -transparent white $path/ppsspp_16.png
77
else
78
convert icon-16.svg -transparent white $path/16x16/apps/ppsspp.png
79
fi
80
fi
81
82
x="x"
83
84
for size in 24 32 48 64 96 128 256 512
85
do
86
if [ "$software_option" == "inkscape" ]; then
87
if [ "$path" == "icons" ]; then
88
inkscape --export-area-page --export-width=$size --export-height=$size --file=icon-512.svg --export-png=$path/ppsspp_$size.png
89
else
90
inkscape --export-area-page --export-width=$size --export-height=$size --file=icon-512.svg --export-png=$path/$size$x$size/apps/ppsspp.png
91
fi
92
elif [ "$software_option" == "imagemagick" ]; then
93
if [ "$path" == "icons" ]; then
94
convert icon-512.svg -resize $size -transparent white $path/ppsspp_$size.png
95
else
96
convert icon-512.svg -resize $size -transparent white $path/$size$x$size/apps/ppsspp.png
97
fi
98
fi
99
done
100
101
echo -e "\nIcons was exported to $path/ folder.\n"
102
103
104
exit 0
105
106