fix resource saving for uploaded resources

Signed-off-by: Victor Seiji Hariki <victorseijih@gmail.com>
This commit is contained in:
Victor Seiji Hariki 2022-12-03 13:08:29 -03:00
parent eea14e1cc9
commit 249e83ed07

View file

@ -99,11 +99,20 @@ const stampTool = () =>
JSON.stringify(
state.resources
.filter((resource) => !resource.temporary)
.map((resource) => ({
id: resource.id,
name: resource.name,
src: resource.image.src,
}))
.map((resource) => {
const canvas = document.createElement("canvas");
canvas.width = resource.image.width;
canvas.height = resource.image.height;
const ctx = canvas.getContext("2d");
ctx.drawImage(resource.image, 0, 0);
return {
id: resource.id,
name: resource.name,
src: canvas.toDataURL(),
};
})
)
);
} catch (e) {
@ -350,7 +359,7 @@ const stampTool = () =>
const image = document.createElement("img");
image.src = url.createObjectURL(file);
state.addResource(file.name, image, false);
image.onload = () => state.addResource(file.name, image, false);
}
});