diff --git a/TelegramUI/PhotoResources.swift b/TelegramUI/PhotoResources.swift index f70bf3caa9..7fe801602c 100644 --- a/TelegramUI/PhotoResources.swift +++ b/TelegramUI/PhotoResources.swift @@ -6,6 +6,7 @@ import AVFoundation import ImageIO import TelegramUIPrivateModule import TelegramCore +import WebP private enum ResourceFileData { case data(Data) @@ -2119,13 +2120,20 @@ func chatMessageImageFile(account: Account, fileReference: FileMediaReference, t } var thumbnailImage: CGImage? - if let thumbnailData = thumbnailData, let imageSource = CGImageSourceCreateWithData(thumbnailData as CFData, nil), let image = CGImageSourceCreateImageAtIndex(imageSource, 0, nil) { - if fullSizeImage == nil { - imageOrientation = imageOrientationFromSource(imageSource) - } - thumbnailImage = image - if thumbnail { - fittedSize = CGSize(width: CGFloat(image.width), height: CGFloat(image.height)).aspectFilled(arguments.boundingSize) + if let thumbnailData = thumbnailData { + if let imageSource = CGImageSourceCreateWithData(thumbnailData as CFData, nil), let image = CGImageSourceCreateImageAtIndex(imageSource, 0, nil) { + if fullSizeImage == nil { + imageOrientation = imageOrientationFromSource(imageSource) + } + thumbnailImage = image + if thumbnail { + fittedSize = CGSize(width: CGFloat(image.width), height: CGFloat(image.height)).aspectFilled(arguments.boundingSize) + } + } else if let image = WebP.convert(fromWebP: thumbnailData) { + thumbnailImage = image.cgImage + if thumbnail { + fittedSize = CGSize(width: CGFloat(image.size.width), height: CGFloat(image.size.height)).aspectFilled(arguments.boundingSize) + } } }