fix an issue where thumbnail is not properly generated

pull/1053/head
Ryan ZHAO 5 months ago
parent fac94f94be
commit 71de47e1b9

@ -104,7 +104,7 @@ public class ThumbnailService {
let thumbnailImage: UIImage
if attachment.isImage || attachment.isAnimated {
thumbnailImage = try MediaUtils.thumbnail(forImageAtPath: originalFilePath, maxDimension: maxDimension)
thumbnailImage = try MediaUtils.thumbnail(forImageAtPath: originalFilePath, maxDimension: maxDimension, type: attachment.contentType)
}
else if attachment.isVideo {
thumbnailImage = try MediaUtils.thumbnail(forVideoAtPath: originalFilePath, maxDimension: maxDimension)

@ -18,13 +18,13 @@ public enum MediaUtils {
public static let maxStillImageDimensions: UInt = 8 * 1024
public static let maxVideoDimensions: CGFloat = 3 * 1024
public static func thumbnail(forImageAtPath path: String, maxDimension: CGFloat) throws -> UIImage {
public static func thumbnail(forImageAtPath path: String, maxDimension: CGFloat, type: String) throws -> UIImage {
SNLog("thumbnailing image: \(path)")
guard FileManager.default.fileExists(atPath: path) else {
throw MediaError.failure(description: "Media file missing.")
}
guard Data.isValidImage(at: path) else {
guard Data.isValidImage(at: path, type: UTType(sessionMimeType: type)) else {
throw MediaError.failure(description: "Invalid image.")
}
guard let originalImage = UIImage(contentsOfFile: path) else {

Loading…
Cancel
Save