Sdwebimage: UIImage width and height 0 with sd_setImage(with: URL)

Created on 21 Nov 2019  ·  9Comments  ·  Source: SDWebImage/SDWebImage

New Issue Checklist

Issue Info

Info | Value |
-------------------------|-------------------------------------|
Platform Name | ios
Platform Version | 13.1.3
SDWebImage Version | 5.3.1
Integration Method | cocoapods
Xcode Version | Xcode 11.2.1
Repro rate | all the time (100%)

Issue Description and Steps

The image.size property of all images have size.height=0 and size.width=0. However, cgImage.width has size greater than 0. Also, all images must have some width and height as they are being displayed correctly within the UIImageView.

profileImageView.sd_setImage(with: URL(string: user.profileImageUrl)) { [weak self] (image, err, cachType, url) in 
            guard let image = image else { return }

            let imageSize = image.size
            let height = imageSize.height
            let width = imageSize.width

            print("cgImage width: \(image.cgImage?.width)")
            print("image width: \(width)")
            print("image height: \(height)")
}
bug stale

All 9 comments

If the UIImage.size is (0, 0), it should always been marked as failed and report an Error:

https://github.com/SDWebImage/SDWebImage/blob/5.3.1/SDWebImage/Core/SDWebImageDownloaderOperation.m#L466

This SDWebImageError.badImageData error.

Can you provide me the demo to re-produce this issue ? Or something URL can trigger this issue. Sounds really strange that one UIImage is CGImage based, but have different size (0) compared to CGImage's size.

Thanks for the fast reply!

I created an example project to demo the bug, however the bug isn't occurring in the demo despite SDWebImage being used in the exact same way as the project in which it is occurring (as far as I can see).

Are there any other steps you'd suggest I try so that I can debug the issue?

Interestingly, even when instantiating UIImage with UIImage(named: ) and an image from the asset catalog, the size of the UIImage instance is (0,0). This makes it unlikely that the issue is due to SDWebImage.

Still very puzzling though.

I guess this related to something about debugger issue ? Xcode issue ? Or are you using the vector format image ?

iOS 13 introduced with symbol image, which may not have a intrinsicContentSize (0,0). Because it can scale at anysize.

But SDWebImage Core repo does not load that image, and if it's downloaded by network, I can ensure a SDWebImageError.badImageData will report to the user to mark it as failed

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. If this is still an issue, please make sure it is up to date and if so, add a comment that this is still an issue to keep it open. Thank you for your contributions.

Found the issue, it was due to configuration elsewhere. Thanks for the assistance.

Found the issue, it was due to configuration elsewhere. Thanks for the assistance.

What’s the configuration cause this ? The coders manager register ? Or HTTP header ?

It was a UIImage issue rather than an image with SDWebImage. We had a UIImage extension that was overriding the image size property. 🤦‍♂️

It was a UIImage issue rather than an image with SDWebImage. We had a UIImage extension that was overriding the image size property. 🤦‍♂️

This extention sound crazy...What does that used for ? (Actually, the better idea is to create a new UIImage with same underlaying CGImage, which can be shared across different UIImage instance, no overhead for RAM)

Was this page helpful?
0 / 5 - 0 ratings