Add JPEG download option

This commit is contained in:
Josh birnholz
2023-04-03 20:08:50 -04:00
parent 6ade07b4bb
commit 96b6495710
2 changed files with 11 additions and 3 deletions

View File

@@ -671,6 +671,7 @@
</div> </div>
<div class='readable-background padding'> <div class='readable-background padding'>
<h3 class='download padding' onclick='downloadCard();'>Download your card</h3> <h3 class='download padding' onclick='downloadCard();'>Download your card</h3>
<h5 onclick='downloadCard(false, true);' id='downloadJpg' href='' target='_blank' class='padding download input-description' style='text-align: left;'>Click here to download as JPEG</h5>
<h5 onclick='downloadCard(true);' id='downloadAlt' href='' target='_blank' class='padding download input-description' style='text-align: left;'>Click here for an alternative download</h5> <h5 onclick='downloadCard(true);' id='downloadAlt' href='' target='_blank' class='padding download input-description' style='text-align: left;'>Click here for an alternative download</h5>
</div> </div>
</div> </div>

View File

@@ -3404,13 +3404,20 @@ function drawCard() {
previewContext.drawImage(cardCanvas, 0, 0, previewCanvas.width, previewCanvas.height); previewContext.drawImage(cardCanvas, 0, 0, previewCanvas.width, previewCanvas.height);
} }
//DOWNLOADING //DOWNLOADING
function downloadCard(alt = false) { function downloadCard(alt = false, jpeg = false) {
if (card.infoArtist.replace(/ /g, '') == '' && !card.artSource.includes('/img/blank.png') && !card.artZoom == 0) { if (card.infoArtist.replace(/ /g, '') == '' && !card.artSource.includes('/img/blank.png') && !card.artZoom == 0) {
notify('You must credit an artist before downloading!', 5); notify('You must credit an artist before downloading!', 5);
} else { } else {
// Prep file information // Prep file information
const imageDataURL = cardCanvas.toDataURL('image/png'); var imageDataURL;
var imageName = getCardName() + '.png'; var imageName = getCardName();
if (jpeg) {
imageDataURL = cardCanvas.toDataURL('image/jpeg', 0.8);
imageName = imageName + '.jpeg';
} else {
imageDataURL = cardCanvas.toDataURL('image/png');
imageName = imageName + '.png';
}
// Download image // Download image
if (alt) { if (alt) {
const newWindow = window.open('about:blank'); const newWindow = window.open('about:blank');