diff --git a/src/wireviz/svgembed.py b/src/wireviz/svgembed.py index 0999b8f..f90ba42 100644 --- a/src/wireviz/svgembed.py +++ b/src/wireviz/svgembed.py @@ -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])