pyglobalgoals-svg

  • | Src:
  • | Nbviewer:

In [3]:
!pip install svgwrite
# https://svgwrite.readthedocs.org/en/latest/overview.html
import svgwrite

!pip install -e git+https://github.com/scardine/image_size@324affe#egg=image-size
import get_image_size


Requirement already satisfied (use --upgrade to upgrade): svgwrite in /home/wturner/-wrk/-ce27/pyglobalgoals/lib/python2.7/site-packages
Requirement already satisfied (use --upgrade to upgrade): pyparsing>=2.0.1 in /home/wturner/-wrk/-ce27/pyglobalgoals/lib/python2.7/site-packages (from svgwrite)
Obtaining image-size from git+https://github.com/scardine/image_size@324affe#egg=image-size
  Updating ./src/image-size clone (to 324affe)
  Could not find a tag or branch '324affe', assuming commit.
Installing collected packages: image-size
  Running setup.py develop for image-size
Successfully installed image-size

In [ ]:
dwg = svgwrite.Drawing(height=800, width=600)
print(('dwg', dwg))
img = svgwrite.image.Image(href='./data/images/partnership.png')
print(('img', img))
dwg.add(img)
print(('dwg', dwg))
print(('elements', dwg.elements))
for e in dwg.elements:
    print((e, e.tostring()))
print(('dwg_svg', dwg.tostring()))

def prettify_xml(obj):
    return (bs4.BeautifulSoup(dwg.tostring(), features='xml').prettify())
print("")
print(prettify_xml(dwg.tostring()))

In [4]:
import glob
files = glob.glob('./data/images/*.png')
for img_path in files:
    md = get_image_size.get_image_metadata(img_path)
    print((img_path, md.height, md.width)) #, md ))


('./data/images/gg-7renewableenergy-english.png', 377, 377)
('./data/images/no-poverty1.png', 377, 377)
('./data/images/gg-16peaceandjusticestronginstitutions-english_newversion_edited_09.09.15.png', 377, 377)
('./data/images/gg-3goodhealth-english.png', 377, 377)
('./data/images/gg-9innovationandinfrastructure-english.png', 377, 377)
('./data/images/land-life.png', 377, 377)
('./data/images/clean-water.png', 377, 377)
('./data/images/gg-8goodjobseconomicgrowth-english.png', 377, 377)
('./data/images/water-life.png', 377, 377)
('./data/images/gg-12responsibleconsumption-english.png', 377, 377)
('./data/images/gg-2nohunger-english.png', 377, 377)
('./data/images/cities.png', 377, 377)
('./data/images/gender1.png', 377, 377)
('./data/images/reduced-inequality.png', 377, 377)
('./data/images/partnership.png', 377, 377)
('./data/images/education.png', 377, 377)
('./data/images/climate.png', 377, 377)

In [ ]: