function copyImage (imageid) {
const img = document.getElementById(imageid);
const canvas = document.createElement('canvas');
const context = canvas.getContext('2d');
fetch(img.src, { mode: 'cors' })
.then((response) => response.blob())
.then((blob) => {
const url = URL.createObjectURL(blob);
const img = new Image();
img.crossOrigin = 'anonymous';
img.onload = () => {
canvas.width = img.width;
canvas.height = img.height;
context.drawImage(img, 0, 0);
canvas.toBlob((blob) => {
const item = new ClipboardItem({ 'image/png': blob });
navigator.clipboard.write([item]).then(() => {
hideShowToast('Image copied to clipboard');
}).catch((error) => {
hideShowToast('Could not copy image to clipboard', 1);
});
}, 'image/png');
};
img.src = url;
})
.catch((error) => {
hideShowToast('Could not copy image to clipboard', 1);
});
}