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
26 changes: 26 additions & 0 deletions LambdaTimeline/Helpers/Extensions/UIImage+Ratio.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,30 @@ extension UIImage {
var ratio: CGFloat {
return size.height / size.width
}

/// Resize the image to a max dimension from size parameter
func imageByScaling(toSize size: CGSize) -> UIImage? {
guard size.width > 0 && size.height > 0 else { return nil }

let originalAspectRatio = self.size.width/self.size.height
var correctedSize = size

if correctedSize.width > correctedSize.width*originalAspectRatio {
correctedSize.width = correctedSize.width*originalAspectRatio
} else {
correctedSize.height = correctedSize.height/originalAspectRatio
}

return UIGraphicsImageRenderer(size: correctedSize, format: imageRendererFormat).image { context in
draw(in: CGRect(origin: .zero, size: correctedSize))
}
}

/// Renders the image if the pixel data was rotated due to orientation of camera
var flattened: UIImage {
if imageOrientation == .up { return self }
return UIGraphicsImageRenderer(size: size, format: imageRendererFormat).image { context in
draw(at: .zero)
}
}
}
1 change: 0 additions & 1 deletion LambdaTimeline/Model Controllers/PostController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,5 @@ class PostController {

let comment = Comment(text: text, author: currentUser)
post.comments.append(comment)

}
}
Loading