PHImageManager requesting exact sized images not always working

374 views Asked by At

I'm actually puzzled. I want to retrieve local images from the photos library and want to resize them to 266x266 pixels. The code is working as expected on my iPhone12 pro 14.6, and on an iPad Pro (iPadOS 14.6) but not on an iPhone11 iOS15.

let imageSize = CGSize(width: 266, height: 266)
   
print("asset size: \(asset.pixelWidth) x \(asset.pixelHeight)")

let fullsizeOptions = PHImageRequestOptions()
fullsizeOptions.deliveryMode = .highQualityFormat
fullsizeOptions.isSynchronous = false
fullsizeOptions.isNetworkAccessAllowed = true
fullsizeOptions.resizeMode = .exact
            
let requestId = manager.requestImage(for: asset, targetSize: imageSize, contentMode: .aspectFill, options: fullsizeOptions, resultHandler: { (image, info) -> Void in
   guard image != nil else {
      print(" detailed image fetch (\(asset.localIdentifier)) failed")
      return
   }
                
   print ("real image size: \(image?.size)")
})

On iPhone11 I receive the following log:

asset size: 3024 x 4032
real image size: Optional((266.0, 354.0))

As you can see the real image size is not 266x266 - as expected. On my iPhone12 and on an iPad this code is working as expected. Any idea what's going wrong here? I had the very same problem with the same iPhone11 with iOS 14.4 - then I updated this one because I thought this is an iOS bug. But with iOS15 I can reproduce the same behaviour.. and now I'm lost. Any ideas?

Thanks a lot!

Cheers Dennis

0

There are 0 answers