File: svg2png.bash

package info (click to toggle)
comixcursors 0.6.1-4
  • links: PTS
  • area: main
  • in suites: squeeze
  • size: 880 kB
  • ctags: 35
  • sloc: sh: 567; makefile: 87
file content (162 lines) | stat: -rwxr-xr-x 4,241 bytes parent folder | download
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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
#!/bin/bash
##########################################################
# svg2png.bash                                           #
# 2006 Jens Luetkens <j.luetkens@limitland.de>           #
# version: ComixCursors 0.5.0                            #
#          flatbedcursors 0.1 (compatible)               #
#                                                        #
# take a simple svg file, export it to an image,         #
# do some image magig, generate a shadow, scale          #
# and merge it to a single image                         #
#                                                        #
# Required tools:                                        #
# ImageMagick : http://www.imagemagick.org               #
# Inkscape    : http://www.inkscape.org                  #
#                                                        #
##########################################################

if [ $# -lt 1 ]; then
  echo ""
  echo "Usage: $0 <in name> {options}"
  echo ""
  echo "Options:"
  echo "    -PART <part>              animated cursors part#"
  echo "    -BACKGROUND <name>        background image name"
  echo "    -SHADOW <name>            shadow image name"
  echo "    -TIME <milliseconds>      background image name"
  echo ""
  exit -1
fi

# don't do transparency post-processing by default
# used for ComixCursors but not for flatbedcursors
CURSORTRANS=0

# read config file .sh syntax)
source CONFIG

# some initialisation before argument processing
PART=0
FIXPART=""

# parse argument list
NAME=$1
SHADOW=$NAME

# parse argument list
while [ "$1" != "" ]; do
	case $1 in
		-PART  )	shift
					PART=$1
					;;
		-BACKGROUND  )	shift
					BACKGROUND=$1
					;;
		-SHADOW  )	shift
					SHADOW=$1
					;;
		-TIME  )	shift
					TIME=$1
					;;
	esac
	shift
done

TMPSIZE=`echo " $SIZE * $TMPSCALE" | bc`

XMOVE=`echo "$XOFFSET * $TMPSCALE" | bc`
YMOVE=`echo "$YOFFSET * $TMPSCALE" | bc`

SCALEBLUR=`echo "$BLUR * $TMPSCALE" | bc`
SCALESIZE=`echo "$SIZE * $TMPSCALE" | bc`
CROP=`echo "($SCALESIZE - $TMPSIZE) / 2" | bc`

# scaling the shadow from a 500x500 px image
RIGHT=`echo "500 / $SHADOWSCALE" | bc`
LEFT=`echo "500 - $RIGHT" | bc`

if [ ! -d tmp ]; then mkdir tmp ; fi
if [ ! -d shadows ]; then mkdir shadows ; fi

if [ $PART -lt 1 ]; then
	echo "processing $NAME..."
else
	echo "processing $NAME part $PART..."
	FIXPART=$PART
	SUBPATH=$NAME/
fi

# write the hotspot config file
if [ $BACKGROUND ] ; then 
  HOTSPOT=(`grep "^$BACKGROUND" HOTSPOTS`)
else 
  HOTSPOT=(`grep "^$NAME" HOTSPOTS`)
fi
	
HOTX=`echo "${HOTSPOT[1]} * $SIZE / 500" | bc`
HOTY=`echo "${HOTSPOT[2]} * $SIZE / 500" | bc`
	
if [ $PART -lt 2 ]; then
  if [ -e build/$SUBPATH$NAME.conf ]; then
    rm build/$SUBPATH$NAME.conf
  fi
fi 
if [ $PART -gt 0 ]; then
  echo "$SIZE $HOTX $HOTY build/$SUBPATH$NAME$PART.png $TIME" >> build/$SUBPATH$NAME.conf
else
  echo "$SIZE $HOTX $HOTY build/$NAME.png" >> build/$NAME.conf
fi

INFILE=tmp/tmp.svg
OUTFILE=build/$SUBPATH$NAME$FIXPART.png
SHADOWIMAGE=shadows/$SHADOW-$SIZE-$SHADOWCOLOR-$SHADOWTRANS.png
CURSORIMAGE=tmp/cursor.png
SCALEDIMAGE=tmp/scaledcursor.png

# compose the image
inkscape -e $CURSORIMAGE \
   -w $TMPSIZE \
   -h $TMPSIZE \
   -b $OUTLINECOLOR \
   -y 0 \
   -d 72 \
   $INFILE >> /dev/null

if [ ! -f $SHADOWIMAGE ]; then
  # echo "creating shadow image $SHADOWIMAGE..."
  # scaling the shadow must be done with exporting a different area from inkscape...
  inkscape -e $SCALEDIMAGE \
     -a $LEFT:$LEFT:$RIGHT:$RIGHT \
     -w $TMPSIZE \
     -h $TMPSIZE \
     -b $OUTLINECOLOR \
     -y 0 \
     -d 72 \
   $INFILE >> /dev/null
  
  convert -modulate 0 \
     -fill "$SHADOWCOLOR" \
     -colorize 100 \
     -channel Alpha \
     -fx \'a-$SHADOWTRANS\' \
     $SCALEDIMAGE $SHADOWIMAGE

  mogrify -channel Alpha \
     -blur $SCALEBLUR\x$SCALEBLUR \
     -resize 50% \
     $SHADOWIMAGE

  mogrify -roll +$XMOVE+$YMOVE \
     $SHADOWIMAGE
fi

if [ `echo "$CURSORTRANS > 0" | bc` -gt 0 ]; then
   # echo "applying cursor transparency: $CURSORTRANS ..."
   convert -channel Alpha -fx \'a-$CURSORTRANS\' $CURSORIMAGE $CURSORIMAGE
fi

composite -geometry $SIZEx$SIZE $CURSORIMAGE $SHADOWIMAGE $OUTFILE

if [ $BACKGROUND ]; then
   composite $OUTFILE build/$BACKGROUND.png $OUTFILE
fi