Remove debugging lines
Use cf77b3463ba73a3ea702d0b130f829eccf82f91e if required.
This commit is contained in:
parent
cf77b3463b
commit
3e092a4fbb
@ -17,21 +17,18 @@ def embed_svg_images(filename_in: Path, overwrite: bool = True):
|
||||
for xlink in re_xlink.finditer(line):
|
||||
num_images = num_images + 1
|
||||
imgurl = xlink.group('URL')
|
||||
print(' Found URL in SVG:', imgurl)
|
||||
if not imgurl in images_b64:
|
||||
print(' ✅This URL is new')
|
||||
if not Path(imgurl).is_absolute(): # resolve relative image path
|
||||
imgurl_abs = (Path(filename_in).parent / imgurl).resolve()
|
||||
print(imgurl, '-->', imgurl_abs)
|
||||
else:
|
||||
imgurl_abs = imgurl
|
||||
|
||||
with open(imgurl_abs, 'rb') as img:
|
||||
data_bin = img.read()
|
||||
data_b64 = base64.b64encode(data_bin)
|
||||
data_str = data_b64.decode('utf-8')
|
||||
images_b64[imgurl] = data_str
|
||||
else: # only cache every image once
|
||||
print(' ❌This URL is not new')
|
||||
|
||||
line = line.replace(imgurl,
|
||||
f'data:image/png;base64, {images_b64[imgurl]}')
|
||||
file_out.write(line)
|
||||
@ -39,12 +36,3 @@ def embed_svg_images(filename_in: Path, overwrite: bool = True):
|
||||
if overwrite:
|
||||
os.remove(filename_in)
|
||||
os.rename(filename_out, filename_in)
|
||||
|
||||
print(f'Embedded {num_images} instances of {len(images_b64)} different images.')
|
||||
print()
|
||||
|
||||
# for debugging, run:
|
||||
# python -m svgembed.py path/to/file.svg
|
||||
if __name__ == '__main__':
|
||||
import sys
|
||||
embed_svg_images(sys.argv[1])
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user