mirror of
https://git.imnavajas.es/jjimenez/safekat.git
synced 2025-07-25 22:52:08 +00:00
fix preview download
This commit is contained in:
@ -379,27 +379,29 @@ class Resumen {
|
|||||||
let parentDiv = $(event.currentTarget).parent().parent();
|
let parentDiv = $(event.currentTarget).parent().parent();
|
||||||
let shapeSvgElQuery = $(parentDiv).find("svg");
|
let shapeSvgElQuery = $(parentDiv).find("svg");
|
||||||
let shapeSvgEl = shapeSvgElQuery[0];
|
let shapeSvgEl = shapeSvgElQuery[0];
|
||||||
console.log(shapeSvgEl)
|
|
||||||
const filename = shapeSvgElQuery.parent().attr("id") ?? "image"
|
const filename = shapeSvgElQuery.parent().attr("id") ?? "image"
|
||||||
const serializer = new XMLSerializer();
|
const serializer = new XMLSerializer();
|
||||||
const svgData = serializer.serializeToString(shapeSvgEl);
|
const svgData = serializer.serializeToString(shapeSvgEl);
|
||||||
const svgBlob = new Blob([svgData], { type: 'image/svg+xml;charset=utf-8' });
|
const svgBlob = new Blob([svgData], { type: 'image/svg+xml;charset=utf-8' });
|
||||||
const svgUrl = URL.createObjectURL(svgBlob);
|
const svgUrl = URL.createObjectURL(svgBlob);
|
||||||
const img = new Image();
|
const img = new Image(shapeSvgEl.getBoundingClientRect().width,shapeSvgEl.getBoundingClientRect().height);
|
||||||
img.onload = () => {
|
img.onload = () => {
|
||||||
|
const scaleFactor = 3; // Increase resolution (e.g., 2x, 3x)
|
||||||
const canvas = document.createElement('canvas');
|
const canvas = document.createElement('canvas');
|
||||||
canvas.width = img.width;
|
// Scale canvas for high resolution
|
||||||
canvas.height = img.height;
|
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');
|
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 pngUrl = canvas.toDataURL('image/png');
|
||||||
const downloadLink = document.createElement('a');
|
const downloadLink = document.createElement('a');
|
||||||
downloadLink.href = pngUrl;
|
downloadLink.href = pngUrl;
|
||||||
downloadLink.download = filename ?? '.png';
|
downloadLink.download = filename ?? '.png';
|
||||||
document.body.appendChild(downloadLink);
|
document.body.appendChild(downloadLink);
|
||||||
downloadLink.click();
|
downloadLink.click();
|
||||||
document.body.removeChild(downloadLink);
|
|
||||||
|
|
||||||
URL.revokeObjectURL(svgUrl);
|
URL.revokeObjectURL(svgUrl);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user