-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add support for renderscale * Fix
- Loading branch information
Showing
5 changed files
with
42 additions
and
3 deletions.
There are no files selected for viewing
File renamed without changes.
19 changes: 19 additions & 0 deletions
19
Sources/SnapshotTestCase/Extensions/UIImageExtensions+Resize.swift
This file contains 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 characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import UIKit | ||
|
||
extension UIImage { | ||
func resized(toScale scale: CGFloat) -> UIImage? { | ||
guard scale > 0, scale != 1 else { | ||
return self | ||
} | ||
return resized(toWidth: scale * size.width) | ||
} | ||
|
||
func resized(toWidth width: CGFloat, isOpaque: Bool = true) -> UIImage? { | ||
let canvas = CGSize(width: width, height: CGFloat(ceil(width / size.width * size.height))) | ||
let format = imageRendererFormat | ||
format.opaque = isOpaque | ||
return UIGraphicsImageRenderer(size: canvas, format: format).image { _ in | ||
draw(in: CGRect(origin: .zero, size: canvas)) | ||
} | ||
} | ||
} |
This file contains 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 characters
This file contains 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 characters
This file contains 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 characters