Different output from converting SVG file provided via StringIO and filename

The MagickWand interface is a new high-level C API interface to ImageMagick core methods. We discourage the use of the core methods and encourage the use of this API instead. Post MagickWand questions, bug reports, and suggestions to this forum.
Post Reply
dcunhas
Posts: 1
Joined: 2016-06-17T10:38:50-07:00
Authentication code: 1151

Different output from converting SVG file provided via StringIO and filename

Post by dcunhas » 2016-06-17T10:42:11-07:00

I was doing some conversions to figure out the Python Wand API and I noticed that when I provide the same SVG string two different ways, I get two different images.
My code is:

Code: Select all

from wand.image import Image
import StringIO
import os


print os.environ['MAGICK_HOME']

svg = '<?xml version="1.0" encoding="UTF-8" standalone="no"?><!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd"><svg version="1.1" id="Layer_1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px" xml:space="preserve" height="241"  width="386"><g xmlns="http://www.w3.org/2000/svg" fill="none" stroke="none" stroke-width="none" stroke-linecap="butt" stroke-linejoin="miter" stroke-miterlimit="10" stroke-dasharray="" stroke-dashoffset="0" font-family="sans-serif" font-weight="normal" font-size="12" text-anchor="start" mix-blend-mode="normal"><path d="M165.2135,102.5625c0,-8.99478 7.29171,-16.2865 16.2865,-16.2865c8.99478,0 16.2865,7.29171 16.2865,16.2865c0,8.99478 -7.29171,16.2865 -16.2865,16.2865c-8.99478,0 -16.2865,-7.29171 -16.2865,-16.2865z" fill="#808080" stroke="#ffff00" stroke-width="3" opacity="0.3"/></g></svg>'

st = StringIO.StringIO(svg)
st.seek(0)

with Image(filename='C:/Users/Sandeep/temp/test.svg', format='svg') as img:
    img.format='png'
    img.save(filename="C:/Users/Sandeep/temp/s.png")

with Image(file=st, format='svg') as img:
    img.format='png'
    img.save(filename="C:/Users/Sandeep/temp/t.png")
    
s.png and t.png (the two output files) show different images. Furthermore, they have different file sizes (s.png is 2.54 KB and t.png is 3.12 KB). I verified that the file contents are the same as the contents of the string above, so any idea what's going on? I originally posted this on the Wand's Github page but was referred here.
Thanks

Post Reply