Created
July 3, 2022 20:02
-
-
Save kylehowells/c92bbb7471f8ca919084817113815285 to your computer and use it in GitHub Desktop.
Revisions
-
kylehowells created this gist
Jul 3, 2022 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,21 @@ private func AVMakeRectFill(aspectRatio: CGSize, insideRect boundingRect: CGRect) -> CGRect { let targetSize = boundingRect.size if targetSize == .zero { return .zero } let widthRatio = targetSize.width / aspectRatio.width let heightRatio = targetSize.height / aspectRatio.height let scalingFactor = max(widthRatio, heightRatio) let newSize = CGSize( width: aspectRatio.width * scalingFactor, height: aspectRatio.height * scalingFactor ) let origin = CGPoint( x: (targetSize.width - newSize.width) / 2, y: (targetSize.height - newSize.height) / 2 ) return CGRect(origin: origin, size: newSize) }