add xlink fix in laser_check
This commit is contained in:
parent
f9c2be0270
commit
66ed980951
@ -13,6 +13,7 @@ from collections import Counter
|
||||
from PIL import Image
|
||||
from io import BytesIO
|
||||
import base64
|
||||
import urllib.request as urllib
|
||||
|
||||
class LaserCheck(inkex.EffectExtension):
|
||||
|
||||
@ -36,6 +37,30 @@ class LaserCheck(inkex.EffectExtension):
|
||||
- output time/cost estimations per stroke color
|
||||
'''
|
||||
|
||||
def checkImagePath(self, node):
|
||||
"""Embed the data of the selected Image Tag element"""
|
||||
xlink = node.get('xlink:href')
|
||||
if xlink and xlink[:5] == 'data:':
|
||||
# No need, data alread embedded
|
||||
return
|
||||
|
||||
url = urllib.urlparse(xlink)
|
||||
href = urllib.url2pathname(url.path)
|
||||
|
||||
# Primary location always the filename itself.
|
||||
path = self.absolute_href(href or '')
|
||||
|
||||
# Backup directory where we can find the image
|
||||
if not os.path.isfile(path):
|
||||
path = node.get('sodipodi:absref', path)
|
||||
|
||||
if not os.path.isfile(path):
|
||||
inkex.errormsg('File not found "{}". Unable to embed image.').format(path)
|
||||
return
|
||||
|
||||
if (os.path.isfile(path)):
|
||||
return path
|
||||
|
||||
def add_arguments(self, pars):
|
||||
pars.add_argument('--tab')
|
||||
|
||||
@ -482,10 +507,13 @@ class LaserCheck(inkex.EffectExtension):
|
||||
malformedScales = []
|
||||
maxDPIhits = []
|
||||
minDPIhits = []
|
||||
|
||||
for image in images:
|
||||
inkex.utils.debug("image id={}".format(image.get('id')))
|
||||
|
||||
image_string = image.get('{http://www.w3.org/1999/xlink}href')
|
||||
self.path = self.checkImagePath(image) # This also ensures the file exists
|
||||
if self.path is None: # check if image is embedded or linked
|
||||
image_string = node.get('{http://www.w3.org/1999/xlink}href')
|
||||
# find comma position
|
||||
i = 0
|
||||
while i < 40:
|
||||
@ -493,6 +521,10 @@ class LaserCheck(inkex.EffectExtension):
|
||||
break
|
||||
i = i + 1
|
||||
img = Image.open(BytesIO(base64.b64decode(image_string[i + 1:len(image_string)])))
|
||||
else:
|
||||
img = Image.open(self.path)
|
||||
|
||||
if img:
|
||||
img_w = img.getbbox()[2]
|
||||
img_h = img.getbbox()[3]
|
||||
if image.get('width') is None:
|
||||
|
Loading…
Reference in New Issue
Block a user