Feat: Add crop functionality to image editing with overlay support#6645
Feat: Add crop functionality to image editing with overlay support#6645nicolas-raoul merged 13 commits intocommons-app:mainfrom
Conversation
| ExifInterface.TAG_GPS_LONGITUDE_REF, | ||
| ExifInterface.TAG_GPS_PROCESSING_METHOD, | ||
| ExifInterface.TAG_GPS_TIMESTAMP, | ||
| ExifInterface.TAG_IMAGE_LENGTH, |
There was a problem hiding this comment.
Removed TAG_ORIENTATION, TAG_IMAGE_WIDTH, and TAG_IMAGE_LENGTH from the EXIF copy list because they describe image geometry, which changes after rotation or crop. LLJTran’s lossless rotation physically rotates the pixels and resets orientation to normal. Copying the old orientation caused a double-rotation (viewers rotated an already-rotated image), leading to a 90° mismatch between edit and upload screens. Width/height tags also become invalid after rotation or crop. All capture metadata (GPS, camera info, timestamps, etc.) is still preserved.
|
hi @nicolas-raoul please take a look when you get time. |
|
@shankarpriyank Thanks for the feature, On a fresh install with this branch, i went to the custom selector, selected a photo from downloads, and clicked the upload button. It took me to the details screen, where i edited the image and clicked cancel upload without uploading the pic. then I came back to downloads and selected the newly saved (edited) pic to upload, but this time i am not able to upload. it is marked as uploaded to commons, even though i just edited the pic. Video: Screenrecorder-2026-02-07-10-01-46-212.mp4But i think you can wait to start working on the above said comment till the pr #6642 gets confirmation. @RitikaPahwa4444 Correct me if i am wrong. |
|
@Kota-Jagadeesh thanks for catching this bug. |
Can you please wait for confirmation from the maintainers, because I have addressed similar type of issue in another PR as mentioned above, and it is open. |
yeah i just checked out that pr, good work ! i would brace for merge conflicts 💣 |
| ) | ||
|
|
||
| // Step 4: Apply lossless crop (in-place) | ||
| lljTran.transform( |
|
Crop rectangle is not aligned with picture: 1bd870e8-4061-4aad-9c7a-321a2a331575.mp4 |
98bc0861-a4f1-4de1-beff-d469d15d9d00.mp4 |
|
with phone unfolded I can't find the top and bottom grip points: 3833fb63-4c83-4e66-8140-9d05cba9dc9c.mp4 |
|
@nicolas-raoul thanks for reporting the bugs let me fix them |
|
@nicolas-raoul , can you please test again ? i tested with a bunch of images and seems the problems have been fixed. but if you do find error, please also share the test images with me 🙇 |
nicolas-raoul
left a comment
There was a problem hiding this comment.
ac7979e7-c21a-40dc-aef6-b7f45b8e4074.mp4
Nothing suspicious in logcat
|
@nicolas-raoul are you clicking on crop button again after selecting crop area? |
|
hi @nicolas-raoul can you please reply to the comment above
|
|
I assumed I have to tap "crop" to crop. Somehow the UI that was straightforward for rotate feels unintuitive for crop. Any idea for a more straightforward UI? |
@nicolas-raoul yes tapping crop will cancel the crop operation we can probably improve the UX later, but yeah please do let me know if you think this is a blocker and we should fix it right now |
|
That could be a future issue indeed. |
|
hi @nicolas-raoul, thanks for reporting the issue, it should be fixed now |
|
I start testing. Meanwhile, would you mind solving the conflicts? Thanks! :-) |
|
I uploaded a picture, crop looks correct, I will try a few more later this week. |
|
I actually tried a bit more, it seems fixed, thanks! I will merge, would you mind solving the conflicts? |
| /** | ||
| * Crops the specified image file using lossless JPEG cropping via LLJTran. | ||
| * | ||
| * Works around a porting bug in the Android LLJTran library where the internal |
There was a problem hiding this comment.
Would you mind adding a URL to the bug report? Or if there is no bug report, to the best webpage explaining this? Thanks!
# Conflicts: # app/src/main/java/fr/free/nrw/commons/edit/EditActivity.kt # app/src/main/java/fr/free/nrw/commons/edit/EditViewModel.kt # app/src/main/java/fr/free/nrw/commons/edit/TransformImage.kt # app/src/main/res/layout/activity_edit.xml
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
|
@shankarpriyank I just tested your branch With this branch in the edit screen, I feel that the And also do we really need the back button ? For reference i added the 2nd screenshot on how the edit scren looks like in main branch : )
|
|
hi @Kota-Jagadeesh , thanks for pointing it out I have fixed it 🙇 |
|
found a small bug: when I crop a picture and then save it, the app stores the new cropped image in my Downloads folder. Shouldn’t cropped images be stored in the app’s internal or Also, could you just revert this commit cc4e150. I was using the app from main branch which wasn't updated from few days, so was not aware of the recent changes (now even the main branch has the Topbar in the edit screen) Please revert the change. Thank you 🙂 |
…p related code" This reverts commit cc4e150.
|
fixed |
|
✅ Generated APK variants! |
| * whenever the crop origin is nonzero. | ||
| * | ||
| * See the buggy assignment in validateCropBounds: | ||
| * https://github.com/bkhall/AndroidMediaUtil/blob/master/src/android/mediautil/image/jpeg/LLJTran.java |
There was a problem hiding this comment.
Can you please create an issue about this at https://github.com/bkhall/AndroidMediaUtil/issues ? Thanks!
nicolas-raoul
left a comment
There was a problem hiding this comment.
Re-tested normal crop. Tested crop plus rotation. Working well it seems.
Thanks for this very significant, useful and technically challenging contribution!




Description (required)
What changes did you make and why?
Added crop feature to the app
Tests performed (required)
tested the app locally and made sure it works fine
Tested betaDebug on pixel 9 fold with API level 36.
Not adding any screen shots, as its sort of a complete new flow, just verifying with image would not be sufficient
Screen_recording_20260207_132016.mp4