Spaces:
Running
Running
هنوز بخشهایی از عکس اصلی در صفحات چوستر ساخته نشده اند درست کن و مطمین شئ تمام نقاط عکس در صفحه های پوستر موجود باشد
Browse files
script.js
CHANGED
|
@@ -164,24 +164,46 @@ let uploadedImage = null;
|
|
| 164 |
sh = segmentHeight + (row < gridSize-1 ? overlapYPx : 0);
|
| 165 |
}
|
| 166 |
}
|
| 167 |
-
//
|
| 168 |
-
|
| 169 |
-
|
| 170 |
-
|
| 171 |
-
|
| 172 |
-
|
| 173 |
-
|
| 174 |
-
|
| 175 |
-
|
| 176 |
-
|
| 177 |
-
|
| 178 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 179 |
}
|
| 180 |
|
| 181 |
-
// Adjust
|
|
|
|
|
|
|
| 182 |
sw = Math.min(sw, uploadedImage.width - sx);
|
| 183 |
sh = Math.min(sh, uploadedImage.height - sy);
|
| 184 |
-
|
| 185 |
ctx.save();
|
| 186 |
if (orient === 'diagonal') {
|
| 187 |
// For diagonal orientation, rotate the canvas
|
|
@@ -202,15 +224,25 @@ let uploadedImage = null;
|
|
| 202 |
// Adjust destination position based on any out-of-bounds
|
| 203 |
const destX = -dx * (destWidth / sw);
|
| 204 |
const destY = -dy * (destHeight / sh);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 205 |
|
| 206 |
ctx.drawImage(
|
| 207 |
uploadedImage,
|
| 208 |
sx, sy, sw, sh,
|
| 209 |
-
|
| 210 |
-
|
| 211 |
-
destHeight * (sh / (sh + dy))
|
| 212 |
);
|
| 213 |
-
|
| 214 |
// Draw border around the image segment
|
| 215 |
ctx.strokeStyle = 'rgba(255, 0, 0, 0.5)';
|
| 216 |
ctx.lineWidth = 2;
|
|
|
|
| 164 |
sh = segmentHeight + (row < gridSize-1 ? overlapYPx : 0);
|
| 165 |
}
|
| 166 |
}
|
| 167 |
+
// Ensure we cover the entire image while maintaining proper overlaps
|
| 168 |
+
if (centerOverlaps) {
|
| 169 |
+
// For center overlaps, make sure we don't leave gaps
|
| 170 |
+
if (col === 0) {
|
| 171 |
+
sx = 0;
|
| 172 |
+
sw = segmentWidth + overlapXPx;
|
| 173 |
+
} else if (col === gridSize-1) {
|
| 174 |
+
sx = uploadedImage.width - segmentWidth - overlapXPx;
|
| 175 |
+
sw = segmentWidth + overlapXPx;
|
| 176 |
+
} else {
|
| 177 |
+
sx = col * segmentWidth - overlapXPx;
|
| 178 |
+
sw = segmentWidth + overlapXPx * 2;
|
| 179 |
+
}
|
| 180 |
+
|
| 181 |
+
if (row === 0) {
|
| 182 |
+
sy = 0;
|
| 183 |
+
sh = segmentHeight + overlapYPx;
|
| 184 |
+
} else if (row === gridSize-1) {
|
| 185 |
+
sy = uploadedImage.height - segmentHeight - overlapYPx;
|
| 186 |
+
sh = segmentHeight + overlapYPx;
|
| 187 |
+
} else {
|
| 188 |
+
sy = row * segmentHeight - overlapYPx;
|
| 189 |
+
sh = segmentHeight + overlapYPx * 2;
|
| 190 |
+
}
|
| 191 |
+
} else {
|
| 192 |
+
// Traditional overlaps - ensure we cover the entire image
|
| 193 |
+
if (col === gridSize-1) {
|
| 194 |
+
sw = uploadedImage.width - col * segmentWidth;
|
| 195 |
+
}
|
| 196 |
+
if (row === gridSize-1) {
|
| 197 |
+
sh = uploadedImage.height - row * segmentHeight;
|
| 198 |
+
}
|
| 199 |
}
|
| 200 |
|
| 201 |
+
// Adjust for any out-of-bounds that might still occur
|
| 202 |
+
sx = Math.max(0, sx);
|
| 203 |
+
sy = Math.max(0, sy);
|
| 204 |
sw = Math.min(sw, uploadedImage.width - sx);
|
| 205 |
sh = Math.min(sh, uploadedImage.height - sy);
|
| 206 |
+
// Draw the image segment with border
|
| 207 |
ctx.save();
|
| 208 |
if (orient === 'diagonal') {
|
| 209 |
// For diagonal orientation, rotate the canvas
|
|
|
|
| 224 |
// Adjust destination position based on any out-of-bounds
|
| 225 |
const destX = -dx * (destWidth / sw);
|
| 226 |
const destY = -dy * (destHeight / sh);
|
| 227 |
+
// Calculate scale to fill canvas while maintaining aspect ratio
|
| 228 |
+
const scale = Math.min(
|
| 229 |
+
destWidth / sw,
|
| 230 |
+
destHeight / sh
|
| 231 |
+
);
|
| 232 |
+
const scaledWidth = sw * scale;
|
| 233 |
+
const scaledHeight = sh * scale;
|
| 234 |
+
|
| 235 |
+
// Center the image on canvas
|
| 236 |
+
const offsetX = (destWidth - scaledWidth) / 2;
|
| 237 |
+
const offsetY = (destHeight - scaledHeight) / 2;
|
| 238 |
|
| 239 |
ctx.drawImage(
|
| 240 |
uploadedImage,
|
| 241 |
sx, sy, sw, sh,
|
| 242 |
+
offsetX, offsetY,
|
| 243 |
+
scaledWidth, scaledHeight
|
|
|
|
| 244 |
);
|
| 245 |
+
}
|
| 246 |
// Draw border around the image segment
|
| 247 |
ctx.strokeStyle = 'rgba(255, 0, 0, 0.5)';
|
| 248 |
ctx.lineWidth = 2;
|