fluttercandies / flutter_photo_manager

A Flutter plugin that provides images, videos, and audio abstraction management APIs without interface integration, available on Android, iOS, macOS and OpenHarmony.
https://pub.dev/packages/photo_manager
Apache License 2.0
671 stars 304 forks source link

The size of the image picked from we chat assets picker increasing the size of the image in IOS. #928

Closed Durgeshzibtek closed 1 year ago

Durgeshzibtek commented 1 year ago

When I pick an image from the gallery, I'm getting the File correctly but then I print its file size. I am getting: 22254847 which is about 22Mb. We checked the file size using the print(file.lengthSync()); When I check the image details in the gallery, I see 5.8Mb.

This happens only in the IOS.

Image_20230420_133003

Please anyone has a solution regarding this let us know.

venkateshavenki commented 1 year ago

I am also getting the above issue in we chat asset picker

AlexV525 commented 1 year ago

cc @CaiJingLong

CaiJingLong commented 1 year ago

The file method does not get the picture as it is, but through transcoding, which is a black box of apple system SDK.

https://github.com/fluttercandies/flutter_photo_manager/blob/23ea684c0eab9c383abe12c217f3975f346bebbb/lib/src/types/entity.dart#L683-L705

https://github.com/fluttercandies/flutter_photo_manager/blob/23ea684c0eab9c383abe12c217f3975f346bebbb/lib/src/internal/plugin.dart#L182-L195

https://github.com/fluttercandies/flutter_photo_manager/blob/23ea684c0eab9c383abe12c217f3975f346bebbb/ios/Classes/PMPlugin.m#L298-L308

https://github.com/fluttercandies/flutter_photo_manager/blob/23ea684c0eab9c383abe12c217f3975f346bebbb/ios/Classes/core/PMManager.m#L479-L480

https://github.com/fluttercandies/flutter_photo_manager/blob/23ea684c0eab9c383abe12c217f3975f346bebbb/ios/Classes/core/PMManager.m#L780-L787

The apple developer document about PHImageRequestOptions and I've annotated the image below, the options used by PhotoManager.

image image

Currently, PhotoManager does not provide an option to change it.

I can only speculate temporarily that the original image may not be stored in JPEG format, but in heic (although it is marked in jpeg format), and the jpeg image of 8000x5000 size should not be only 5MB. You can check the size using originFile.lengthSync of the same file.


My suggestion is to use thumbnailDataWithOption to get, size can use width and height, ThumbnailOption.ios provides parameters to modify them.

Durgeshzibtek commented 1 year ago

@CaiJingLong @AlexV525

We tried with the thumbnailDataWithOption but it's loose its original quality if we gave manual height and width.

element.thumbnailDataWithOption(ThumbnailOption.ios(size: const ThumbnailSize(5000, 5000)))

We need the actual size of the file. Because if we fixed the thumbnail Data With Option size width and height then it loses its quality and also for low MB or KB image files it becomes too low again.

AlexV525 commented 1 year ago

Use .originFile to obtain the raw file regardless of extension, compression, and metadata, e.g. get .heic if the original image is .heic, which is fit for your case. Regarding the HEIC handling, the plugin can only convert HEIC to JPEG through the .file getter, you'll need to manipulate the file on your own when using .originFile or .originBytes. It's very common that a HEIC compressed image is way smaller than a regular JPEG image, and in this case, 8192×5461 with 45MP camera config should deserve a 22MB's JPEG.

Durgeshzibtek commented 1 year ago

@AlexV525 In our case, .originFile is working fine.

Thank you