Skip to content

Commit

Permalink
update fallback solution
Browse files Browse the repository at this point in the history
  • Loading branch information
lyqht committed Jan 5, 2024
1 parent e39c513 commit 829599c
Showing 1 changed file with 10 additions and 12 deletions.
22 changes: 10 additions & 12 deletions src/utils/convertToImage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,24 +44,22 @@ export async function copyImageToClipboard(element: HTMLElement, options: Option
)
} else {
// Fallback for browsers that don't support ClipboardItem
const reader = new FileReader()
reader.readAsDataURL(blob)
reader.onloadend = () => {
const base64data = reader.result as string
navigator.clipboard.writeText(base64data).then(
() => {
console.log('Copied base64 image to clipboard')
},
(error) => {
console.error('Error copying base64 image to clipboard:', error)
}
)
const canvas = document.createElement('canvas')
const ctx = canvas.getContext('2d')
const img = new Image()
img.onload = () => {
canvas.width = img.width
canvas.height = img.height
ctx!.drawImage(img, 0, 0)
browser.clipboard.setImageData(ctx!.getImageData(0, 0, img.width, img.height))
}
img.src = URL.createObjectURL(blob)
}
})
}



export function downloadPngElement(element: HTMLElement, filename: string, options: Options) {
const formattedOptions = getFormattedOptions(element, options)
domtoimage.toPng(element, formattedOptions).then((dataUrl: string) => {
Expand Down

0 comments on commit 829599c

Please sign in to comment.