ivpusic / react-native-image-crop-picker

iOS/Android image picker with support for camera, video, configurable compression, multiple images and cropping
MIT License
6.15k stars 1.57k forks source link

[iOS] Blank image returned when compress size above certain value #2074

Open markholland opened 4 months ago

markholland commented 4 months ago

Version

Tell us which versions you are using:

Platform

Tell us to which platform this issue is related

Expected behaviour

Picking an image with options:

{
  compressImageMaxHeight: 2049,
  compressImageMaxWidth: 2049
}

To return the resized image.

Actual behaviour

Returns a blank image

Steps to reproduce

1.

Call ImagePicker.openPicker() with options:

{
  compressImageMaxHeight: 2049,
  compressImageMaxWidth: 2049
}

2.

Select an image with the picker

3.

Open image referenced by result.path. It will be blank instead of resized original image.

Description

We encountered an issue after upgrading to versions >= 0.41.0.

We are setting compressImageMaxHeight and compressImageMaxWidth, the issue is that the resized image would be blank.

We narrowed it down to this commit. On the surface it looked like an important change but definitely was the cause of our issue.

After further debugging we discovered that the issue would only occur for values of compressImageMaxHeight/compressImageMaxWidth >= 2049 on iPhone 15 Pro

At which point we noticed a log in the debugger 8196 by 6147 iosurface is too large for GPU

This lead us to issues such as https://stackoverflow.com/questions/61263161/why-use-a-lot-of-memory-when-drawing-image-with-uigraphicsimagerenderer and https://stackoverflow.com/questions/77150918/how-do-i-prevent-uigraphicsimagerenderer-image-from-crashing-when-using-uiimag

Applying the fix found there resolved the issue for us.

Example app can be found here. Image will be blank unless compress size is reduced.

PR with fix here

wrldh commented 1 month ago

I confirm that issue exists. Tested on physical iPhone 14 iOS 17. Small images are okay, larger ones appear to be blank. Using library version 0.40.3 it still works okay with the same files. Using v. 0.41.2 images appear to be blank after resizing.

compressImageMaxHeight and compressImageMaxWidth are set to 3000 in my case.