Added image compression for large images#3
Conversation
Co-authored-by: akemmanuel <akemmanuel@users.noreply.github.com>
Code Review: Image Compression PRConfidence Score: 4/5Issues Found:1. Unused Constant (Low) const MAX_IMAGE_SIZE = 5 * 1024 * 1024; // 5 MBThis constant is defined but never used in the code. 2. Base64 Size Calculation Bug (Medium) const base64Length = result.length - "data:image/jpeg;base64,".length;
const byteSize = Math.round((base64Length * 3) / 4);The calculation 3. Transparency Loss for PNG Images (Medium) const result = canvas.toDataURL("image/jpeg", quality);JPEG doesn't support transparency - any PNG with transparency will become black background. Consider either:
4. Potential Infinite Loop Risk (Low) if (byteSize <= TARGET_IMAGE_SIZE || quality <= 0.1) {
resolve(result);
} else {
quality -= 0.1;
tryCompress();
}If the image is extremely large and even at 0.1 quality exceeds 4.5MB, the loop terminates but returns a very low-quality image with no warning. 5. Missing Cleanup for Image Object (Low) 6. No Error Handling for Corrupt Images (Medium) Suggestions:
|
|
/oc can you fix this? |
Co-authored-by: akemmanuel <akemmanuel@users.noreply.github.com>
|
Fixed the following issues from the code review:
|
|
User opencode-agent[bot] does not have write permissions |


The fix is complete. I added image compression in
src/components/PromptBox.tsx:Added
compressImagefunction - Compresses images over 4.5MB using canvas:Updated
appendImages- Now usescompressImageinstead of rawreadFileAsDataURLThis ensures images are automatically compressed before being sent to the provider, preventing the "image exceeds 5 MB maximum" error.
Closes #2
opencode session | github run