{"url":"https://api.github.com/gists/6466603","forks_url":"https://api.github.com/gists/6466603/forks","commits_url":"https://api.github.com/gists/6466603/commits","id":"6466603","node_id":"MDQ6R2lzdDY0NjY2MDM=","git_pull_url":"https://gist.github.com/6466603.git","git_push_url":"https://gist.github.com/6466603.git","html_url":"https://gist.github.com/6466603","files":{".block":{"filename":".block","type":"text/plain","language":null,"raw_url":"https://gist.githubusercontent.com/mbostock/6466603/raw/703d310b399098a243a76a50bc209167e924cfd2/.block","size":17,"truncated":false,"content":"license: gpl-3.0\n"},"README.md":{"filename":"README.md","type":"text/plain","language":"Markdown","raw_url":"https://gist.githubusercontent.com/mbostock/6466603/raw/cebb2e72c4f11d6ab20601c71eb88526e0eedc4a/README.md","size":2096,"truncated":false,"content":"Say you have an SVG built dynamically on the client by [D3](http://d3js.org). Now say you want to save it to a static PNG as a fallback for old browsers. There are lots of ways to do this using alternative renderers (such as [Batik](http://xmlgraphics.apache.org/batik/) and [PhantomJS](http://phantomjs.org/)), but what if you want your browser to do it, so that you the static PNG matches the dynamic SVG exactly, down to the subpixel, including transparency?\n\nHere’s how.\n\n## 1. Save as SVG.\n\nUse the [SVG Crowbar](http://nytimes.github.io/svg-crowbar/) bookmarklet to save the SVG to a file. Call this file “fallback.svg”. Open the SVG in your browser to verify that it looks right.\n\nSVG Crowbar helpfully inlines any stylesheets you may have on the page, but you might find you need to edit a few of the styles by hand to get things to look right. For example, the font-family “sans-serif” won’t work in an SVG image, even though it works when the SVG is built client-side; you’ll have to make the font name explicit, such as “Helvetica” or “Arial”.\n\n## 2. Convert SVG to PNG.\n\nCreate and save the following HTML file as “fallback.html”:\n\n```html\n\n\n\n\n```\n\nNow start a local webserver in the same directory as your fallback.html file. For example:\n\n```bash\npython -m SimpleHTTPServer 8008 &\n```\n\nLastly, visit , and it will automatically download fallback.png! Hooray.\n\nNote: if you are using Chrome or Safari, you’ll need to download [Chrome Canary](https://www.google.com/intl/en/chrome/browser/canary.html) due to this [recently-fixed WebKit bug](https://bugs.webkit.org/show_bug.cgi?id=119492)."}},"public":true,"created_at":"2013-09-06T16:59:13Z","updated_at":"2018-11-23T02:26:25Z","description":"Save SVG as PNG","comments":7,"user":null,"comments_url":"https://api.github.com/gists/6466603/comments","owner":{"login":"mbostock","id":230541,"node_id":"MDQ6VXNlcjIzMDU0MQ==","avatar_url":"https://avatars2.githubusercontent.com/u/230541?v=4","gravatar_id":"","url":"https://api.github.com/users/mbostock","html_url":"https://github.com/mbostock","followers_url":"https://api.github.com/users/mbostock/followers","following_url":"https://api.github.com/users/mbostock/following{/other_user}","gists_url":"https://api.github.com/users/mbostock/gists{/gist_id}","starred_url":"https://api.github.com/users/mbostock/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mbostock/subscriptions","organizations_url":"https://api.github.com/users/mbostock/orgs","repos_url":"https://api.github.com/users/mbostock/repos","events_url":"https://api.github.com/users/mbostock/events{/privacy}","received_events_url":"https://api.github.com/users/mbostock/received_events","type":"User","site_admin":false},"forks":[{"url":"https://api.github.com/gists/27ed5f876ef97e7625c3","user":{"login":"miklobit","id":1035161,"node_id":"MDQ6VXNlcjEwMzUxNjE=","avatar_url":"https://avatars3.githubusercontent.com/u/1035161?v=4","gravatar_id":"","url":"https://api.github.com/users/miklobit","html_url":"https://github.com/miklobit","followers_url":"https://api.github.com/users/miklobit/followers","following_url":"https://api.github.com/users/miklobit/following{/other_user}","gists_url":"https://api.github.com/users/miklobit/gists{/gist_id}","starred_url":"https://api.github.com/users/miklobit/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/miklobit/subscriptions","organizations_url":"https://api.github.com/users/miklobit/orgs","repos_url":"https://api.github.com/users/miklobit/repos","events_url":"https://api.github.com/users/miklobit/events{/privacy}","received_events_url":"https://api.github.com/users/miklobit/received_events","type":"User","site_admin":false},"id":"27ed5f876ef97e7625c3","created_at":"2014-09-23T14:34:44Z","updated_at":"2015-08-29T14:06:49Z"},{"url":"https://api.github.com/gists/4bfb35b057448cc2b735","user":{"login":"y-lan","id":769291,"node_id":"MDQ6VXNlcjc2OTI5MQ==","avatar_url":"https://avatars2.githubusercontent.com/u/769291?v=4","gravatar_id":"","url":"https://api.github.com/users/y-lan","html_url":"https://github.com/y-lan","followers_url":"https://api.github.com/users/y-lan/followers","following_url":"https://api.github.com/users/y-lan/following{/other_user}","gists_url":"https://api.github.com/users/y-lan/gists{/gist_id}","starred_url":"https://api.github.com/users/y-lan/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/y-lan/subscriptions","organizations_url":"https://api.github.com/users/y-lan/orgs","repos_url":"https://api.github.com/users/y-lan/repos","events_url":"https://api.github.com/users/y-lan/events{/privacy}","received_events_url":"https://api.github.com/users/y-lan/received_events","type":"User","site_admin":false},"id":"4bfb35b057448cc2b735","created_at":"2014-10-20T14:17:47Z","updated_at":"2015-08-29T14:07:55Z"},{"url":"https://api.github.com/gists/a984131e4a464ce0de15","user":{"login":"jcanaway","id":4371172,"node_id":"MDQ6VXNlcjQzNzExNzI=","avatar_url":"https://avatars1.githubusercontent.com/u/4371172?v=4","gravatar_id":"","url":"https://api.github.com/users/jcanaway","html_url":"https://github.com/jcanaway","followers_url":"https://api.github.com/users/jcanaway/followers","following_url":"https://api.github.com/users/jcanaway/following{/other_user}","gists_url":"https://api.github.com/users/jcanaway/gists{/gist_id}","starred_url":"https://api.github.com/users/jcanaway/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jcanaway/subscriptions","organizations_url":"https://api.github.com/users/jcanaway/orgs","repos_url":"https://api.github.com/users/jcanaway/repos","events_url":"https://api.github.com/users/jcanaway/events{/privacy}","received_events_url":"https://api.github.com/users/jcanaway/received_events","type":"User","site_admin":false},"id":"a984131e4a464ce0de15","created_at":"2015-04-11T12:16:45Z","updated_at":"2015-08-29T14:18:56Z"},{"url":"https://api.github.com/gists/30ba448a91524108e6a9","user":{"login":"dgilperez","id":264590,"node_id":"MDQ6VXNlcjI2NDU5MA==","avatar_url":"https://avatars1.githubusercontent.com/u/264590?v=4","gravatar_id":"","url":"https://api.github.com/users/dgilperez","html_url":"https://github.com/dgilperez","followers_url":"https://api.github.com/users/dgilperez/followers","following_url":"https://api.github.com/users/dgilperez/following{/other_user}","gists_url":"https://api.github.com/users/dgilperez/gists{/gist_id}","starred_url":"https://api.github.com/users/dgilperez/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/dgilperez/subscriptions","organizations_url":"https://api.github.com/users/dgilperez/orgs","repos_url":"https://api.github.com/users/dgilperez/repos","events_url":"https://api.github.com/users/dgilperez/events{/privacy}","received_events_url":"https://api.github.com/users/dgilperez/received_events","type":"User","site_admin":false},"id":"30ba448a91524108e6a9","created_at":"2015-09-23T00:55:52Z","updated_at":"2015-09-23T00:55:52Z"},{"url":"https://api.github.com/gists/1bf35db8763843bf3ccc","user":{"login":"ningunaparte","id":7590728,"node_id":"MDQ6VXNlcjc1OTA3Mjg=","avatar_url":"https://avatars3.githubusercontent.com/u/7590728?v=4","gravatar_id":"","url":"https://api.github.com/users/ningunaparte","html_url":"https://github.com/ningunaparte","followers_url":"https://api.github.com/users/ningunaparte/followers","following_url":"https://api.github.com/users/ningunaparte/following{/other_user}","gists_url":"https://api.github.com/users/ningunaparte/gists{/gist_id}","starred_url":"https://api.github.com/users/ningunaparte/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ningunaparte/subscriptions","organizations_url":"https://api.github.com/users/ningunaparte/orgs","repos_url":"https://api.github.com/users/ningunaparte/repos","events_url":"https://api.github.com/users/ningunaparte/events{/privacy}","received_events_url":"https://api.github.com/users/ningunaparte/received_events","type":"User","site_admin":false},"id":"1bf35db8763843bf3ccc","created_at":"2015-12-14T12:32:29Z","updated_at":"2015-12-14T12:33:19Z"},{"url":"https://api.github.com/gists/6eaa2ea4b8278ea908b5","user":{"login":"zigi74","id":4866129,"node_id":"MDQ6VXNlcjQ4NjYxMjk=","avatar_url":"https://avatars2.githubusercontent.com/u/4866129?v=4","gravatar_id":"","url":"https://api.github.com/users/zigi74","html_url":"https://github.com/zigi74","followers_url":"https://api.github.com/users/zigi74/followers","following_url":"https://api.github.com/users/zigi74/following{/other_user}","gists_url":"https://api.github.com/users/zigi74/gists{/gist_id}","starred_url":"https://api.github.com/users/zigi74/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/zigi74/subscriptions","organizations_url":"https://api.github.com/users/zigi74/orgs","repos_url":"https://api.github.com/users/zigi74/repos","events_url":"https://api.github.com/users/zigi74/events{/privacy}","received_events_url":"https://api.github.com/users/zigi74/received_events","type":"User","site_admin":false},"id":"6eaa2ea4b8278ea908b5","created_at":"2016-03-24T16:15:29Z","updated_at":"2016-03-24T16:15:30Z"},{"url":"https://api.github.com/gists/f085bdf2115dd15ae0a6bb385bdf8781","user":{"login":"mikecasas","id":11261164,"node_id":"MDQ6VXNlcjExMjYxMTY0","avatar_url":"https://avatars3.githubusercontent.com/u/11261164?v=4","gravatar_id":"","url":"https://api.github.com/users/mikecasas","html_url":"https://github.com/mikecasas","followers_url":"https://api.github.com/users/mikecasas/followers","following_url":"https://api.github.com/users/mikecasas/following{/other_user}","gists_url":"https://api.github.com/users/mikecasas/gists{/gist_id}","starred_url":"https://api.github.com/users/mikecasas/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mikecasas/subscriptions","organizations_url":"https://api.github.com/users/mikecasas/orgs","repos_url":"https://api.github.com/users/mikecasas/repos","events_url":"https://api.github.com/users/mikecasas/events{/privacy}","received_events_url":"https://api.github.com/users/mikecasas/received_events","type":"User","site_admin":false},"id":"f085bdf2115dd15ae0a6bb385bdf8781","created_at":"2016-09-09T12:47:54Z","updated_at":"2016-09-09T12:48:45Z"},{"url":"https://api.github.com/gists/748753808c5460fb6aa5b523c9430e72","user":{"login":"imixtron","id":10543720,"node_id":"MDQ6VXNlcjEwNTQzNzIw","avatar_url":"https://avatars1.githubusercontent.com/u/10543720?v=4","gravatar_id":"","url":"https://api.github.com/users/imixtron","html_url":"https://github.com/imixtron","followers_url":"https://api.github.com/users/imixtron/followers","following_url":"https://api.github.com/users/imixtron/following{/other_user}","gists_url":"https://api.github.com/users/imixtron/gists{/gist_id}","starred_url":"https://api.github.com/users/imixtron/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/imixtron/subscriptions","organizations_url":"https://api.github.com/users/imixtron/orgs","repos_url":"https://api.github.com/users/imixtron/repos","events_url":"https://api.github.com/users/imixtron/events{/privacy}","received_events_url":"https://api.github.com/users/imixtron/received_events","type":"User","site_admin":false},"id":"748753808c5460fb6aa5b523c9430e72","created_at":"2016-12-30T08:30:25Z","updated_at":"2016-12-30T08:30:25Z"},{"url":"https://api.github.com/gists/a778bf2bb4eaef1d8c887aed4d2cafc2","user":{"login":"adongy","id":95287,"node_id":"MDQ6VXNlcjk1Mjg3","avatar_url":"https://avatars1.githubusercontent.com/u/95287?v=4","gravatar_id":"","url":"https://api.github.com/users/adongy","html_url":"https://github.com/adongy","followers_url":"https://api.github.com/users/adongy/followers","following_url":"https://api.github.com/users/adongy/following{/other_user}","gists_url":"https://api.github.com/users/adongy/gists{/gist_id}","starred_url":"https://api.github.com/users/adongy/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/adongy/subscriptions","organizations_url":"https://api.github.com/users/adongy/orgs","repos_url":"https://api.github.com/users/adongy/repos","events_url":"https://api.github.com/users/adongy/events{/privacy}","received_events_url":"https://api.github.com/users/adongy/received_events","type":"User","site_admin":false},"id":"a778bf2bb4eaef1d8c887aed4d2cafc2","created_at":"2017-02-14T16:19:52Z","updated_at":"2017-02-14T16:19:52Z"},{"url":"https://api.github.com/gists/fba20353ea945de12a2f72fc72290c45","user":{"login":"orthodoc","id":302414,"node_id":"MDQ6VXNlcjMwMjQxNA==","avatar_url":"https://avatars3.githubusercontent.com/u/302414?v=4","gravatar_id":"","url":"https://api.github.com/users/orthodoc","html_url":"https://github.com/orthodoc","followers_url":"https://api.github.com/users/orthodoc/followers","following_url":"https://api.github.com/users/orthodoc/following{/other_user}","gists_url":"https://api.github.com/users/orthodoc/gists{/gist_id}","starred_url":"https://api.github.com/users/orthodoc/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/orthodoc/subscriptions","organizations_url":"https://api.github.com/users/orthodoc/orgs","repos_url":"https://api.github.com/users/orthodoc/repos","events_url":"https://api.github.com/users/orthodoc/events{/privacy}","received_events_url":"https://api.github.com/users/orthodoc/received_events","type":"User","site_admin":false},"id":"fba20353ea945de12a2f72fc72290c45","created_at":"2017-04-07T17:19:50Z","updated_at":"2017-04-07T17:19:51Z"},{"url":"https://api.github.com/gists/2c49fe0313c68450469561b8cbe77d4c","user":{"login":"hieusonson9x","id":15144197,"node_id":"MDQ6VXNlcjE1MTQ0MTk3","avatar_url":"https://avatars1.githubusercontent.com/u/15144197?v=4","gravatar_id":"","url":"https://api.github.com/users/hieusonson9x","html_url":"https://github.com/hieusonson9x","followers_url":"https://api.github.com/users/hieusonson9x/followers","following_url":"https://api.github.com/users/hieusonson9x/following{/other_user}","gists_url":"https://api.github.com/users/hieusonson9x/gists{/gist_id}","starred_url":"https://api.github.com/users/hieusonson9x/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/hieusonson9x/subscriptions","organizations_url":"https://api.github.com/users/hieusonson9x/orgs","repos_url":"https://api.github.com/users/hieusonson9x/repos","events_url":"https://api.github.com/users/hieusonson9x/events{/privacy}","received_events_url":"https://api.github.com/users/hieusonson9x/received_events","type":"User","site_admin":false},"id":"2c49fe0313c68450469561b8cbe77d4c","created_at":"2018-03-25T16:30:43Z","updated_at":"2018-03-25T16:30:43Z"},{"url":"https://api.github.com/gists/4e9a18f79f59edb4e5f6a3fd4b48a41e","user":{"login":"myriky","id":581861,"node_id":"MDQ6VXNlcjU4MTg2MQ==","avatar_url":"https://avatars3.githubusercontent.com/u/581861?v=4","gravatar_id":"","url":"https://api.github.com/users/myriky","html_url":"https://github.com/myriky","followers_url":"https://api.github.com/users/myriky/followers","following_url":"https://api.github.com/users/myriky/following{/other_user}","gists_url":"https://api.github.com/users/myriky/gists{/gist_id}","starred_url":"https://api.github.com/users/myriky/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/myriky/subscriptions","organizations_url":"https://api.github.com/users/myriky/orgs","repos_url":"https://api.github.com/users/myriky/repos","events_url":"https://api.github.com/users/myriky/events{/privacy}","received_events_url":"https://api.github.com/users/myriky/received_events","type":"User","site_admin":false},"id":"4e9a18f79f59edb4e5f6a3fd4b48a41e","created_at":"2018-05-10T15:18:50Z","updated_at":"2018-05-10T15:18:51Z"},{"url":"https://api.github.com/gists/0c527172a54e54fba821afb9f26d9e2f","user":{"login":"yswxyz","id":21124044,"node_id":"MDQ6VXNlcjIxMTI0MDQ0","avatar_url":"https://avatars3.githubusercontent.com/u/21124044?v=4","gravatar_id":"","url":"https://api.github.com/users/yswxyz","html_url":"https://github.com/yswxyz","followers_url":"https://api.github.com/users/yswxyz/followers","following_url":"https://api.github.com/users/yswxyz/following{/other_user}","gists_url":"https://api.github.com/users/yswxyz/gists{/gist_id}","starred_url":"https://api.github.com/users/yswxyz/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/yswxyz/subscriptions","organizations_url":"https://api.github.com/users/yswxyz/orgs","repos_url":"https://api.github.com/users/yswxyz/repos","events_url":"https://api.github.com/users/yswxyz/events{/privacy}","received_events_url":"https://api.github.com/users/yswxyz/received_events","type":"User","site_admin":false},"id":"0c527172a54e54fba821afb9f26d9e2f","created_at":"2018-08-15T08:52:46Z","updated_at":"2018-08-15T08:52:47Z"}],"history":[{"user":{"login":"mbostock","id":230541,"node_id":"MDQ6VXNlcjIzMDU0MQ==","avatar_url":"https://avatars2.githubusercontent.com/u/230541?v=4","gravatar_id":"","url":"https://api.github.com/users/mbostock","html_url":"https://github.com/mbostock","followers_url":"https://api.github.com/users/mbostock/followers","following_url":"https://api.github.com/users/mbostock/following{/other_user}","gists_url":"https://api.github.com/users/mbostock/gists{/gist_id}","starred_url":"https://api.github.com/users/mbostock/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mbostock/subscriptions","organizations_url":"https://api.github.com/users/mbostock/orgs","repos_url":"https://api.github.com/users/mbostock/repos","events_url":"https://api.github.com/users/mbostock/events{/privacy}","received_events_url":"https://api.github.com/users/mbostock/received_events","type":"User","site_admin":false},"version":"6f83c2c53c7633fd469a175bbb0acdc2c76a090e","committed_at":"2016-02-09T02:01:26Z","change_status":{"total":1,"additions":1,"deletions":0},"url":"https://api.github.com/gists/6466603/6f83c2c53c7633fd469a175bbb0acdc2c76a090e"},{"user":{"login":"mbostock","id":230541,"node_id":"MDQ6VXNlcjIzMDU0MQ==","avatar_url":"https://avatars2.githubusercontent.com/u/230541?v=4","gravatar_id":"","url":"https://api.github.com/users/mbostock","html_url":"https://github.com/mbostock","followers_url":"https://api.github.com/users/mbostock/followers","following_url":"https://api.github.com/users/mbostock/following{/other_user}","gists_url":"https://api.github.com/users/mbostock/gists{/gist_id}","starred_url":"https://api.github.com/users/mbostock/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mbostock/subscriptions","organizations_url":"https://api.github.com/users/mbostock/orgs","repos_url":"https://api.github.com/users/mbostock/repos","events_url":"https://api.github.com/users/mbostock/events{/privacy}","received_events_url":"https://api.github.com/users/mbostock/received_events","type":"User","site_admin":false},"version":"4ab38c2cc97dbee4b090ecb411c0d72b08402af7","committed_at":"2013-09-06T17:01:09Z","change_status":{"total":2,"additions":1,"deletions":1},"url":"https://api.github.com/gists/6466603/4ab38c2cc97dbee4b090ecb411c0d72b08402af7"},{"user":{"login":"mbostock","id":230541,"node_id":"MDQ6VXNlcjIzMDU0MQ==","avatar_url":"https://avatars2.githubusercontent.com/u/230541?v=4","gravatar_id":"","url":"https://api.github.com/users/mbostock","html_url":"https://github.com/mbostock","followers_url":"https://api.github.com/users/mbostock/followers","following_url":"https://api.github.com/users/mbostock/following{/other_user}","gists_url":"https://api.github.com/users/mbostock/gists{/gist_id}","starred_url":"https://api.github.com/users/mbostock/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mbostock/subscriptions","organizations_url":"https://api.github.com/users/mbostock/orgs","repos_url":"https://api.github.com/users/mbostock/repos","events_url":"https://api.github.com/users/mbostock/events{/privacy}","received_events_url":"https://api.github.com/users/mbostock/received_events","type":"User","site_admin":false},"version":"71a8c906d3f736cd9a3ae1e118525f2d973faeb3","committed_at":"2013-09-06T17:00:05Z","change_status":{"total":3,"additions":2,"deletions":1},"url":"https://api.github.com/gists/6466603/71a8c906d3f736cd9a3ae1e118525f2d973faeb3"},{"user":{"login":"mbostock","id":230541,"node_id":"MDQ6VXNlcjIzMDU0MQ==","avatar_url":"https://avatars2.githubusercontent.com/u/230541?v=4","gravatar_id":"","url":"https://api.github.com/users/mbostock","html_url":"https://github.com/mbostock","followers_url":"https://api.github.com/users/mbostock/followers","following_url":"https://api.github.com/users/mbostock/following{/other_user}","gists_url":"https://api.github.com/users/mbostock/gists{/gist_id}","starred_url":"https://api.github.com/users/mbostock/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mbostock/subscriptions","organizations_url":"https://api.github.com/users/mbostock/orgs","repos_url":"https://api.github.com/users/mbostock/repos","events_url":"https://api.github.com/users/mbostock/events{/privacy}","received_events_url":"https://api.github.com/users/mbostock/received_events","type":"User","site_admin":false},"version":"ebe67b42d29c443624c8147e14857f4a91148e09","committed_at":"2013-09-06T16:59:13Z","change_status":{"total":45,"additions":45,"deletions":0},"url":"https://api.github.com/gists/6466603/ebe67b42d29c443624c8147e14857f4a91148e09"}],"truncated":false}