github-actions[bot] commited on
Commit
b948e3a
·
1 Parent(s): f596af1

Sync from GitHub: c4c615ffc9be9af88c27315300a80d370d17d13d

Browse files
frontend/src/components/ResultCard.jsx CHANGED
@@ -10,6 +10,7 @@ const ResultCard = ({ result, imageData, onReprocess, isProcessing }) => {
10
  const [resolution, setResolution] = useState(100);
11
  const [adjustedDataUrl, setAdjustedDataUrl] = useState(null);
12
  const [previewDimensions, setPreviewDimensions] = useState({ width: 0, height: 0 });
 
13
 
14
  // Function to crop image regions
15
  const cropRegion = (img, coords, scaleX, scaleY) => {
@@ -34,8 +35,9 @@ const ResultCard = ({ result, imageData, onReprocess, isProcessing }) => {
34
  return cropCanvas.toDataURL();
35
  };
36
 
 
37
  useEffect(() => {
38
- if (!imageData || !canvasRef.current) return;
39
 
40
  const canvas = canvasRef.current;
41
  const ctx = canvas.getContext('2d');
@@ -68,15 +70,19 @@ const ResultCard = ({ result, imageData, onReprocess, isProcessing }) => {
68
  const scaleX = width / img.width;
69
  const scaleY = height / img.height;
70
 
71
- // Create cropped images for signature and stamp
72
- if (result.signature_coords && result.signature_coords.length > 0) {
73
- const sigCrop = cropRegion(img, result.signature_coords, 1, 1);
74
- setSignatureCrop(sigCrop);
75
- }
76
- if (result.stamp_coords && result.stamp_coords.length > 0) {
77
- const stCrop = cropRegion(img, result.stamp_coords, 1, 1);
78
- setStampCrop(stCrop);
79
- }
 
 
 
 
80
 
81
  // Draw bounding boxes for signature
82
  if (result.signature_coords && result.signature_coords.length > 0) {
@@ -123,10 +129,10 @@ const ResultCard = ({ result, imageData, onReprocess, isProcessing }) => {
123
  }
124
  };
125
 
126
- img.src = imageData;
127
- }, [imageData, result]);
128
 
129
- // Handle resolution adjustment for preview
130
  useEffect(() => {
131
  if (!imageData || !previewCanvasRef.current) return;
132
 
@@ -148,6 +154,9 @@ const ResultCard = ({ result, imageData, onReprocess, isProcessing }) => {
148
  // Generate adjusted data URL
149
  const adjustedUrl = canvas.toDataURL('image/jpeg', 0.95);
150
  setAdjustedDataUrl(adjustedUrl);
 
 
 
151
  };
152
 
153
  img.src = imageData;
 
10
  const [resolution, setResolution] = useState(100);
11
  const [adjustedDataUrl, setAdjustedDataUrl] = useState(null);
12
  const [previewDimensions, setPreviewDimensions] = useState({ width: 0, height: 0 });
13
+ const [currentImageData, setCurrentImageData] = useState(imageData);
14
 
15
  // Function to crop image regions
16
  const cropRegion = (img, coords, scaleX, scaleY) => {
 
35
  return cropCanvas.toDataURL();
36
  };
37
 
38
+ // Main effect to draw image with bounding boxes using currentImageData
39
  useEffect(() => {
40
+ if (!currentImageData || !canvasRef.current) return;
41
 
42
  const canvas = canvasRef.current;
43
  const ctx = canvas.getContext('2d');
 
70
  const scaleX = width / img.width;
71
  const scaleY = height / img.height;
72
 
73
+ // Create cropped images for signature and stamp from ORIGINAL imageData
74
+ const originalImg = new Image();
75
+ originalImg.onload = () => {
76
+ if (result.signature_coords && result.signature_coords.length > 0) {
77
+ const sigCrop = cropRegion(originalImg, result.signature_coords, 1, 1);
78
+ setSignatureCrop(sigCrop);
79
+ }
80
+ if (result.stamp_coords && result.stamp_coords.length > 0) {
81
+ const stCrop = cropRegion(originalImg, result.stamp_coords, 1, 1);
82
+ setStampCrop(stCrop);
83
+ }
84
+ };
85
+ originalImg.src = imageData;
86
 
87
  // Draw bounding boxes for signature
88
  if (result.signature_coords && result.signature_coords.length > 0) {
 
129
  }
130
  };
131
 
132
+ img.src = currentImageData;
133
+ }, [currentImageData, imageData, result]);
134
 
135
+ // Handle resolution adjustment for preview and update currentImageData
136
  useEffect(() => {
137
  if (!imageData || !previewCanvasRef.current) return;
138
 
 
154
  // Generate adjusted data URL
155
  const adjustedUrl = canvas.toDataURL('image/jpeg', 0.95);
156
  setAdjustedDataUrl(adjustedUrl);
157
+
158
+ // Update the current image data to reflect resolution change
159
+ setCurrentImageData(adjustedUrl);
160
  };
161
 
162
  img.src = imageData;