Skip to content

Commit

Permalink
Add option to download uncropped pic in debug mode
Browse files Browse the repository at this point in the history
  • Loading branch information
typingbeaver committed Dec 8, 2023
1 parent e3f66ad commit 97839b6
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 5 deletions.
4 changes: 4 additions & 0 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,10 @@
class="bg-amber-400 px-4 py-2 text-sm font-medium text-gray-900 shadow-sm hover:font-bold focus:outline-none focus:ring-2 focus:ring-gray-900 focus:ring-offset-2">
Save as PNG Image
</button>
<button id="downloadPageIMG" hidden
class="border-amber-400 border-4 text-amber-400 px-4 py-2 text-sm font-medium shadow-sm hover:font-bold focus:outline-none focus:ring-2 focus:ring-gray-900 focus:ring-offset-2">
Save uncropped PNG Image
</button>
</div>
</div>
</main>
Expand Down
19 changes: 14 additions & 5 deletions src/js/crop.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,20 @@ import 'pdfjs-dist/build/pdf.worker.entry';
import { saveAs } from 'file-saver';

const debug = false;
// debug && readFile();
debug && (downloadPageIMG.hidden = false);
console.log('Application loaded. debug =', debug);

const viewImg = document.getElementById('view');
let label,
labelArrayBuffer;
var labelData = {
image: new Image(),
};

convertLabel.addEventListener('click', readFile, false);
downloadLabel.addEventListener('click', saveLabel, false);
downloadLabelIMG.addEventListener('click', savePNG, false);
downloadPageIMG.addEventListener('click', savePagePNG, false);

function savePNG() {
saveAs(
Expand All @@ -24,6 +28,15 @@ function savePNG() {
);
}

function savePagePNG() {
labelData.canvas.toBlob((blob) => {
saveAs(
blob,
document.getElementById('file-input').files[0].name.replace(/(.pdf|.gif)/g,'') + '.png'
);
});
}

async function saveLabel() {
const pdfBytes = await generatePDF();
saveAs(
Expand Down Expand Up @@ -71,10 +84,6 @@ function readFile() {
}

reader.onload = async (e) => {
var labelData = {
image: new Image(),
};

switch(label.file.type) {
case 'pdf':
// read PDF
Expand Down

0 comments on commit 97839b6

Please sign in to comment.