summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 7635f13)
raw | patch | inline | side by side (parent: 7635f13)
author | amphi <amphi@users.sourceforge.net> | |
Tue, 9 Jan 2007 09:24:59 +0000 (09:24 +0000) | ||
committer | amphi <amphi@users.sourceforge.net> | |
Tue, 9 Jan 2007 09:24:59 +0000 (09:24 +0000) |
share/extensions/embedimage.py | patch | blob | history | |
share/extensions/extractimage.py | patch | blob | history |
index 964d1a5ecfbeea57d4e583120710ee34b9c489a5..81380c165d3f532f7e2354c4f97091cea88eabef 100644 (file)
xlink = node.attributes.getNamedItemNS(inkex.NSS[u'xlink'],'href')
if (xlink.value[:4]!='data'):
absref=node.attributes.getNamedItemNS(inkex.NSS[u'sodipodi'],'absref')
- if (os.path.isfile(absref.value)):
- file = open(absref.value,"rb").read()
+ href=node.attributes.getNamedItemNS(inkex.NSS[u'xlink'],'href')
+ svg=self.document.getElementsByTagName('svg')[0]
+ docbase=svg.attributes.getNamedItemNS(inkex.NSS[u'sodipodi'],'docbase')
+
+ path=''
+ #path selection strategy:
+ # 1. absref
+ # 2. href if absolute
+ # 3. sodipodi:docbase + href
+ # 4. realpath-ified href
+ if (absref != None):
+ path=absref.value
+ elif (href != None):
+ if (os.path.isabs(href.value)):
+ path=os.path.realpath(href.value)
+ elif (docbase != None):
+ path=os.path.join(docbase.value,href.value)
+ else:
+ path=os.path.realpath(href.value)
+ else:
+ inkex.debug('No xlink:href or sodipodi:absref attributes found! Unable to embed image.')
+
+ if (os.path.isfile(path)):
+ file = open(path,"rb").read()
embed=True
if (file[:4]=='\x89PNG'):
type='image/png'
elif (file[:6]=='GIF87a' or file[:6]=='GIF89a'):
type='image/gif'
#ico files lack any magic... therefore we check the filename instead
- elif(absref.value.endswith('.ico')):
+ elif(path.endswith('.ico')):
type='image/x-icon' #official IANA registered MIME is 'image/vnd.microsoft.icon' tho
else:
embed=False
xlink.value = 'data:%s;base64,%s' % (type, base64.encodestring(file))
node.removeAttributeNS(inkex.NSS[u'sodipodi'],'absref')
else:
- inkex.debug("%s is not of type image/png, image/jpeg, image/bmp, image/gif or image/x-icon" % absref.value)
+ inkex.debug("%s is not of type image/png, image/jpeg, image/bmp, image/gif or image/x-icon" % path)
else:
- inkex.debug("Sorry we could not locate %s" % absref.value)
+ inkex.debug("Sorry we could not locate %s" % path)
e = MyEffect()
e.affect()
index 5807c9e5b56a0f7947aebda3d824da9345d342fe..f0540ac507f8fc1e35758d0872228f91cde85fd9 100644 (file)
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
'''
-import inkex, base64
+import inkex, base64, os
class MyEffect(inkex.Effect):
def __init__(self):
'icon':'.ico',
'gif' :'.gif'
}
- ctx = inkex.xml.xpath.Context.Context(self.document,processorNss=inkex.NSS)
+ #ctx = inkex.xml.xpath.Context.Context(self.document,processorNss=inkex.NSS)
# exbed the first embedded image
path = self.options.filepath
#save
data = base64.decodestring(xlink.value[comma:])
open(path,'wb').write(data)
- xlink.value = path
+ xlink.value = os.path.realpath(path) #absolute for making in-mem cycles work
else:
inkex.debug('Difficulty finding the image data.')
break