mirror of
https://git.imnavajas.es/jjimenez/safekat.git
synced 2025-07-25 22:52:08 +00:00
fix download
This commit is contained in:
@ -614,21 +614,24 @@ class PresupuestoAdminEdit {
|
||||
const svgData = serializer.serializeToString(shapeSvgEl);
|
||||
const svgBlob = new Blob([svgData], { type: 'image/svg+xml;charset=utf-8' });
|
||||
const svgUrl = URL.createObjectURL(svgBlob);
|
||||
const img = new Image();
|
||||
const img = new Image(shapeSvgEl.getBoundingClientRect().width,shapeSvgEl.getBoundingClientRect().height);
|
||||
img.onload = () => {
|
||||
const scaleFactor = 3; // Increase resolution (e.g., 2x, 3x)
|
||||
const canvas = document.createElement('canvas');
|
||||
canvas.width = img.width;
|
||||
canvas.height = img.height;
|
||||
// Scale canvas for high resolution
|
||||
const width = img.naturalWidth || img.width;
|
||||
const height = img.naturalHeight || img.height;
|
||||
canvas.width = width * scaleFactor;
|
||||
canvas.height = height * scaleFactor;
|
||||
const ctx = canvas.getContext('2d');
|
||||
ctx.drawImage(img, 0, 0);
|
||||
ctx.scale(scaleFactor, scaleFactor);
|
||||
ctx.drawImage(img, 0,0,width,height);
|
||||
const pngUrl = canvas.toDataURL('image/png');
|
||||
const downloadLink = document.createElement('a');
|
||||
downloadLink.href = pngUrl;
|
||||
downloadLink.download = filename ?? '.png';
|
||||
document.body.appendChild(downloadLink);
|
||||
downloadLink.click();
|
||||
document.body.removeChild(downloadLink);
|
||||
|
||||
URL.revokeObjectURL(svgUrl);
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user