damus

nostr ios client
git clone git://jb55.com/damus
Log | Files | Refs | README | LICENSE

commit 49c8d63d0b5699cd10c85ba223ed634177b7cd64
parent 774da239b92ed630fbf91fce42d9e233661c0d7f
Author: Daniel D’Aquino <daniel@daquino.me>
Date:   Thu,  8 Aug 2024 10:18:52 -0700

Merge pull request #2365 from danieldaquino/#2341

Fix crash with blurhashes with reported dimension of 0x0
Diffstat:
Mdamus/Util/Images/ImageMetadata.swift | 8+++++---
1 file changed, 5 insertions(+), 3 deletions(-)

diff --git a/damus/Util/Images/ImageMetadata.swift b/damus/Util/Images/ImageMetadata.swift @@ -60,7 +60,8 @@ struct ImageMetadata: Equatable { func process_blurhash(blurhash: String, size: CGSize?) async -> UIImage? { let res = Task.detached(priority: .low) { - let size = get_blurhash_size(img_size: size ?? CGSize(width: 100.0, height: 100.0)) + let default_size = CGSize(width: 100.0, height: 100.0) + let size = get_blurhash_size(img_size: size ?? default_size) ?? default_size guard let img = UIImage.init(blurHash: blurhash, size: size) else { let noimg: UIImage? = nil return noimg @@ -135,7 +136,8 @@ extension UIImage { } } -func get_blurhash_size(img_size: CGSize) -> CGSize { +func get_blurhash_size(img_size: CGSize) -> CGSize? { + guard img_size.width > 0 && img_size.height > 0 else { return nil } return CGSize(width: 100.0, height: (100.0/img_size.width) * img_size.height) } @@ -145,7 +147,7 @@ func calculate_blurhash(img: UIImage) async -> String? { } let res = Task.detached(priority: .low) { - let bhs = get_blurhash_size(img_size: img.size) + let bhs = get_blurhash_size(img_size: img.size) ?? CGSize(width: 100.0, height: 100.0) let smaller = img.resized(to: bhs) guard let blurhash = smaller.blurHash(numberOfComponents: (5,5)) else {