# Can't download PNG or SVG of

**URL:** <https://talk.observablehq.com/t/cant-download-png-or-svg-of/4942>\
**Category:** Help\
**Created:** [April 18, 2021, 10:27pm UTC](https://talk.observablehq.com/t/cant-download-png-or-svg-of/4942 "2021-04-18T22:27:51Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![mcmcclur](https://yyz2.discourse-cdn.com/flex030/user_avatar/talk.observablehq.com/mcmcclur/32/2364_2.png) [@mcmcclur](https://talk.observablehq.com/u/mcmcclur)\
**Post date:** [April 18, 2021, 10:27pm UTC](https://talk.observablehq.com/t/cant-download-png-or-svg-of/4942/1 "2021-04-18T22:27:51Z")

</div>

I’ve got some fun GraphViz generated graphs labeled with MathJaX below. For some reason, I don’t have the option to download SVG or PNG images and I’m wondering if that’s a bug?

https://observablehq.com/embed/@mcmcclur/d3-graphviz-with-mathjax?cells=topmatter%2Cviewof+example%2Cviewof+engine%2Cviewof+texit%2Cgraph%2Ccomment%2Cseir_graph

---

<div class="post-metadata">

**Author:** ![severo](https://yyz2.discourse-cdn.com/flex030/user_avatar/talk.observablehq.com/severo/32/786_2.png) [@severo](https://talk.observablehq.com/u/severo)\
**Post date:** [April 19, 2021, 6:27am UTC](https://talk.observablehq.com/t/cant-download-png-or-svg-of/4942/2 "2021-04-19T06:27:36Z")

</div>

I think it’s because of the wrapper div. If the cell is an SVG or a canvas, instead of a div, you should have the option to download the image.

---

<div class="post-metadata">

**Author:** ![mcmcclur](https://yyz2.discourse-cdn.com/flex030/user_avatar/talk.observablehq.com/mcmcclur/32/2364_2.png) [@mcmcclur](https://talk.observablehq.com/u/mcmcclur)\
**Post date:** [April 19, 2021, 9:29am UTC](https://talk.observablehq.com/t/cant-download-png-or-svg-of/4942/3 "2021-04-19T09:29:56Z")

</div>

> [@severo](#):
>
> I think it’s because of the wrapper div.

I think you’re on to something - thanks!

It seems a bit more complicated than just that, because I’ve built plenty of images that place either a Canvas or an SVG into a DIV but have still been able to download the images. For example, [here’s the graph of a function](https://observablehq.com/@mcmcclur/plotting-a-javascript-function-with-functionplot) that’s built that way.

What I have noticed, though, is that nesting or stacking Canvases and SVGs within a DIV seems to confuse the download buttons. For example, [this n-body simulator](https://observablehq.com/@mcmcclur/gravitation-and-the-n-body-problem) places an SVG (which draws moving bodies( on top of a Canvas (which draws paths of growing complexity). There are download buttons but you only get the bodies.

In the case at hand, the image consists of a DIV with an SVG that contains nested SVGs. Perhaps that extra level of complexity is the problem because, I find the same problem in the second image [in this notebook](https://observablehq.com/@mcmcclur/svg-and-mathjax-3#download_problem).

---

<div class="post-metadata">

**Author:** ![mootari](https://yyz2.discourse-cdn.com/flex030/user_avatar/talk.observablehq.com/mootari/32/581_2.png) [@mootari](https://talk.observablehq.com/u/mootari)\
**Post date:** [April 19, 2021, 7:11pm UTC](https://talk.observablehq.com/t/cant-download-png-or-svg-of/4942/4 "2021-04-19T19:11:11Z")

</div>

Observable’s rules for SVG detection are:

- top level element is instance of `SVGSVGElement` _OR_
- top level element contains exactly one `svg` element (at any level) _AND_
  - svg fills at least 75% of top level element’s width _OR_
  - svg fills at least 75% of top level element’s height

Equivalent conditions apply to canvas detection.

~~Graphviz plots fail these tests because they nest `svg` elements.~~ _See next answer._

@mbostock I think Observable’s detection could be improved by not counting SVG that are nested inside other SVGs.

---

<div class="post-metadata">

**Author:** ![mcmcclur](https://yyz2.discourse-cdn.com/flex030/user_avatar/talk.observablehq.com/mcmcclur/32/2364_2.png) [@mcmcclur](https://talk.observablehq.com/u/mcmcclur)\
**Post date:** [April 19, 2021, 9:00pm UTC](https://talk.observablehq.com/t/cant-download-png-or-svg-of/4942/5 "2021-04-19T21:00:44Z")

</div>

> [@mootari](#):
>
> Graphviz plots fail these tests because they nest `svg` elements.

Not quite. You can download SVGs of [Mike’s original Graphviz graphs](https://observablehq.com/@observablehq/graphviz), for example. The problem is the way that I introduce typeset math into an SVG, which explicitly nests SVG (for the typeset stuff) into a larger SVG. If I return the larger SVG, then no problem. If I place the whole thing inside a DIV, then there’s an issue.

Thanks!
