Set background after applying transform

Reset transform in addition to globalAlpha
This commit is contained in:
mike-000
2022-08-08 10:23:01 +01:00
committed by GitHub
parent e6b8fed64a
commit 94caeeab12

View File

@@ -64,13 +64,6 @@ document.getElementById('export-png').addEventListener('click', function () {
const opacity = const opacity =
canvas.parentNode.style.opacity || canvas.style.opacity; canvas.parentNode.style.opacity || canvas.style.opacity;
mapContext.globalAlpha = opacity === '' ? 1 : Number(opacity); mapContext.globalAlpha = opacity === '' ? 1 : Number(opacity);
const backgroundColor = canvas.parentNode.style.backgroundColor;
if (backgroundColor) {
mapContext.fillStyle = backgroundColor;
mapContext.fillRect(0, 0, canvas.width, canvas.height);
}
let matrix; let matrix;
const transform = canvas.style.transform; const transform = canvas.style.transform;
if (transform) { if (transform) {
@@ -94,11 +87,17 @@ document.getElementById('export-png').addEventListener('click', function () {
mapContext, mapContext,
matrix matrix
); );
const backgroundColor = canvas.parentNode.style.backgroundColor;
if (backgroundColor) {
mapContext.fillStyle = backgroundColor;
mapContext.fillRect(0, 0, canvas.width, canvas.height);
}
mapContext.drawImage(canvas, 0, 0); mapContext.drawImage(canvas, 0, 0);
} }
} }
); );
mapContext.globalAlpha = 1; mapContext.globalAlpha = 1;
mapContext.setTransform(1, 0, 0, 1, 0, 0);
const link = document.getElementById('image-download'); const link = document.getElementById('image-download');
link.href = mapCanvas.toDataURL(); link.href = mapCanvas.toDataURL();
link.click(); link.click();