capacitor-plugins icon indicating copy to clipboard operation
capacitor-plugins copied to clipboard

bug: PWA Camera plugin cameraOptions ignored

Open LuisPerez94 opened this issue 4 years ago • 16 comments

Bug Report

Capacitor Version

npx cap doctor output: Capacitor Doctor

Latest Dependencies:

@capacitor/cli: 2.0.0

@capacitor/core: 2.0.0

@capacitor/android: 2.0.0

@capacitor/electron: 2.0.0

@capacitor/ios: 2.0.0

Installed Dependencies:

@capacitor/ios not installed

@capacitor/electron not installed

@capacitor/cli 2.0.0

@capacitor/core 2.0.0

@capacitor/android 2.0.0

[success] Android looking great! �👌

Affected Platform(s)

  • Web

Current Behavior

it seems when I use the getPhoto API with it's options quality, width and height those get ignored by the android camera. I recieve a big size image and the dimensions are not what I used regarding I expect a small image.

I was testing with my laptop camera and it was work Ok ( iI think is beacause is a VGA), and when I started to test on my phone (a huawei mate 10) I realized.

Expected Behaivor

It would be great that the camera method returns a image with the correct properties predifined.

I need this to get an image with at least 500kb size.

Sample Code or Sample Application Repo

image = await Camera.getPhoto({
      quality: 10,
      height: 1280,
      width: 960,
      allowEditing: false,
      saveToGallery: true,
      direction: CameraDirection.Rear,
      source: CameraSource.Camera,
      resultType: CameraResultType.DataUrl
    });

but when I want to upload mi image to internet its weight is to big

image

Reproduction Steps

Other Technical Details

npm --version output: 6.13.4

node --version output:v 12.14.1

LuisPerez94 avatar Apr 07 '20 02:04 LuisPerez94

Is it when you run as web or as android? In the title you said pwa, but you checked android as platform and not web

jcesarmobile avatar Apr 07 '20 08:04 jcesarmobile

Is it when you run as web or as android? In the title you said pwa, but you checked android as platform and not web

Sorry, is in the mobile browser. I'm using Chrome and my phone is Huawei mate 10. I supose it happens me now because my phone camera is powerful than my laptop camera.

LuisPerez94 avatar Apr 07 '20 13:04 LuisPerez94

yeah, web camera doesn't support all the native features

jcesarmobile avatar Apr 07 '20 14:04 jcesarmobile

Can you tell me what file it needs to be updated?. maybe I can help with a PR.

LuisPerez94 avatar Apr 07 '20 14:04 LuisPerez94

could be https://github.com/ionic-team/capacitor/blob/master/core/src/web/camera.ts or could be this package the plugin uses for taking the pictures https://github.com/ionic-team/pwa-elements

jcesarmobile avatar Apr 07 '20 14:04 jcesarmobile

Any chance to improve Camera capabilities to resolve this issue?

Thanks

vosecek avatar Nov 29 '20 21:11 vosecek

Hello. In my case, always opens the front camera by default. Any workaround to open the rear camera by default? Thanks

leocharrua avatar Jan 28 '21 21:01 leocharrua

I am having the same issue with PWA Camera on web app, but in mobile app, the same code took the options works very well.

Duy-Nguyen-Globals avatar Feb 09 '21 01:02 Duy-Nguyen-Globals

Sorry @Duy-Nguyen-Globals, with "mobile app", are you meaning generating APK for Android, for example, aren't you? Because, If I run the PWA in Windows, Android or iOS like PWA or Web App, I allways get the front camera for default and the settings didn't work.

leocharrua avatar Feb 09 '21 09:02 leocharrua

Yes, I deployed to Android, iOS by capacitor, and on mobile OS, Camera Plugin worked as expect. In case open using application on mobile Chrome or Safari, the Camera Plugin simply ignores all the options and turn on the Front facing Camera as default, even if I switch to Rear Camera, the plugin always picked the tele Camera or the super wide camera other than the main best quality Camera when using multi-cam Smartphone. Capacitor version: "@capacitor/android": "^2.4.6", "@capacitor/core": "^2.4.6", "@capacitor/ios": "^2.4.6",

Duy-Nguyen-Globals avatar Feb 10 '21 02:02 Duy-Nguyen-Globals

My PWA is for a small bussiness and there is not chance (nor sense), to publish in app markets. I think this must be resolved (I don't know by who) ... but in PWAs the camera must work ok.

leocharrua avatar Feb 10 '21 14:02 leocharrua

Would a PR be appreciated to enable setting width and height? As far as I can tell it's the file https://github.com/ionic-team/capacitor-plugins/blob/main/camera/src/web.ts. I would provide an implementation for the web using canvas. Also, in case I create a PR, which version should it be based on?

teggno avatar Feb 17 '21 07:02 teggno

My PWA is for a small bussiness and there is not chance (nor sense), to publish in app markets. I think this must be resolved (I don't know by who) ... but in PWAs the camera must work ok.

Yes, same problem and requirement. How to enable, by default, the rear camera on web/pwa application?

arcadeJHS avatar Feb 25 '21 11:02 arcadeJHS

Hello. In my case, always opens the front camera by default. Any workaround to open the rear camera by default? Thanks

I was facing the same problem, and as a solution I changed the value of the facingMode variable in the constructor in the CameraPWA class. Module path: \node_modules@ionic\pwa-elements\dist\esm\pwa-camera.entry.js

With the file open, we should search for the CameraPWA class and let the variable initialize with the following value (facingMode = 'environment'). With that the smartphone camera started on the main.

Dr141 avatar Apr 22 '21 00:04 Dr141

The problem for options not being respected still exists. Web browsers seem to ignore the option of camera direction. This issue still needs attention.

KasTasElis avatar Sep 20 '21 11:09 KasTasElis

Hello. Any advance or workarround? Thanks

leocharrua avatar Nov 26 '21 20:11 leocharrua