How to Get the Real (Unscaled) Size of an Embedded Image in the Svg Document!

Embed SVG in SVG?

Use the image element and reference your SVG file. For fun, save the following as recursion.svg:

<svg width="100%" height="100%" viewBox="-100 -100 200 200" version="1.1"
xmlns="http://www.w3.org/2000/svg">
<circle cx="-50" cy="-50" r="30" style="fill:red" />
<image x="10" y="20" width="80" height="80" href="recursion.svg" />
</svg>

Can the Django dev server correctly serve SVG?

I don't have Django available to test this at the moment but it looks like the static server uses the mimetypes library to determine the content type (specifically guess_type()).

With a little bit a Googling, I came across some code that you could probably throw in your settings.py to add support for the svg content type:

import mimetypes

mimetypes.add_type("image/svg+xml", ".svg", True)
mimetypes.add_type("image/svg+xml", ".svgz", True)

There's also this blog post specific to Pylons but it mentions a similar issue. He specifies that the MIME types are stored in "/etc/mime.types" and that SVG is missing because it's not an official MIME type. He may be right, since I can't find a MIME-type for SVG anywhere on the IANA.

filling space in svg width path

I suspect the script is the problem. The last data point in the plot is at

L 1314.6117266886256 77.66199637121403

before the the graph dives down screen to

L 1366 1535.7468222475618

and back to

L 0, 1535.7468222475618

so the fill will work. Currently the plummet in the plot is clipped by the view port so it looks like it's vertical and as if the graph cuts off at x = 1314, whereas it doesn't and continues to x=1366. This can be demonstrated by changing the view port height to several thousand and removing the height attribute on the svg tag.

Why the script doesn't plot a data point at 1366 is unclear - I would expect the distance represented by points[points.length-1].distance would be the same as totalDistance. Perhaps some judicious logging will clear up the matter.

Note that use of the unscaled rangeHeight value (unrelated to svg dimensions) can be replaced by svgHeight when completing path data as for example:

return {
track: track = track + layout.width + ' ' + svgHeight + ' L 0 ' + svgHeight
}


Related Topics



Leave a reply



Submit