ionic-team / capacitor

Build cross-platform Native Progressive Web Apps for iOS, Android, and the Web ⚡️
https://capacitorjs.com
MIT License
11.97k stars 995 forks source link

feat: Compress heavy images from files inputs, for fast upload #4869

Open Aarbel opened 3 years ago

Aarbel commented 3 years ago

Referring this discussion post: https://github.com/ionic-team/capacitor/discussions/4389

Problem

Image size reduction / compression is only available for Camera API.

Images coming from files inputs are basically not compressed. These images can be very heavy, so it can be very long to upload with slow connexion (and even with a fast one).

Feature request

Provide a capacitor API to compress images coming from files inputs on the front-end side before sending them to back-end.

It should be great to use native CPU on mobile, and not webview CPU which can be limited. 👉 Having the same returned type of files as Camera would also be great ! (‘Base64’, ‘DataUrl’ or ‘Uri’... and not Filelist).

Thanks a lot for your help !

Interesting libs

For web

For Capacitor / Cordova

sandstrom commented 3 years ago

I'm not totally against this, though it feels somewhat out of scope for capacitor.

For people who need this, it's totally possible to handle in JS-land today: https://github.com/nodeca/pica (we're doing this today with Capacitor, and it works well)

jcesarmobile commented 3 years ago

The input file on iOS already allows users to choose a quality, but it's on the users hand to compress the images or not, not on the developer hands.

For Android it should be possible to show some similar UI when picking the pictures and before returning the result to the WebView, but again, it would be on the user hands to choose the quality, not on the app developer hands.

If the image picked by the user is still too big, then the developer should use some js code or library to compress the images.

Aarbel commented 3 years ago

@jcesarmobile Do you have screenshot examples ?

jcesarmobile commented 3 years ago

I just noticed it's only available when you pick an existing picture, not possible when you take a new picture from the camera.

IMG_118E27EE1BAB-1

This is totally handled by the WKWebView and there is no way for us to compress the images from the camera from the native side. So if you want it to be available also for new pictures you should request it to Apple here