Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 5 additions & 7 deletions MastodonSDK/Sources/MastodonUI/Extension/UIImage.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,10 @@ extension UIImage {
}

extension UIImage {
public func normalized() -> UIImage? {
public func normalized() -> UIImage {
if imageOrientation == .up { return self }
UIGraphicsBeginImageContext(size)
draw(in: CGRect(origin: CGPoint.zero, size: size))
let image = UIGraphicsGetImageFromCurrentImageContext()
UIGraphicsEndImageContext()
return image
return UIGraphicsImageRenderer(size: size).image { _ in
draw(in: CGRect(origin: .zero, size: size))
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ extension AttachmentViewModel {
func load(input: Input) async throws -> Output {
switch input {
case .image(let image):
guard let data = image.normalized()?.pngData() else {
guard let data = image.normalized().pngData() else {
throw AttachmentError.invalidAttachmentType
}
return .image(data, imageKind: .png)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,15 +34,7 @@ public final class StripProgressLayer: CALayer {

return presentation()?.progress ?? self.progress
}()
// os_log(.info, log: .debug, "%{public}s[%{public}ld], %{public}s: progress: %.2f", ((#file as NSString).lastPathComponent), #line, #function, progress)

UIGraphicsBeginImageContextWithOptions(bounds.size, false, 0)
guard let context = UIGraphicsGetCurrentContext() else {
assertionFailure()
return
}
context.clear(bounds)

var rect = bounds
let newWidth = CGFloat(progress) * rect.width
let widthChanged = rect.width - newWidth
Expand All @@ -53,13 +45,11 @@ public final class StripProgressLayer: CALayer {
default:
break
}
let path = UIBezierPath(rect: rect)
context.setFillColor(tintColor.cgColor)
context.addPath(path.cgPath)
context.fillPath()

contents = UIGraphicsGetImageFromCurrentImageContext()?.cgImage
UIGraphicsEndImageContext()

contents = UIGraphicsImageRenderer(size: bounds.size).image { context in
tintColor.setFill()
context.fill(rect)
}.cgImage
}

}
Expand Down