I’m using the Capacitor camera plugin to allow the user take a photo with the phone’s camera. I need to reduce the resolution of the photo so the images are a manageable size, since they need to be uploaded to our server. The only problem I’m having is getting the pixel resolution I want in the resulting images.
The desired resolution is simple: If the photo is landscape, then I want the width to be 1024 pixels (and scale the height proportionally). If the photo is portrait, then I want the height to be 1024 (and scale the width proportionally).
This seems to be impossible to achieve with the current camera plugin, unless I am missing something.
There are fields named “width” and a “height” in the “ImageOptions” interface that you can use to control the photo’s resolution. The problem is that I don’t know the width or height because it depends on the orientation of the camera (portrait vs landscape). I know I want the larger edge to be 1024 pixels.
However, there is also a field named “correctOrientation” in the “ImageOptions” interface. When this is set to true (the default), it auto-rotates the image so that a portrait-orientation photo is not sideways. I can set this field to false, to prevent auto-rotation. Now I can set the “width” field to 1024, and the image is scaled according to my requirements. But the problem now is that all portrait-orientation photos are sideways.
Is there a way to set up the ImageOptions field values so that I get both of the following:
- The longer edge is 1024 pixels, and the shorter edge is scaled proportionally
AND - The photo is properly rotated for portrait/landscape orientation
Thank you for any guidance you can provide.