Comments (2)
The main difference should be in embedding HTMLImageElement
-
html2canvs by using
img.crossOrigin
https://github.com/niklasvh/html2canvas/blob/v1.4.1/src/core/cache-storage.ts#L96-L99
//ios safari 10.3 taints canvas with data urls unless crossOrigin is set to anonymous if (isInlineBase64Image(src) || useCORS) { img.crossOrigin = 'anonymous'; }
-
html-to-image and modern-screenshot by using
window.fetch
convertimg.src
to the base64 dataURLhttps://github.com/bubkoo/html-to-image/blob/v1.11.11/src/embed-images.ts#L53-L55
const url = isImageElement ? clonedNode.src : clonedNode.href.baseVal const dataURL = await resourceToDataURL(url, getMimeType(url), options)
https://github.com/qq15725/modern-screenshot/blob/v4.2.12/src/embed-image-element.ts#L9-L26
if (isImageElement(clone) && !isDataUrl(clone.currentSrc || clone.src)) { const currentSrc = clone.currentSrc || clone.src clone.srcset = '' clone.dataset.originalSrc = currentSrc return [ fetchDataUrl(currentSrc, context, true).then(url => { clone.src = url }), ] } else if (isSVGElementNode(clone) && !isDataUrl(clone.href.baseVal)) { const currentSrc = clone.href.baseVal clone.dataset.originalSrc = currentSrc return [ fetchDataUrl(currentSrc, context, true).then(url => { clone.href.baseVal = url }), ] }
The embedded dataURI img does not trigger a CORS error when the foreign-object svg is finally rendered to the canvas
References:
https://stackoverflow.com/a/22716873
https://stackoverflow.com/a/20285053
from modern-screenshot.
Wonderful, thank you for the detailed insights
from modern-screenshot.
Related Issues (20)
- Google web fonts not working in Firefox. Getting DOMException: CSSStyleSheet.cssRules error. HOT 1
- Support for `text-stroke` HOT 5
- domToPng 执行过程会阻塞 UI 线程渲染 HOT 1
- scrollbar problem HOT 1
- iled to drawImage DOMException: Failed to execute 'drawImage' on 'CanvasRenderingContext2D': The HTMLImageElement provided is in the 'broken' state. HOT 6
- Fonts are not applied in Safari. HOT 10
- 自定义标签的一般应对方法。 HOT 4
- The rendered image has a text cloning bug. HOT 1
- Grey boxes surrounding all nodes in image
- There are gray boxes inside the picture
- How Screenshot of hidden div using modern-screenshort HOT 5
- Getting blank white image when taking screenshot in Firefox. HOT 6
- 文字渐变不支持 HOT 5
- Default font on Firefox HOT 2
- div style is positiion: fixed;don't get img??
- 生产的图片很模糊,如何调整呢 HOT 1
- How do I manage cors with images? HOT 1
- 在高清屏下图片分辨率太低 HOT 1
- 背景图是 http 资源时,生成图片有概率丢失 HOT 2
- html元素中包含emoji表情时,生成报错 HOT 8
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from modern-screenshot.