This commit is contained in:
fmodf 2024-07-16 17:13:16 +02:00
parent 6974ac5b7d
commit 7ca8af3bdc

View file

@ -28,14 +28,24 @@ final class FileProcessing {
// create thumbnail if not exists
switch localName.attachmentType {
case .image:
guard let image = UIImage(contentsOfFile: localUrl.path) else { return nil }
guard let image = UIImage(contentsOfFile: localUrl.path) else {
print("FileProcessing: Error loading image: \(localUrl)")
return nil
}
let targetSize = CGSize(width: Const.attachmentPreviewSize, height: Const.attachmentPreviewSize)
guard let thumbnail = scaleAndCropImage(image, targetSize) else { return nil }
guard let data = thumbnail.pngData() else { return nil }
guard let thumbnail = scaleAndCropImage(image, targetSize) else {
print("FileProcessing: Error scaling image: \(localUrl)")
return nil
}
guard let data = thumbnail.pngData() else {
print("FileProcessing: Error converting thumbnail of \(localUrl) to data")
return nil
}
do {
try data.write(to: thumbnailUrl)
return thumbnailFileName
} catch {
print("FileProcessing: Error writing thumbnail: \(error)")
return nil
}