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

getPicture heic to jpeg support on Samsung Android phones #711

Closed
5 of 6 tasks
CGS38 opened this issue Feb 22, 2021 · 10 comments · Fixed by #731
Closed
5 of 6 tasks

getPicture heic to jpeg support on Samsung Android phones #711

CGS38 opened this issue Feb 22, 2021 · 10 comments · Fixed by #731

Comments

@CGS38
Copy link

CGS38 commented Feb 22, 2021

Issue Type

  • Bug Report
  • Feature Request
  • Support Question

Description

heic format is used by default by many Samsung camera.
But this format is not compatible with webview component.
The 'encodingType: Camera.EncodingType.JPEG' param in the navigator.camera.getPicture method does not convert heic image to jpeg.

Information

Command or Code

navigator.camera.getPicture(image_lib.onPhotoURISuccess,image_lib.onFailPhoto,
{ quality: 100,
targetWidth: width,
targetHeight: height,
encodingType: Camera.EncodingType.JPEG,
destinationType: Camera.DestinationType.FILE_URI,
correctOrientation : true,
sourceType: Camera.PictureSourceType.PHOTOLIBRARY });

Environment, Platform, Device

Android 10 , SM-A307FN

Version information

Cordova v10 Android v9
Camera plugin version 5.0.1

Checklist

  • I searched for already existing GitHub issues about this
  • I updated all Cordova tooling to their most recent version
  • I included all the necessary information above
@CodeWithOz
Copy link

@CGS38 do you currently have any workarounds for this?

@CGS38
Copy link
Author

CGS38 commented Mar 15, 2021

Unfortunately not...

@SnpDeveloper
Copy link

I am also looking for a workarround... any suggestions??

@SnpDeveloper
Copy link

Only way i was able to achieve / make heic file type to convert jpeg is modifying CameraLauncher.java

Line 718:
if (this.mediaType == VIDEO || !(JPEG_MIME_TYPE.equalsIgnoreCase(mimeType) || PNG_MIME_TYPE.equalsIgnoreCase(mimeType))) {

To
if (this.mediaType == VIDEO && !(JPEG_MIME_TYPE.equalsIgnoreCase(mimeType))) {

There should be a better way... for me this helped..

@PieterVanPoyer
Copy link
Contributor

@SnpDeveloper with the change of code in the CameraLauncher, the plugin will convert the Heic photo to a JPEG?
What happens when the Heic photo is not converted? Does the app crash, or it the photo just not shown?

@SnpDeveloper
Copy link

In my local testing with Samsung device uploaded image size got compressed didnt give me any error or crash.

@PieterVanPoyer
Copy link
Contributor

PieterVanPoyer commented May 23, 2021

You could try my branche for testing purposes.

npx cordova plugin remove cordova-plugin-camera
npx cordova plugin add https://github.com/PieterVanPoyer/cordova-plugin-camera/#feature/issue-711-heif-format

Please test it and give feedback.

@SnpDeveloper
Copy link

Thanks @PieterVanPoyer looks much cleaner code. I shall give a go and let you know tomorrow.

I havent seen the full changes yet. But one thing noticed in old code when mimeType was video or png it used return as filepath rather than file:///... i shall give a full check again and confirm all works expected.

Thanks again for quick turn arround.

@SnpDeveloper
Copy link

SnpDeveloper commented May 24, 2021

Thanks @PieterVanPoyer I have tested heic conversion, all seems to work fine.

But here are some of my observations, feel free to comment my thoughts

  1. bitmap conversion does a very excellent job.
    It converts GIF, BMP, JPG, PNG, HEIC to desired format (JPG in mycase)

  2. While failing to convert (TIF, HEIF formats) I am getting a clear exception - App is not crashing (again as i would except and a good thing) so easy for me to show File format not support error message in my app.

New changes you have made make sense preseving the encoding mimeType (JPG) extension.. a nice touch.

What i dont understand is why we are restricting support only to JPG, PNG and HEIC, as mentioned before GIF, BMP, JPG, PNG, HEIC formats are all working.

Some of my customer's upload BMP and GIF as well...

Correct me if I have missed anything.

@PieterVanPoyer
Copy link
Contributor

Hey @SnpDeveloper

So, the heic works just fine with the PR.

About your observations and thoughts. I agree with it mostly. But for this issue, I'd just like to fix and focus on the heic case. Fix and focus on the original issue.

For the other types, the behaviour is the same as before. (The original image and type is returned for Android) So it's a small improvement now.

If we decide to convert the other types to the encodingType too, it's more a breaking change. And I am not willing to take that risk now, it needs a little more discussion with other people I think. I suggest you make another issue for that. And I agree/assume that should be the purpose of the encodingType.

Hey @CGS38
Are you able to test this PR? And leave your testing results?

npx cordova plugin remove cordova-plugin-camera
npx cordova plugin add https://github.com/PieterVanPoyer/cordova-plugin-camera/#feature/issue-711-heif-format

Kind regards
Pieter

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants