@@ -0,0 +1,2280 @@
+#!/usr/bin/env python3%0A%0A################################################################################%0A# Copyright (C) 2015-2016 by Arena of Titans Contributors.%0A#%0A# This file is part of Arena of Titans.%0A#%0A# Arena of Titans is free software: you can redistribute it and/or modify%0A# it under the terms of the GNU Affero General Public License as published by%0A# the Free Software Foundation, either version 3 of the License, or%0A# (at your option) any later version.%0A#%0A# Arena of Titans is distributed in the hope that it will be useful,%0A# but WITHOUT ANY WARRANTY; without even the implied warranty of%0A# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the%0A# GNU Affero General Public License for more details.%0A#%0A# You should have received a copy of the GNU Affero General Public License%0A# along with Arena of Titans. If not, see %3Chttp://www.gnu.org/licenses/%3E.%0A################################################################################%0A%0A%0Aimport sys%0A%0Afrom base64 import b64decode%0Afrom lxml import etree%0A%0A%0ANS = %7B%0A    'svg': 'http://www.w3.org/2000/svg',%0A    'xlink': 'http://www.w3.org/1999/xlink',%0A%7D%0A%0A%0Adef print_help():%0A    print('./extract-images-svg.py SVG_FILE')%0A    print('This will extract the images included in b64 in the SVG.')%0A%0A%0Adef extract_images_svg(file_name):%0A    with open(file_name) as svg_file:%0A        svg = etree.parse(svg_file)%0A%0A    images = svg.xpath('.//svg:image', namespaces=NS)%0A    for index, img in enumerate(images):%0A        content = img.get('%7Bhttp://www.w3.org/1999/xlink%7Dhref')%0A        if content.startswith('data:image/'):%0A            meta, img_b64 = content.split(';base64,')%0A            _, img_format = meta.split('/')%0A            img_file_name = 'img-%7Bindex%7D.%7Bformat%7D'.format(index=index, format=img_format)%0A            img.set('%7Bhttp://www.w3.org/1999/xlink%7Dhref', img_file_name)%0A            with open(img_file_name, 'wb') as img_file:%0A                img_file.write(b64decode(img_b64))%0A%0A    with open('svg-without-images.svg', 'w') as svg_file:%0A        svg_content = etree.tostring(svg)%5C%0A                .decode('utf-8')%5C%0A                .replace('&gt;', '%3E')%0A        svg_file.write(svg_content)%0A%0A%0Aif __name__ == %22__main__%22:%0A    if len(sys.argv) != 2:%0A        print_help()%0A        sys.exit(0)%0A%0A    extract_images_svg(sys.argv%5B1%5D)%0A

add script to extract images from SVG