-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsprite_export_css.py
51 lines (46 loc) · 1.33 KB
/
sprite_export_css.py
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
#! /usr/bin/env python
from gimpfu import *
import os, string, sys
import os.path
def sprite_export_css(image, drw, path):
css = ''
for layer in image.layers:
x, y = layer.offsets
if x == 0 :
l = '0'
elif image.width == layer.width + x:
l = '100%'# ES IGUAL A RIGHT PERO TIENE UN BY MENOS 4 VS 5
else :
l = "%spx" % (-x)
if y == 0:
t = '0'
else:
t = "%spx" % (-y)
css = css + "." + layer.name + "{\n "
if layer.name.endswith('-back'):
css = css + 'background-repeat: repeat-x;' + "\n "
css = css + "background-position: %s %s;\r" % (l, t)
if l == 'right':
css = css + " background-position: %spx %s;\r" % (-x, t)
css = css + " width: %spx;\n" % (layer.width)
css = css + " height: %spx;\n" % (layer.height)
css = css + "}\n\n"
fullpath = image.name.replace('xcf', 'css')
fullpath = os.path.join(path, fullpath);
file = open(fullpath, 'w')
file.write(css)
file.close()
register(
'sprite_export_css',
'Genera el css necesario para el sprite',
'Genera el css necesario para el sprite',
'Loduis Madariaga',
'Loduis Madariaga',
'2010',
'<Image>/Filters/Web/Sprite/Export css',
'RGBA, RGB',
[(PF_DIRNAME, "path", "Save PNGs here", os.getcwd())],
[],
sprite_export_css
)
main()