Skip to content

Commit

Permalink
Image尚未加载导致不显示
Browse files Browse the repository at this point in the history
  • Loading branch information
hzsrc committed Jan 21, 2025
1 parent 705e6aa commit e43e2e6
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 2 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "html-to-image-big",
"version": "1.11.13",
"version": "1.11.15",
"description": "Generates an image from a DOM node using HTML5 canvas and SVG. Support big html page.",
"main": "lib/index.js",
"module": "es/index.js",
Expand Down
2 changes: 1 addition & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ async function prepareNode(node: HTMLElement, options: Options = {}) {
if (!('usePageCss' in options)) options.usePageCss = true
const clonedNode = (await cloneNode(node, options, true)) as HTMLElement
// svg中的图片地址无法离线下载,需要先转成dataUrl
setImgDataUrl(clonedNode)
await setImgDataUrl(clonedNode)
return clonedNode
}

Expand Down
1 change: 1 addition & 0 deletions src/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -323,6 +323,7 @@ export function setImgDataUrl(el: Element) {
const imgs = el.querySelectorAll('img')
return Promise.all(
[].slice.call(imgs, 0).map((img: HTMLImageElement) => {
if (/^data:/.test(img.src)) return Promise.resolve()
return urlToDataUrl(img.src).then((dataUrl) => (img.src = dataUrl))
}),
)
Expand Down

0 comments on commit e43e2e6

Please sign in to comment.