hbf0421 commited on
Commit
00280b6
·
verified ·
1 Parent(s): 92c791d

صفحات ایجاد شده کامل نیست و برخی قسمت های عکس در صفحات نیست

Browse files
Files changed (1) hide show
  1. script.js +49 -22
script.js CHANGED
@@ -135,8 +135,7 @@ let uploadedImage = null;
135
  }
136
 
137
  const ctx = canvas.getContext('2d');
138
-
139
- // Calculate source rectangle with overlap
140
  let sx, sy, sw, sh;
141
 
142
  if (orient === 'diagonal') {
@@ -152,25 +151,36 @@ let uploadedImage = null;
152
  } else {
153
  // Standard orientation
154
  if (centerOverlaps) {
155
- // Center overlaps evenly around all edges
156
- sx = col * segmentWidth - overlapXPx/2;
157
- sy = row * segmentHeight - overlapYPx/2;
158
- sw = segmentWidth + overlapXPx;
159
- sh = segmentHeight + overlapYPx;
160
  } else {
161
- // Overlaps only on right/bottom (traditional)
162
- sx = Math.max(0, col * segmentWidth - overlapXPx);
163
- sy = Math.max(0, row * segmentHeight - overlapYPx);
164
- sw = Math.min(uploadedImage.width - sx, segmentWidth + (col > 0 ? overlapXPx : 0) + (col < gridSize-1 ? overlapXPx : 0));
165
- sh = Math.min(uploadedImage.height - sy, segmentHeight + (row > 0 ? overlapYPx : 0) + (row < gridSize-1 ? overlapYPx : 0));
166
  }
167
  }
 
 
168
 
169
- // Ensure we don't go outside image bounds
170
- sx = Math.max(0, sx);
171
- sy = Math.max(0, sy);
172
- sw = Math.min(uploadedImage.width - sx, sw);
173
- sh = Math.min(uploadedImage.height - sy, sh);
 
 
 
 
 
 
 
 
 
174
  // Draw the image segment with border
175
  ctx.save();
176
  if (orient === 'diagonal') {
@@ -185,19 +195,36 @@ let uploadedImage = null;
185
  ctx.setTransform(1, 0, 0, 1, 0, 0);
186
  } else {
187
  // Standard orientation
 
 
 
 
 
 
 
 
188
  ctx.drawImage(
189
  uploadedImage,
190
  sx, sy, sw, sh,
191
- 0, 0, canvas.width, canvas.height
 
 
192
  );
193
  }
194
-
195
  // Draw border around the image segment
196
  ctx.strokeStyle = 'rgba(255, 0, 0, 0.5)';
197
  ctx.lineWidth = 2;
198
- ctx.strokeRect(0, 0, canvas.width, canvas.height);
199
-
200
- // Draw overlap indicators
 
 
 
 
 
 
 
 
201
  ctx.strokeStyle = 'rgba(0, 0, 255, 0.5)';
202
  ctx.lineWidth = 1;
203
  ctx.setLineDash([5, 5]);
 
135
  }
136
 
137
  const ctx = canvas.getContext('2d');
138
+ // Calculate source rectangle with proper overlap handling
 
139
  let sx, sy, sw, sh;
140
 
141
  if (orient === 'diagonal') {
 
151
  } else {
152
  // Standard orientation
153
  if (centerOverlaps) {
154
+ // Center overlaps - add equal overlap on all sides
155
+ sx = col * segmentWidth - overlapXPx;
156
+ sy = row * segmentHeight - overlapYPx;
157
+ sw = segmentWidth + overlapXPx * 2;
158
+ sh = segmentHeight + overlapYPx * 2;
159
  } else {
160
+ // Traditional overlaps - add overlap to right and bottom only
161
+ sx = col * segmentWidth;
162
+ sy = row * segmentHeight;
163
+ sw = segmentWidth + (col < gridSize-1 ? overlapXPx : 0);
164
+ sh = segmentHeight + (row < gridSize-1 ? overlapYPx : 0);
165
  }
166
  }
167
+ // Adjust source rectangle to stay within image bounds
168
+ let dx = 0, dy = 0;
169
 
170
+ if (sx < 0) {
171
+ dx = -sx;
172
+ sw += sx;
173
+ sx = 0;
174
+ }
175
+ if (sy < 0) {
176
+ dy = -sy;
177
+ sh += sy;
178
+ sy = 0;
179
+ }
180
+
181
+ // Adjust width/height if extending beyond image
182
+ sw = Math.min(sw, uploadedImage.width - sx);
183
+ sh = Math.min(sh, uploadedImage.height - sy);
184
  // Draw the image segment with border
185
  ctx.save();
186
  if (orient === 'diagonal') {
 
195
  ctx.setTransform(1, 0, 0, 1, 0, 0);
196
  } else {
197
  // Standard orientation
198
+ // Calculate destination rectangle with proper aspect ratio
199
+ const destWidth = canvas.width;
200
+ const destHeight = canvas.height;
201
+
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
+ destX, destY,
210
+ destWidth * (sw / (sw + dx)),
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;
217
+
218
+ if (orient === 'portrait' || orient === 'landscape') {
219
+ const borderX = dx > 0 ? dx * (canvas.width / sw) : 0;
220
+ const borderY = dy > 0 ? dy * (canvas.height / sh) : 0;
221
+ const borderWidth = canvas.width * (sw / (sw + dx));
222
+ const borderHeight = canvas.height * (sh / (sh + dy));
223
+ ctx.strokeRect(borderX, borderY, borderWidth, borderHeight);
224
+ } else {
225
+ ctx.strokeRect(0, 0, canvas.width, canvas.height);
226
+ }
227
+ // Draw overlap indicators
228
  ctx.strokeStyle = 'rgba(0, 0, 255, 0.5)';
229
  ctx.lineWidth = 1;
230
  ctx.setLineDash([5, 5]);