Skip to content

Feat: Add crop functionality to image editing with overlay support#6645

Merged
nicolas-raoul merged 13 commits intocommons-app:mainfrom
shankarpriyank:add-crop-support
Mar 5, 2026
Merged

Feat: Add crop functionality to image editing with overlay support#6645
nicolas-raoul merged 13 commits intocommons-app:mainfrom
shankarpriyank:add-crop-support

Conversation

@shankarpriyank
Copy link
Contributor

@shankarpriyank shankarpriyank commented Feb 6, 2026

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

ExifInterface.TAG_GPS_LONGITUDE_REF,
ExifInterface.TAG_GPS_PROCESSING_METHOD,
ExifInterface.TAG_GPS_TIMESTAMP,
ExifInterface.TAG_IMAGE_LENGTH,
Copy link
Contributor Author

@shankarpriyank shankarpriyank Feb 6, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@shankarpriyank shankarpriyank marked this pull request as ready for review February 6, 2026 17:28
@shankarpriyank
Copy link
Contributor Author

hi @nicolas-raoul please take a look when you get time.

@Kota-Jagadeesh
Copy link
Collaborator

@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.mp4

But 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.

@shankarpriyank
Copy link
Contributor Author

@Kota-Jagadeesh thanks for catching this bug.
let me fix this.

@Kota-Jagadeesh
Copy link
Collaborator

let me fix this.

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.

@shankarpriyank
Copy link
Contributor Author

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(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚀

@nicolas-raoul
Copy link
Member

Crop rectangle is not aligned with picture:

1bd870e8-4061-4aad-9c7a-321a2a331575.mp4

@nicolas-raoul
Copy link
Member

  • The crop UI interferes with edge-based navigation. Not sure what a good UI would be. Photo Editor has a usable one.
  • Cropping gives wrong result, presumbly due to offset I mentioned in my previous comment:
98bc0861-a4f1-4de1-beff-d469d15d9d00.mp4

@nicolas-raoul
Copy link
Member

with phone unfolded I can't find the top and bottom grip points:

3833fb63-4c83-4e66-8140-9d05cba9dc9c.mp4

@shankarpriyank
Copy link
Contributor Author

@nicolas-raoul thanks for reporting the bugs let me fix them

@shankarpriyank
Copy link
Contributor Author

@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 🙇

Copy link
Member

@nicolas-raoul nicolas-raoul left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ac7979e7-c21a-40dc-aef6-b7f45b8e4074.mp4

Nothing suspicious in logcat

@shankarpriyank
Copy link
Contributor Author

@nicolas-raoul are you clicking on crop button again after selecting crop area?

@shankarpriyank
Copy link
Contributor Author

hi @nicolas-raoul can you please reply to the comment above

@nicolas-raoul are you clicking on crop button again after selecting crop area?

@nicolas-raoul
Copy link
Member

I assumed I have to tap "crop" to crop.
Does that actually cancel everything?

Somehow the UI that was straightforward for rotate feels unintuitive for crop.

Any idea for a more straightforward UI?

@shankarpriyank
Copy link
Contributor Author

shankarpriyank commented Feb 22, 2026

I assumed I have to tap "crop" to crop.
Does that actually cancel everything?
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
yeah i also agree the UI can be improved, but I personally think its usable right now and could be merged

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

@nicolas-raoul
Copy link
Member

That could be a future issue indeed.
Sorry I am super busy unfortunately, review will take time.

Copy link
Member

@nicolas-raoul nicolas-raoul left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just cropped+uploaded this picture in the app:

https://upload.wikimedia.org/wikipedia/commons/e/eb/%E6%84%9B%E7%9F%A5%E7%9C%8C%E8%AD%A6_%E6%84%9B1.jpg

Screenshot_20260226-211756.png

Problem: the bottom shows pixels that actually are the top of the orange ship.

I guess you need to crop at the nearest JPG block boundary.

Original:
PXL_20260223_080033780.jpg

@shankarpriyank
Copy link
Contributor Author

hi @nicolas-raoul, thanks for reporting the issue, it should be fixed now
but in case it persists, please send the test picture over email, so that I can debut it

@nicolas-raoul
Copy link
Member

I start testing.

Meanwhile, would you mind solving the conflicts? Thanks! :-)

@nicolas-raoul
Copy link
Member

I uploaded a picture, crop looks correct, I will try a few more later this week.

@nicolas-raoul
Copy link
Member

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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would you mind adding a URL to the bug report? Or if there is no bug report, to the best webpage explaining this? Thanks!

shankarpriyank and others added 2 commits March 3, 2026 19:23
# 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>
@Kota-Jagadeesh
Copy link
Collaborator

@shankarpriyank I just tested your branch

With this branch in the edit screen, I feel that the Edit Image title at the top is occupying more space. How about removing it and restoring the layout to look more like the main branch, or at least reducing the size it takes? @nicolas-raoul, is that a good idea? 🤔

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 : )

image image

@shankarpriyank
Copy link
Contributor Author

hi @Kota-Jagadeesh , thanks for pointing it out I have fixed it 🙇
@nicolas-raoul please have a look again

@Kota-Jagadeesh
Copy link
Collaborator

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 cachedir instead?

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 🙂

@shankarpriyank
Copy link
Contributor Author

fixed

@github-actions
Copy link

github-actions bot commented Mar 4, 2026

✅ 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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you please create an issue about this at https://github.com/bkhall/AndroidMediaUtil/issues ? Thanks!

Copy link
Member

@nicolas-raoul nicolas-raoul left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Re-tested normal crop. Tested crop plus rotation. Working well it seems.

Thanks for this very significant, useful and technically challenging contribution!

@nicolas-raoul nicolas-raoul merged commit 7ce4fc8 into commons-app:main Mar 5, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants