Fix image rotation to use 360 degrees instead of 180#61
Conversation
Co-authored-by: YoungMame <134452452+YoungMame@users.noreply.github.com>
Co-authored-by: YoungMame <134452452+YoungMame@users.noreply.github.com>
…rotation icons Co-authored-by: YoungMame <134452452+YoungMame@users.noreply.github.com>
Co-authored-by: YoungMame <134452452+YoungMame@users.noreply.github.com>
Co-authored-by: YoungMame <134452452+YoungMame@users.noreply.github.com>
Co-authored-by: YoungMame <134452452+YoungMame@users.noreply.github.com>
|
In fastify you have to update image rotation that is on 180 deg in the POST /profile-picture route |
There was a problem hiding this comment.
Pull request overview
This PR fixes a bug where image rotation was limited to only two orientations (0° and 90°) instead of allowing full 360° rotation through all four orientations (0°, 90°, 180°, 270°). The fix changes the modulo operation from % 180 to % 360 in the rotation logic.
- Implemented new
ImageCroppercomponent with corrected rotation handlers using% 360 - Added utility functions
cropImage.tsandgetImageUrl.tsfor image processing and URL generation - Integrated
react-easy-croplibrary for enhanced cropping functionality
Reviewed changes
Copilot reviewed 4 out of 5 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| nextjs/matcha/src/components/common/ImageCropper.tsx | New component with fixed 360° rotation logic for both left ((rotation - 90 + 360) % 360) and right ((rotation + 90) % 360) rotation |
| nextjs/matcha/src/utils/cropImage.ts | Utility functions for image processing including rotation conversion to radians, size calculations, and canvas-based cropping |
| nextjs/matcha/src/utils/getImageUrl.ts | Helper function to create blob URLs from File objects for image preview |
| nextjs/matcha/package.json | Added react-easy-crop v5.5.6 dependency |
| nextjs/matcha/pnpm-lock.yaml | Dependency lock updates for react-easy-crop and its transitive dependency normalize-wheel |
Files not reviewed (1)
- nextjs/matcha/pnpm-lock.yaml: Language not supported
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| @@ -0,0 +1,6 @@ | |||
| /** | |||
| * Convert a File object to a data URL for display | |||
There was a problem hiding this comment.
The comment says "Convert a File object to a data URL" but URL.createObjectURL() creates a blob URL (e.g., blob:...), not a data URL (e.g., data:image/png;base64,...). Consider updating the comment to accurately describe the function's behavior: "Convert a File object to a blob URL for display".
| * Convert a File object to a data URL for display | |
| * Convert a File object to a blob URL for display |
| return additionalPictures[currentCroppingIndex - 1] || null; | ||
| }; | ||
|
|
||
| const imageUrl = getImageUrl(getCurrentImage()) || "none"; |
There was a problem hiding this comment.
Memory leak: Object URLs created with URL.createObjectURL() should be revoked with URL.revokeObjectURL() when no longer needed to prevent memory leaks. In this component, a new object URL is created on every render when getCurrentImage() changes, but previous URLs are never cleaned up. Consider using a useEffect hook to manage the URL lifecycle:
useEffect(() => {
const currentImage = getCurrentImage();
const url = currentImage ? URL.createObjectURL(currentImage) : "none";
return () => {
if (url !== "none") {
URL.revokeObjectURL(url);
}
};
}, [currentCroppingIndex, profilePicture, additionalPictures]);| @@ -0,0 +1,105 @@ | |||
| /** | |||
| * Create a cropped image from a source image URL | |||
There was a problem hiding this comment.
The comment says "Create a cropped image from a source image URL" but this function only loads an image, it doesn't crop it. The actual cropping is done by getCroppedImg(). Consider updating to: "Load an image from a URL".
| * Create a cropped image from a source image URL | |
| * Load an image from a URL |
…r-management' into copilot/fix-image-rotation-issue
ece69cb
into
57-image-scroping-in-inscription-form-image-upload-error-management
Image rotation was limited to 180 degrees due to incorrect modulo operation (
% 180instead of% 360), preventing full rotation through all four orientations.Changes
ImageCropper.tsx: New component with correct 360° rotation logic
(rotation - 90 + 360) % 360(rotation + 90) % 360Areainterface, SVG rotation iconsUtility files: Added
cropImage.tsandgetImageUrl.tsfor image processingDependencies: Added
react-easy-cropfor cropping UIFixes #60
Warning
Firewall rules blocked me from connecting to one or more addresses (expand for details)
I tried to connect to the following addresses, but was blocked by firewall rules:
fonts.googleapis.com/usr/local/bin/node node /home/REDACTED/work/matcha/matcha/nextjs/matcha/node_modules/.bin/next build --turbopack(dns block)https://api.github.com//advisories/home/REDACTED/work/_temp/ghcca-node/node/bin/node /home/REDACTED/work/_temp/ghcca-node/node/bin/node --enable-source-maps /home/REDACTED/work/_temp/copilot-developer-action-main/dist/index.js(http block)If you need me to access, download, or install something from one of these locations, you can either:
Original prompt
✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.