achorein / expo-share-intent

πŸš€ Simple share intent in an Expo Native Module
MIT License
119 stars 10 forks source link

[QUESTION] Possible to retrieve more file information #34

Closed TomCorvus closed 2 months ago

TomCorvus commented 3 months ago

Hi πŸ‘‹πŸ»

Do you think is it possible to retrieve more information of files and get closer to the information retrieved by expo-image-picker for example? (width, height, size...)

I have to manipulate images on my project, photos on phones these days are too heavy and these informations would give me the possibility to compress and resize only biggest files and avoid using too much memory.

Thank you

achorein commented 3 months ago

πŸ€” interesting,

expo-image-picker use a native code in the ios and android module, as it stands, i don't have the information in share intent context, only the file path. to retrieve image info, i'd have to add the necessary logic on both platforms. i think it's better to manage this on the react native side, but don't know how for the moment. Getting image meta data (before ImageManipulator) should not need to load all the file in memory.

achorein commented 3 months ago

after some digging, i may be able to add something like this (for record) :

android (conditional for image mimeType

BitmapFactory.Options options = new BitmapFactory.Options();
options.inJustDecodeBounds = true;
BitmapFactory.decodeStream(
        getContext().getContentResolver().openInputStream(mPhotoUri),
        null,
        options);
int imageHeight = options.outHeight;
int imageWidth = options.outWidth;

ios

 if let imageSource = CGImageSourceCreateWithURL(url! as CFURL, nil) {
     if let imageProperties = CGImageSourceCopyPropertiesAtIndex(imageSource, 0, nil) as Dictionary? {
          let pixelWidth = imageProperties[kCGImagePropertyPixelWidth] as! Int
          let pixelHeight = imageProperties[kCGImagePropertyPixelHeight] as! Int
          print("the image width is: \(pixelWidth)")
          print("the image height is: \(pixelHeight)")
       }
   }

image should not load in memory that way and we can retrieve useful meta data (width / height).

πŸ€” wondering if it should be an option to activate in share intent and if it is really pertinent for this package.

TomCorvus commented 3 months ago

We need to know how this package is used in general. I think that in every project, the shared file has to be sent somewhere. On a server for example. And pictures nowadays are very heavy to be sent. For now, I'm using expo-image-manipulator on each image to get more information of it, but if share intent give us these informations in advance, it will avoid to manipulate them for nothing. It would be interesting to get others point of view on this.

achorein commented 3 months ago

@TomCorvus new version (v1.3.0) give the size (in octet) of shared files, it should be enough to resize or not the given image.

TomCorvus commented 3 months ago

@achorein Thanks for this new release. I tried it on an iOS emulator but it gives me an error when I use share extension and the app is opening.

Capture d’écran 2024-04-08 aΜ€ 09 48 41

Is there a way to get image dimensions btw? I think, in a real context, these information will be useful to send share intent files and manipulate them if dimensions are too important. If size is much important, the app should have these dimensions to resize image and keep the ratio. I am referring in particular to the parameters necessary to use the resize method of expo-image-manipulator which requires at least one of the dimensions. https://docs.expo.dev/versions/latest/sdk/imagemanipulator/#actionresize

Thanks again for this feat.

achorein commented 3 months ago

yes, the file size is a quick win for now, will work on image dimensions later.

for your error, can you give me more details ? i have checked for a simple image share from the gallery, do you have an specific use case ? (multiple file, from other app, file format, ...)

TomCorvus commented 3 months ago

I just try to share a single JPG image like ones that are on emulator by default. Everything works fine on Android but the crash occurs on iOS emulator and real iOS device. Downgrade to 1.2.1 version, and it fixes the problem. I tried to clear and rebuild my app without success.

achorein commented 3 months ago

Is the image heavy ? (Wondering about int max value for octet)

Can you open a bug for the file size error on ios ? Will keep this issue for new feature

TomCorvus commented 3 months ago

not needed. I forgot to update ShareViewController.swift. I'm on bare environment so I have to update manually this file.

achorein commented 2 months ago

@TomCorvus width and height are now available in v1.5.0 πŸŽ‰