{"id":13991946,"url":"https://github.com/pbakaus/domvas","last_synced_at":"2025-04-07T15:09:02.185Z","repository":{"id":4475283,"uuid":"5614225","full_name":"pbakaus/domvas","owner":"pbakaus","description":"Domvas implements the missing piece that connects the DOM and Canvas.","archived":false,"fork":false,"pushed_at":"2013-07-15T00:58:05.000Z","size":206,"stargazers_count":408,"open_issues_count":10,"forks_count":56,"subscribers_count":26,"default_branch":"master","last_synced_at":"2025-03-31T13:17:57.870Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/pbakaus.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"MIT-LICENSE.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2012-08-30T11:52:25.000Z","updated_at":"2025-03-10T12:14:01.000Z","dependencies_parsed_at":"2022-08-09T15:03:07.194Z","dependency_job_id":null,"html_url":"https://github.com/pbakaus/domvas","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pbakaus%2Fdomvas","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pbakaus%2Fdomvas/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pbakaus%2Fdomvas/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pbakaus%2Fdomvas/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/pbakaus","download_url":"https://codeload.github.com/pbakaus/domvas/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247675597,"owners_count":20977376,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-08-09T14:01:41.557Z","updated_at":"2025-04-07T15:09:02.166Z","avatar_url":"https://github.com/pbakaus.png","language":"JavaScript","funding_links":[],"categories":["JavaScript","13. 页面交互"],"sub_categories":["13.5 图片剪裁/图片处理/图片转换"],"readme":"# Domvas\n\n## Overview\n\n__Domvas implements the missing piece that connects the DOM and Canvas__. It gives to the ability to take arbitrary DOM content and paint it to a Canvas of your choice.\n\n## Usage\n```js\nvar canvas = document.getElementById(\"test\");\nvar context = canvas.getContext('2d');\n\ndomvas.toImage(document.getElementById(\"dom\"), function() {\n    context.drawImage(this, 20, 20);\n});\n```\n\n## Syntax\n```js\ndomvas.toImage(domElement, readyCallback, width, height, left, top);\n```\nreadyCallback's 'this' and first argument points to a valid, preloaded image node that you can simply draw to your canvas context.\n\n## How it works\n\nDomvas uses a feature of SVG that allows you to embed XHTML content into the SVG – and as you might know, the actual SVG can be used as a data uri, and therefore behaves like a standard image.\n\nI have written about this technique in 2008 [when I brought CSS transforms to browsers that did not have them](http://paulbakaus.com/2008/08/19/css-transforms-for-firefox/). It took a little more experimentation to transform it into a reusable plugin: HTML content needs to be serialized to XML, and all styles have to be inlined.\t\n\n## Caveats\n\n- __Internet Explorer is not supported__, as it doesn't support the foreignObject tag in SVG.\n- For whatever reason, Opera is failing. I am not sure why. If a Opera pal is reading this, get in touch!\n- SVG's foreignObject is subject to strong security – meaning any external content will likely fail (i.e. iframes, web fonts)\n- The DOM object is __not linked, but copied__ – if you change the style of the DOM object, it will not automatically update in Canvas\n- Content outside the bounding box of the element will be cut of per default if painted to Canvas. Don't worry though, simply pass a more comfortable offset to the toImage function (see above)\n\n## Credits / License\n\n©2012 Paul Bakaus. Licensed under MIT. Reach out on [Twitter](http://twitter.com/pbakaus)!\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpbakaus%2Fdomvas","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpbakaus%2Fdomvas","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpbakaus%2Fdomvas/lists"}