fix: fix copy as png feature (#1143)

This commit is contained in:
Karol Stawowski 2023-02-10 14:42:25 +01:00 committed by GitHub
parent 3d1d329b6f
commit b6dacdc1cd
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -1139,10 +1139,6 @@ export class TLDR {
const svgString = TLDR.getSvgString(svg, scale)
const width = +svg.getAttribute('width')!
const height = +svg.getAttribute('height')!
const svgSrc = svg.lastElementChild!.getAttribute('xlink:href')!
if (!svgString) return
const canvas = await new Promise<HTMLCanvasElement>((resolve) => {
@ -1158,10 +1154,12 @@ export class TLDR {
const canvas = document.createElement('canvas') as HTMLCanvasElement
const context = canvas.getContext('2d')!
canvas.width = width
canvas.height = height
const imageWidth = image.width
const imageHeight = image.height
context.drawImage(image, 0, 0, width, height)
canvas.width = imageWidth
canvas.height = imageHeight
context.drawImage(image, 0, 0, imageWidth, imageHeight)
URL.revokeObjectURL(dataUrl)
@ -1172,7 +1170,7 @@ export class TLDR {
console.warn('Could not convert that SVG to an image.')
}
image.src = svgSrc.includes('data:') ? dataUrl : svgSrc
image.src = dataUrl
})
const blob = await new Promise<Blob>((resolve) =>