Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Image Cropping: PNG is converted to JPG #17817

Open
3 of 4 tasks
brishtibheja opened this issue Jan 14, 2025 · 9 comments
Open
3 of 4 tasks

Image Cropping: PNG is converted to JPG #17817

brishtibheja opened this issue Jan 14, 2025 · 9 comments
Assignees

Comments

@brishtibheja
Copy link

Checked for duplicates?

  • This issue is not a duplicate

Does it also happen in the desktop version?

  • This bug does not occur in the latest version of Anki Desktop

What are the steps to reproduce this bug?

  1. Add a PNG file from the Add/Edit screen.
  2. Crop the file using the AnkiDroid feature.

Expected behaviour

The image is silently converted to JPG. This would've been fine normally but I'm working with transparent images so JPG doesn't work for me. I expect one of these to happen instead:

  1. This is a bug and it should get fixed. Cropping PNGs work just fine.
  2. It's not a bug. AnkiDroid disables image cropping for PNGs and shows a snackbar.
  3. AnkiDroid allows image cropping for PNGs but informs the user that the file format has changed.

Debug info

AnkiDroid Version = 2.21alpha7 (96f58db59b4cc391d1bc92a7e48ad259d13f6682)
Backend Version = 0.1.48-anki24.11 (24.11 c47638ca36f99dd4f3b81ae82d964aec66e392e0)
Android Version = 11 (SDK 30)
ProductFlavor = full
Device Info = realme | realme | RMX2193 | RMX2193 | RMX2193 | mt6768
Webview User Agent = Mozilla/5.0 (Linux; Android 11; RMX2193 Build/RP1A.200720.011; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/131.0.6778.200 Mobile Safari/537.36
ACRA UUID = cf265e01-9693-407f-984d-61ddf9698fac
FSRS = 1.4.3 (Enabled: true)
Crash Reports Enabled = true

(Optional) Anything else you want to share?

No response

Research

  • I have checked the manual and the FAQ and could not find a solution to my issue
  • (Optional) I have confirmed the issue is not resolved in the latest alpha release (instructions)
@david-allison
Copy link
Member

@criticalAY FYI

@mikehardy
Copy link
Member

that's unexpected, we just worked near this area and did a lot of cropping / crop preview display etc work and the idea was to leave the source images less-transformed. We should leave PNG as PNG

@BrayanDSO
Copy link
Member

Previous work: #17020.

Can't we delegate it to an app with a proper editor (#14222) which won't try to convert the file to JPG? Maybe we could even ditch AnkiDroid's current crop activity with that

@mikehardy
Copy link
Member

Can't we delegate it to an app with a proper editor

I think having basic crop built in is nice, and it should work. It can already always be delegated to a "proper editor" (whatever that is? an endless discussion there...) by any user if they unbundle their image acquisition steps to "open camera, take photo, open editor, edit, save photo, then open ankidroid and attach that image". This is easy to understand ("just use your existing apps to do what you want then attach the result") vs a bunch of custom app picker work in AnkiDroid. I don't have any appetite for that...

What's missing is setting the output format, others have had this issue:

CanHub/Android-Image-Cropper#289 (comment)

If you don't set it, you get JPG by default, which will naturally not have any transparency etc as the format doesn't support it

https://github.com/CanHub/Android-Image-Cropper/blob/b91cb3f67897c41b9231bff19ded2d9ba046d15d/cropper/src/main/kotlin/com/canhub/cropper/CropImageOptions.kt#L72

@Scapesfear
Copy link

i will work on the issue.

@Scapesfear
Copy link

So upon inspection i found that we use a library canhub.cropper.CropImageView to crop images and it by default saves in JPEG format

fun croppedImageAsync(
    saveCompressFormat: CompressFormat = CompressFormat.JPEG,
    saveCompressQuality: Int = 90,
    reqWidth: Int = 0,
    reqHeight: Int = 0,
    options: RequestSizeOptions = RequestSizeOptions.RESIZE_INSIDE,
    customOutputUri: Uri? = null,
  ) {
    requireNotNull(mOnCropImageCompleteListener) { "mOnCropImageCompleteListener is not set" }
    startCropWorkerTask(
      reqWidth = reqWidth,
      reqHeight = reqHeight,
      options = options,
      saveCompressFormat = saveCompressFormat,
      saveCompressQuality = saveCompressQuality,
      customOutputUri = customOutputUri,
    )
  }

@mikehardy
Copy link
Member

@Scapesfear so upon inspection you found exactly what I wrote in the above comment? That's amazing

@Scapesfear
Copy link

Scapesfear commented Jan 17, 2025

@mikehardy, Love the sarcasm, actually! I went through a lot of references (#17020 -> (#16798 && #17014)) and got pretty deep into them. But then I thought, why not dive straight into the codebase and figure it out from there? Looks like I missed checking out your reference! If I had gotten stuck, I would’ve definitely taken a closer look at it.

P.S: Sorry for not looking at it. It would have saved some time.

@mikehardy
Copy link
Member

For what it's worth, I found it in about 5 seconds by just doing a repo search for PNG. Popped up immediately that it was an output format specification we were missing --> https://github.com/search?q=repo%3ACanHub%2FAndroid-Image-Cropper+png&type=code

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

No branches or pull requests

5 participants