Compress the images taken by Camera

Hi,
I developed an app where the user can add pictures to the data they register. Either by taking a new one with the camera component or picking an existing one.
After a lot of head scratching I got the whole lot running (SAF, permissions, and so on) but the size of the data can explode if the user takes too many pictures.
Is there a way to compress the pictures taken, or limit the size of it ? I tried the Image Compressor from DevYB but it doesn't look to be android 13+ compatible : it asks for the WRITE_EXTERNAL_STORAGE permission, and on android 13+, well, it shouldn't and has no hope to be granted it.

Here are a couple of ideas:

Thanks, interesting ! but I remark that finding the original dimensions to resize the pic relies on the file being a JPEG format. Does anyone know whether the camera component always register a JPEG picture, on all devices ?

Yes, the camera should return a jpeg.

(The imageConvertor extension will handle png and webp images as well)

Why SAF? Show your blocks.

Oh I misspoke, I did use SAF but not for pictures, for non-media documents (ZIP and CSV) the user downloads, so that I had to go pick in the download directory.
For media documents the headscratching went about the permissions as my app is used with various android versions.

On Android < 13 you must request READ_EXTERNAL_STORAGE to access images in the external storage (outside the ASD). On Android 13+ you must request READ_MEDIA_IMAGES. If you want to change these images you must request WRITE_EXTERNAL_STORAGE on Android < 11. On Android 11+ you must copy the image to the ASD and do the compression there. On Android 11+ you can only change/compress/resize images that ware created by the app itself.

See also: How to access non-media & media files on Android 11+

On Android 11+ you must copy the image to the ASD and do the compression there. On Android 11+ you can only change/compress/resize images that ware created by the app itself.

About that, I suppose that the camera component will create images in the ASD of course. It looks like they are all put in a /Pictures/ directory in the ASD, is that it ?

So I went with Timai's idea about Taifun's Image extension. It almost works, but sends a "the file to resize does not exist" which looks very weird. Here are the do-it commented blocks:


And looking in the ASD with a file explorer, a brand new "file:" directory has appeared in ASD, and the extension seems to have created the complete directories path from there : file/storage/emulated/0/Android/data/edu.mit.appinventor/files/Pictures/

But my image path is absolute, starts with file:/// as requested by Taifun's extension.
Did I do something wrong ?

the latest version 5 expects the image in the ASD directly, but not in one of its subfiolders

download the previous version 4 from the Download section here App Inventor Extensions: Image | Pura Vida Apps

Taifun

As you said, "... or pick an existing one". And this one would be in the Shared folder /DCIM/Camera/ and not in die ASD.