WebContextMenus: Fix jpegs being uncopyable
This commit is contained in:
parent
0dee968e98
commit
acc874c34f
1 changed files with 18 additions and 7 deletions
|
@ -179,14 +179,25 @@ export default definePlugin({
|
||||||
],
|
],
|
||||||
|
|
||||||
async copyImage(url: string) {
|
async copyImage(url: string) {
|
||||||
const data = await fetchImage(url);
|
// Clipboard only supports image/png, jpeg and similar won't work. Thus, we need to convert it to png
|
||||||
if (!data) return;
|
// via canvas first
|
||||||
|
const img = new Image();
|
||||||
|
img.onload = () => {
|
||||||
|
const canvas = document.createElement("canvas");
|
||||||
|
canvas.width = img.naturalWidth;
|
||||||
|
canvas.height = img.naturalHeight;
|
||||||
|
canvas.getContext("2d")!.drawImage(img, 0, 0);
|
||||||
|
|
||||||
await navigator.clipboard.write([
|
canvas.toBlob(data => {
|
||||||
|
navigator.clipboard.write([
|
||||||
new ClipboardItem({
|
new ClipboardItem({
|
||||||
[data.type]: data
|
"image/png": data!
|
||||||
})
|
})
|
||||||
]);
|
]);
|
||||||
|
}, "image/png");
|
||||||
|
};
|
||||||
|
img.crossOrigin = "anonymous";
|
||||||
|
img.src = url;
|
||||||
},
|
},
|
||||||
|
|
||||||
async saveImage(url: string) {
|
async saveImage(url: string) {
|
||||||
|
|
Loading…
Reference in a new issue