Spaces:
Running
Running
Promote version 4a5eddd to main
Browse filesPromoted commit 4a5eddd862cbbbc2cd96e8c2318c0bd5af578841 to main branch
- index.html +8 -21
- script.js +31 -108
- style.css +1 -4
index.html
CHANGED
|
@@ -35,6 +35,7 @@
|
|
| 35 |
</button>
|
| 36 |
</div>
|
| 37 |
</div>
|
|
|
|
| 38 |
<div class="mt-6">
|
| 39 |
<label for="page-count" class="block text-sm font-medium text-gray-700 mb-2">Number of A4 Pages</label>
|
| 40 |
<div class="flex items-center gap-4">
|
|
@@ -44,13 +45,6 @@
|
|
| 44 |
</div>
|
| 45 |
|
| 46 |
<div class="mt-6">
|
| 47 |
-
<label for="overlap" class="block text-sm font-medium text-gray-700 mb-2">Overlap between pages (mm)</label>
|
| 48 |
-
<div class="flex items-center gap-4">
|
| 49 |
-
<input type="range" id="overlap" min="0" max="20" value="5" class="w-full">
|
| 50 |
-
<span id="overlap-value" class="font-medium text-gray-800">5mm</span>
|
| 51 |
-
</div>
|
| 52 |
-
</div>
|
| 53 |
-
<div class="mt-6">
|
| 54 |
<label for="orientation" class="block text-sm font-medium text-gray-700 mb-2">Orientation</label>
|
| 55 |
<div class="flex gap-4">
|
| 56 |
<button id="portrait" class="orientation-btn active bg-indigo-100 text-indigo-700 px-4 py-2 rounded-lg">
|
|
@@ -86,17 +80,11 @@
|
|
| 86 |
<div id="result-section" class="hidden">
|
| 87 |
<div class="flex justify-between items-center mb-4">
|
| 88 |
<h2 class="text-2xl font-bold text-gray-800">Your Poster Pages</h2>
|
| 89 |
-
<
|
| 90 |
-
<
|
| 91 |
-
|
| 92 |
-
|
| 93 |
-
|
| 94 |
-
<button id="download-pdf" class="flex items-center gap-2 bg-green-600 text-white px-4 py-2 rounded-lg hover:bg-green-700 transition">
|
| 95 |
-
<i data-feather="file-text"></i>
|
| 96 |
-
PDF for Print
|
| 97 |
-
</button>
|
| 98 |
-
</div>
|
| 99 |
-
</div>
|
| 100 |
|
| 101 |
<div id="poster-pages" class="grid grid-cols-1 sm:grid-cols-2 md:grid-cols-3 lg:grid-cols-4 gap-4">
|
| 102 |
<!-- Generated pages will appear here -->
|
|
@@ -120,11 +108,10 @@
|
|
| 120 |
</main>
|
| 121 |
|
| 122 |
<custom-footer></custom-footer>
|
|
|
|
| 123 |
<script src="script.js"></script>
|
| 124 |
<script>
|
| 125 |
-
|
| 126 |
-
feather.replace();
|
| 127 |
-
});
|
| 128 |
</script>
|
| 129 |
<script src="https://huggingface.co/deepsite/deepsite-badge.js"></script>
|
| 130 |
</body>
|
|
|
|
| 35 |
</button>
|
| 36 |
</div>
|
| 37 |
</div>
|
| 38 |
+
|
| 39 |
<div class="mt-6">
|
| 40 |
<label for="page-count" class="block text-sm font-medium text-gray-700 mb-2">Number of A4 Pages</label>
|
| 41 |
<div class="flex items-center gap-4">
|
|
|
|
| 45 |
</div>
|
| 46 |
|
| 47 |
<div class="mt-6">
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 48 |
<label for="orientation" class="block text-sm font-medium text-gray-700 mb-2">Orientation</label>
|
| 49 |
<div class="flex gap-4">
|
| 50 |
<button id="portrait" class="orientation-btn active bg-indigo-100 text-indigo-700 px-4 py-2 rounded-lg">
|
|
|
|
| 80 |
<div id="result-section" class="hidden">
|
| 81 |
<div class="flex justify-between items-center mb-4">
|
| 82 |
<h2 class="text-2xl font-bold text-gray-800">Your Poster Pages</h2>
|
| 83 |
+
<button id="download-all" class="flex items-center gap-2 bg-indigo-600 text-white px-4 py-2 rounded-lg hover:bg-indigo-700 transition">
|
| 84 |
+
<i data-feather="download"></i>
|
| 85 |
+
Download All
|
| 86 |
+
</button>
|
| 87 |
+
</div>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 88 |
|
| 89 |
<div id="poster-pages" class="grid grid-cols-1 sm:grid-cols-2 md:grid-cols-3 lg:grid-cols-4 gap-4">
|
| 90 |
<!-- Generated pages will appear here -->
|
|
|
|
| 108 |
</main>
|
| 109 |
|
| 110 |
<custom-footer></custom-footer>
|
| 111 |
+
|
| 112 |
<script src="script.js"></script>
|
| 113 |
<script>
|
| 114 |
+
feather.replace();
|
|
|
|
|
|
|
| 115 |
</script>
|
| 116 |
<script src="https://huggingface.co/deepsite/deepsite-badge.js"></script>
|
| 117 |
</body>
|
script.js
CHANGED
|
@@ -1,15 +1,5 @@
|
|
| 1 |
-
|
| 2 |
-
// Load jsPDF library
|
| 3 |
-
const script = document.createElement('script');
|
| 4 |
-
script.src = 'https://cdnjs.cloudflare.com/ajax/libs/jspdf/2.5.1/jspdf.umd.min.js';
|
| 5 |
-
script.onload = function() {
|
| 6 |
-
window.jspdf = window.jspdf.jsPDF;
|
| 7 |
-
document.dispatchEvent(new Event('jspdfLoaded'));
|
| 8 |
-
};
|
| 9 |
-
document.head.appendChild(script);
|
| 10 |
-
|
| 11 |
document.addEventListener('DOMContentLoaded', function() {
|
| 12 |
-
// DOM elements
|
| 13 |
const fileInput = document.getElementById('file-input');
|
| 14 |
const uploadBtn = document.getElementById('upload-btn');
|
| 15 |
const dropZone = document.getElementById('drop-zone');
|
|
@@ -25,66 +15,33 @@ document.addEventListener('DOMContentLoaded', function() {
|
|
| 25 |
const resultSection = document.getElementById('result-section');
|
| 26 |
const posterPages = document.getElementById('poster-pages');
|
| 27 |
const downloadAllBtn = document.getElementById('download-all');
|
| 28 |
-
const downloadPdfBtn = document.getElementById('download-pdf');
|
| 29 |
-
const overlapInput = document.getElementById('overlap');
|
| 30 |
-
const overlapValue = document.getElementById('overlap-value');
|
| 31 |
|
| 32 |
// Current image and settings
|
| 33 |
-
let currentImage = null;
|
| 34 |
let currentOrientation = 'portrait';
|
| 35 |
let currentPageCount = 4;
|
| 36 |
-
let currentOverlap = 5; // in mm
|
| 37 |
-
// Event listeners
|
| 38 |
-
// Set up event listeners properly
|
| 39 |
-
if (uploadBtn && fileInput) {
|
| 40 |
-
uploadBtn.addEventListener('click', (e) => {
|
| 41 |
-
e.preventDefault();
|
| 42 |
-
fileInput.click();
|
| 43 |
-
});
|
| 44 |
-
}
|
| 45 |
|
| 46 |
-
|
| 47 |
-
|
| 48 |
-
|
| 49 |
-
|
| 50 |
-
|
| 51 |
-
|
| 52 |
-
|
| 53 |
-
|
| 54 |
-
handleDragOver(e);
|
| 55 |
-
});
|
| 56 |
-
dropZone.addEventListener('dragleave', (e) => {
|
| 57 |
-
e.preventDefault();
|
| 58 |
-
handleDragLeave(e);
|
| 59 |
-
});
|
| 60 |
-
dropZone.addEventListener('drop', (e) => {
|
| 61 |
-
e.preventDefault();
|
| 62 |
-
handleDrop(e);
|
| 63 |
-
});
|
| 64 |
-
}
|
| 65 |
-
pageCountInput.addEventListener('input', updatePageCount);
|
| 66 |
-
overlapInput.addEventListener('input', updateOverlap);
|
| 67 |
-
portraitBtn.addEventListener('click', () => setOrientation('portrait'));
|
| 68 |
landscapeBtn.addEventListener('click', () => setOrientation('landscape'));
|
| 69 |
generateBtn.addEventListener('click', generatePosterPages);
|
| 70 |
downloadAllBtn.addEventListener('click', downloadAllPages);
|
| 71 |
-
downloadPdfBtn.addEventListener('click', generatePDF);
|
| 72 |
|
| 73 |
// Update page count display
|
| 74 |
-
function updatePageCount() {
|
| 75 |
currentPageCount = parseInt(pageCountInput.value);
|
| 76 |
pageCountValue.textContent = currentPageCount;
|
| 77 |
}
|
| 78 |
|
| 79 |
// Set orientation
|
| 80 |
-
// Update overlap value
|
| 81 |
-
function updateOverlap() {
|
| 82 |
-
currentOverlap = parseInt(overlapInput.value);
|
| 83 |
-
overlapValue.textContent = `${currentOverlap}mm`;
|
| 84 |
-
}
|
| 85 |
-
|
| 86 |
function setOrientation(orientation) {
|
| 87 |
-
currentOrientation = orientation;
|
| 88 |
if (orientation === 'portrait') {
|
| 89 |
portraitBtn.classList.add('active', 'bg-indigo-100', 'text-indigo-700');
|
| 90 |
portraitBtn.classList.remove('border', 'border-gray-300');
|
|
@@ -108,53 +65,44 @@ currentOrientation = orientation;
|
|
| 108 |
|
| 109 |
// Handle drag over
|
| 110 |
function handleDragOver(e) {
|
|
|
|
| 111 |
e.stopPropagation();
|
| 112 |
dropZone.classList.add('highlight');
|
| 113 |
}
|
| 114 |
|
| 115 |
// Handle drag leave
|
| 116 |
function handleDragLeave(e) {
|
|
|
|
| 117 |
e.stopPropagation();
|
| 118 |
dropZone.classList.remove('highlight');
|
| 119 |
}
|
|
|
|
| 120 |
// Handle drop
|
| 121 |
function handleDrop(e) {
|
|
|
|
| 122 |
e.stopPropagation();
|
| 123 |
dropZone.classList.remove('highlight');
|
| 124 |
|
| 125 |
-
const
|
| 126 |
-
const file = dt.files[0];
|
| 127 |
-
|
| 128 |
if (file && file.type.match('image.*')) {
|
| 129 |
processImageFile(file);
|
| 130 |
-
} else {
|
| 131 |
-
alert('Please drop an image file only');
|
| 132 |
}
|
| 133 |
}
|
| 134 |
-
// Process image file
|
| 135 |
-
function processImageFile(file) {
|
| 136 |
-
if (!file.type.match('image.*')) {
|
| 137 |
-
alert('Please select an image file (JPEG, PNG, etc.)');
|
| 138 |
-
return;
|
| 139 |
-
}
|
| 140 |
|
|
|
|
|
|
|
| 141 |
const reader = new FileReader();
|
| 142 |
reader.onload = function(e) {
|
| 143 |
currentImage = new Image();
|
| 144 |
currentImage.onload = function() {
|
| 145 |
showPreview();
|
| 146 |
};
|
| 147 |
-
currentImage.onerror = function() {
|
| 148 |
-
alert('Error loading image');
|
| 149 |
-
};
|
| 150 |
currentImage.src = e.target.result;
|
| 151 |
};
|
| 152 |
-
reader.onerror = function() {
|
| 153 |
-
alert('Error reading file');
|
| 154 |
-
};
|
| 155 |
reader.readAsDataURL(file);
|
| 156 |
}
|
| 157 |
-
|
|
|
|
| 158 |
function showPreview() {
|
| 159 |
imagePreview.src = currentImage.src;
|
| 160 |
imagePreviewContainer.classList.remove('hidden');
|
|
@@ -213,11 +161,12 @@ currentOrientation = orientation;
|
|
| 213 |
|
| 214 |
// Draw the image on canvas
|
| 215 |
ctx.drawImage(currentImage, 0, 0, canvas.width, canvas.height);
|
| 216 |
-
|
| 217 |
-
|
| 218 |
-
const pageWidth = canvas.width / cols
|
| 219 |
-
const pageHeight = canvas.height / rows
|
| 220 |
-
|
|
|
|
| 221 |
for (let row = 0; row < rows; row++) {
|
| 222 |
for (let col = 0; col < cols; col++) {
|
| 223 |
const pageIndex = row * cols + col;
|
|
@@ -230,11 +179,12 @@ currentOrientation = orientation;
|
|
| 230 |
const pageCtx = pageCanvas.getContext('2d');
|
| 231 |
|
| 232 |
// Calculate source dimensions
|
| 233 |
-
const sx =
|
| 234 |
-
const sy =
|
| 235 |
const sw = pageWidth;
|
| 236 |
const sh = pageHeight;
|
| 237 |
-
|
|
|
|
| 238 |
pageCtx.drawImage(
|
| 239 |
canvas,
|
| 240 |
sx, sy, sw, sh,
|
|
@@ -321,31 +271,4 @@ currentOrientation = orientation;
|
|
| 321 |
document.body.removeChild(link);
|
| 322 |
});
|
| 323 |
}
|
| 324 |
-
|
| 325 |
-
// Generate PDF with all pages
|
| 326 |
-
function generatePDF() {
|
| 327 |
-
const { jsPDF } = window.jspdf;
|
| 328 |
-
const pdf = new jsPDF({
|
| 329 |
-
orientation: currentOrientation === 'portrait' ? 'p' : 'l',
|
| 330 |
-
unit: 'mm',
|
| 331 |
-
format: 'a4'
|
| 332 |
-
});
|
| 333 |
-
|
| 334 |
-
const pages = posterPages.querySelectorAll('.poster-page img');
|
| 335 |
-
|
| 336 |
-
pages.forEach((img, index) => {
|
| 337 |
-
if (index > 0) {
|
| 338 |
-
pdf.addPage('a4', currentOrientation === 'portrait' ? 'p' : 'l');
|
| 339 |
-
}
|
| 340 |
-
|
| 341 |
-
// Add image to PDF page (A4 dimensions: 210x297mm or 297x210mm)
|
| 342 |
-
const width = currentOrientation === 'portrait' ? 210 : 297;
|
| 343 |
-
const height = currentOrientation === 'portrait' ? 297 : 210;
|
| 344 |
-
|
| 345 |
-
pdf.addImage(img.src, 'JPEG', 0, 0, width, height, undefined, 'FAST');
|
| 346 |
-
});
|
| 347 |
-
|
| 348 |
-
pdf.save('poster-pages.pdf');
|
| 349 |
-
}
|
| 350 |
-
}
|
| 351 |
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
document.addEventListener('DOMContentLoaded', function() {
|
| 2 |
+
// DOM elements
|
| 3 |
const fileInput = document.getElementById('file-input');
|
| 4 |
const uploadBtn = document.getElementById('upload-btn');
|
| 5 |
const dropZone = document.getElementById('drop-zone');
|
|
|
|
| 15 |
const resultSection = document.getElementById('result-section');
|
| 16 |
const posterPages = document.getElementById('poster-pages');
|
| 17 |
const downloadAllBtn = document.getElementById('download-all');
|
|
|
|
|
|
|
|
|
|
| 18 |
|
| 19 |
// Current image and settings
|
| 20 |
+
let currentImage = null;
|
| 21 |
let currentOrientation = 'portrait';
|
| 22 |
let currentPageCount = 4;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 23 |
|
| 24 |
+
// Event listeners
|
| 25 |
+
uploadBtn.addEventListener('click', () => fileInput.click());
|
| 26 |
+
fileInput.addEventListener('change', handleFileSelect);
|
| 27 |
+
dropZone.addEventListener('dragover', handleDragOver);
|
| 28 |
+
dropZone.addEventListener('dragleave', handleDragLeave);
|
| 29 |
+
dropZone.addEventListener('drop', handleDrop);
|
| 30 |
+
pageCountInput.addEventListener('input', updatePageCount);
|
| 31 |
+
portraitBtn.addEventListener('click', () => setOrientation('portrait'));
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 32 |
landscapeBtn.addEventListener('click', () => setOrientation('landscape'));
|
| 33 |
generateBtn.addEventListener('click', generatePosterPages);
|
| 34 |
downloadAllBtn.addEventListener('click', downloadAllPages);
|
|
|
|
| 35 |
|
| 36 |
// Update page count display
|
| 37 |
+
function updatePageCount() {
|
| 38 |
currentPageCount = parseInt(pageCountInput.value);
|
| 39 |
pageCountValue.textContent = currentPageCount;
|
| 40 |
}
|
| 41 |
|
| 42 |
// Set orientation
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 43 |
function setOrientation(orientation) {
|
| 44 |
+
currentOrientation = orientation;
|
| 45 |
if (orientation === 'portrait') {
|
| 46 |
portraitBtn.classList.add('active', 'bg-indigo-100', 'text-indigo-700');
|
| 47 |
portraitBtn.classList.remove('border', 'border-gray-300');
|
|
|
|
| 65 |
|
| 66 |
// Handle drag over
|
| 67 |
function handleDragOver(e) {
|
| 68 |
+
e.preventDefault();
|
| 69 |
e.stopPropagation();
|
| 70 |
dropZone.classList.add('highlight');
|
| 71 |
}
|
| 72 |
|
| 73 |
// Handle drag leave
|
| 74 |
function handleDragLeave(e) {
|
| 75 |
+
e.preventDefault();
|
| 76 |
e.stopPropagation();
|
| 77 |
dropZone.classList.remove('highlight');
|
| 78 |
}
|
| 79 |
+
|
| 80 |
// Handle drop
|
| 81 |
function handleDrop(e) {
|
| 82 |
+
e.preventDefault();
|
| 83 |
e.stopPropagation();
|
| 84 |
dropZone.classList.remove('highlight');
|
| 85 |
|
| 86 |
+
const file = e.dataTransfer.files[0];
|
|
|
|
|
|
|
| 87 |
if (file && file.type.match('image.*')) {
|
| 88 |
processImageFile(file);
|
|
|
|
|
|
|
| 89 |
}
|
| 90 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 91 |
|
| 92 |
+
// Process image file
|
| 93 |
+
function processImageFile(file) {
|
| 94 |
const reader = new FileReader();
|
| 95 |
reader.onload = function(e) {
|
| 96 |
currentImage = new Image();
|
| 97 |
currentImage.onload = function() {
|
| 98 |
showPreview();
|
| 99 |
};
|
|
|
|
|
|
|
|
|
|
| 100 |
currentImage.src = e.target.result;
|
| 101 |
};
|
|
|
|
|
|
|
|
|
|
| 102 |
reader.readAsDataURL(file);
|
| 103 |
}
|
| 104 |
+
|
| 105 |
+
// Show preview
|
| 106 |
function showPreview() {
|
| 107 |
imagePreview.src = currentImage.src;
|
| 108 |
imagePreviewContainer.classList.remove('hidden');
|
|
|
|
| 161 |
|
| 162 |
// Draw the image on canvas
|
| 163 |
ctx.drawImage(currentImage, 0, 0, canvas.width, canvas.height);
|
| 164 |
+
|
| 165 |
+
// Calculate each page's dimensions
|
| 166 |
+
const pageWidth = canvas.width / cols;
|
| 167 |
+
const pageHeight = canvas.height / rows;
|
| 168 |
+
|
| 169 |
+
// Create individual pages
|
| 170 |
for (let row = 0; row < rows; row++) {
|
| 171 |
for (let col = 0; col < cols; col++) {
|
| 172 |
const pageIndex = row * cols + col;
|
|
|
|
| 179 |
const pageCtx = pageCanvas.getContext('2d');
|
| 180 |
|
| 181 |
// Calculate source dimensions
|
| 182 |
+
const sx = col * pageWidth;
|
| 183 |
+
const sy = row * pageHeight;
|
| 184 |
const sw = pageWidth;
|
| 185 |
const sh = pageHeight;
|
| 186 |
+
|
| 187 |
+
// Draw the portion of the image on the page
|
| 188 |
pageCtx.drawImage(
|
| 189 |
canvas,
|
| 190 |
sx, sy, sw, sh,
|
|
|
|
| 271 |
document.body.removeChild(link);
|
| 272 |
});
|
| 273 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 274 |
});
|
style.css
CHANGED
|
@@ -7,17 +7,14 @@
|
|
| 7 |
.orientation-btn.active {
|
| 8 |
border: 2px solid #6366f1;
|
| 9 |
}
|
|
|
|
| 10 |
.poster-page {
|
| 11 |
position: relative;
|
| 12 |
background-color: white;
|
| 13 |
overflow: hidden;
|
| 14 |
box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
|
| 15 |
-
break-inside: avoid;
|
| 16 |
}
|
| 17 |
|
| 18 |
-
#download-pdf {
|
| 19 |
-
transition: all 0.2s ease;
|
| 20 |
-
}
|
| 21 |
.poster-page::before {
|
| 22 |
content: "";
|
| 23 |
position: absolute;
|
|
|
|
| 7 |
.orientation-btn.active {
|
| 8 |
border: 2px solid #6366f1;
|
| 9 |
}
|
| 10 |
+
|
| 11 |
.poster-page {
|
| 12 |
position: relative;
|
| 13 |
background-color: white;
|
| 14 |
overflow: hidden;
|
| 15 |
box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
|
|
|
|
| 16 |
}
|
| 17 |
|
|
|
|
|
|
|
|
|
|
| 18 |
.poster-page::before {
|
| 19 |
content: "";
|
| 20 |
position: absolute;
|