Add image upload functionality to card creator and draw uploaded art
This commit is contained in:
parent
8ae6d2cb38
commit
7d7cd1bb46
2 changed files with 20 additions and 1 deletions
Binary file not shown.
Before Width: | Height: | Size: 56 KiB After Width: | Height: | Size: 56 KiB |
|
@ -70,6 +70,8 @@ const flavorInput = document.getElementById("flavorInput");
|
||||||
const artistInput = document.getElementById("artistInput");
|
const artistInput = document.getElementById("artistInput");
|
||||||
|
|
||||||
const downloadBtn = document.getElementById("downloadBtn");
|
const downloadBtn = document.getElementById("downloadBtn");
|
||||||
|
const uploadArt = document.getElementById("uploadArt");
|
||||||
|
let uploadedImage = null;
|
||||||
|
|
||||||
// Generate a unique ID for the card based on pack and card name
|
// Generate a unique ID for the card based on pack and card name
|
||||||
async function generateCardId(...args) {
|
async function generateCardId(...args) {
|
||||||
|
@ -93,10 +95,28 @@ frameImage.onload = () => {
|
||||||
drawCard();
|
drawCard();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
uploadArt.addEventListener("change", function(e) {
|
||||||
|
const file = e.target.files[0];
|
||||||
|
if (!file) return;
|
||||||
|
const reader = new FileReader();
|
||||||
|
reader.onload = function(event) {
|
||||||
|
uploadedImage = new Image();
|
||||||
|
uploadedImage.onload = drawCard;
|
||||||
|
uploadedImage.src = event.target.result;
|
||||||
|
};
|
||||||
|
reader.readAsDataURL(file);
|
||||||
|
});
|
||||||
|
|
||||||
function drawCard() {
|
function drawCard() {
|
||||||
ctx.clearRect(0, 0, canvas.width, canvas.height);
|
ctx.clearRect(0, 0, canvas.width, canvas.height);
|
||||||
ctx.fillStyle = "#f5f5f5";
|
ctx.fillStyle = "#f5f5f5";
|
||||||
ctx.fillRect(0, 0, canvas.width, canvas.height);
|
ctx.fillRect(0, 0, canvas.width, canvas.height);
|
||||||
|
|
||||||
|
// Draw uploaded art as background if present
|
||||||
|
if (uploadedImage) {
|
||||||
|
ctx.drawImage(uploadedImage, 0, 0, canvas.width, canvas.height);
|
||||||
|
}
|
||||||
|
|
||||||
ctx.drawImage(frameImage, 0, 0, canvas.width, canvas.height);
|
ctx.drawImage(frameImage, 0, 0, canvas.width, canvas.height);
|
||||||
|
|
||||||
// Name & pack
|
// Name & pack
|
||||||
|
@ -170,6 +190,5 @@ downloadBtn.addEventListener("click", () => {
|
||||||
link.href = canvas.toDataURL("image/png");
|
link.href = canvas.toDataURL("image/png");
|
||||||
link.click();
|
link.click();
|
||||||
});
|
});
|
||||||
|
|
||||||
</script>
|
</script>
|
||||||
{% endblock %}
|
{% endblock %}
|
Loading…
Add table
Reference in a new issue