f1b0f6f7a246f2b1e8a29d1ff468690aa7c92bff
1 #!/usr/bin/env python
2 '''
3 Copyright (C) 2005 Aaron Spike, aaron@ekips.org
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2 of the License, or
8 (at your option) any later version.
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 '''
20 import inkex, base64
22 class MyEffect(inkex.Effect):
23 def __init__(self):
24 inkex.Effect.__init__(self)
25 self.OptionParser.add_option("--filepath",
26 action="store", type="string",
27 dest="filepath", default=None,
28 help="")
29 def effect(self):
30 ctx = inkex.xml.xpath.Context.Context(self.document,processorNss=inkex.NSS)
32 # exbed the first embedded image
33 path = self.options.filepath
34 if (path != ''):
35 if (self.options.ids):
36 for id, node in self.selected.iteritems():
37 if node.tagName == 'image':
38 xlink = node.attributes.getNamedItemNS(inkex.NSS[u'xlink'],'href')
39 if (xlink.value[:4]=='data'):
40 comma = xlink.value.find(',')
41 if comma>0:
42 data = base64.decodestring(xlink.value[comma:])
43 open(path,'wb').write(data)
44 xlink.value = path
45 else:
46 inkex.debug('Difficulty finding the image data.')
47 break
49 e = MyEffect()
50 e.affect()