From e0ffa1d9c5fcac694c7c41d02fe6f5b6b3401250 Mon Sep 17 00:00:00 2001 From: Shadowfacts Date: Sat, 29 Oct 2022 11:47:53 -0400 Subject: [PATCH] Cap blurhash image size at 32x32 --- .../TrendingLinkCardCollectionViewCell.swift | 12 ++++++++---- .../Screens/Explore/TrendingLinkTableViewCell.swift | 10 +++++++--- Tusker/Views/Status/StatusCardView.swift | 13 ++++++++----- 3 files changed, 23 insertions(+), 12 deletions(-) diff --git a/Tusker/Screens/Explore/TrendingLinkCardCollectionViewCell.swift b/Tusker/Screens/Explore/TrendingLinkCardCollectionViewCell.swift index a3d81596..08a562eb 100644 --- a/Tusker/Screens/Explore/TrendingLinkCardCollectionViewCell.swift +++ b/Tusker/Screens/Explore/TrendingLinkCardCollectionViewCell.swift @@ -100,15 +100,19 @@ class TrendingLinkCardCollectionViewCell: UICollectionViewCell { guard let hash = card.blurhash else { return } - let imageViewSize = self.thumbnailView.bounds.size AttachmentView.queue.async { [weak self] in let size: CGSize if let width = card.width, let height = card.height { - size = CGSize(width: width, height: height) + let aspectRatio = CGFloat(width) / CGFloat(height) + if aspectRatio > 1 { + size = CGSize(width: 32, height: 32 / aspectRatio) + } else { + size = CGSize(width: 32 * aspectRatio, height: 32) + } } else { - size = imageViewSize + size = CGSize(width: 32, height: 32) } - + guard let preview = UIImage(blurHash: hash, size: size) else { return } diff --git a/Tusker/Screens/Explore/TrendingLinkTableViewCell.swift b/Tusker/Screens/Explore/TrendingLinkTableViewCell.swift index a7017c23..ce7f1b8f 100644 --- a/Tusker/Screens/Explore/TrendingLinkTableViewCell.swift +++ b/Tusker/Screens/Explore/TrendingLinkTableViewCell.swift @@ -143,13 +143,17 @@ class TrendingLinkTableViewCell: UITableViewCell { guard let hash = card.blurhash else { return } - let imageViewSize = self.thumbnailView.bounds.size AttachmentView.queue.async { [weak self] in let size: CGSize if let width = card.width, let height = card.height { - size = CGSize(width: width, height: height) + let aspectRatio = CGFloat(width) / CGFloat(height) + if aspectRatio > 1 { + size = CGSize(width: 32, height: 32 / aspectRatio) + } else { + size = CGSize(width: 32 * aspectRatio, height: 32) + } } else { - size = imageViewSize + size = CGSize(width: 32, height: 32) } guard let preview = UIImage(blurHash: hash, size: size) else { diff --git a/Tusker/Views/Status/StatusCardView.swift b/Tusker/Views/Status/StatusCardView.swift index 7bcb8dfa..089be89c 100644 --- a/Tusker/Views/Status/StatusCardView.swift +++ b/Tusker/Views/Status/StatusCardView.swift @@ -168,18 +168,21 @@ class StatusCardView: UIView { private func loadBlurHash() { guard let card = card, let hash = card.blurhash else { return } - let imageViewSize = self.imageView.bounds.size - AttachmentView.queue.async { [weak self] in guard let self = self else { return } let size: CGSize if let width = card.width, let height = card.height { - size = CGSize(width: width, height: height) + let aspectRatio = CGFloat(width) / CGFloat(height) + if aspectRatio > 1 { + size = CGSize(width: 32, height: 32 / aspectRatio) + } else { + size = CGSize(width: 32 * aspectRatio, height: 32) + } } else { - size = imageViewSize + size = CGSize(width: 32, height: 32) } - + guard let preview = UIImage(blurHash: hash, size: size) else { return }