Skip to content

Commit

Permalink
Merge pull request #649 from onevcat/fix/cg-cropping-scale
Browse files Browse the repository at this point in the history
Crop scaled rect for CGImage
  • Loading branch information
onevcat authored Apr 11, 2017
2 parents bfc075b + 0691a38 commit 54160d9
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion Sources/Image.swift
Original file line number Diff line number Diff line change
Expand Up @@ -437,7 +437,7 @@ extension Kingfisher where Base: Image {
}

let rect = self.size.kf.constrainedRect(for: size, anchor: anchor)
guard let image = cgImage.cropping(to: rect) else {
guard let image = cgImage.cropping(to: rect.scaled(scale)) else {
assertionFailure("[Kingfisher] Cropping image failed.")
return base
}
Expand Down Expand Up @@ -747,6 +747,13 @@ extension CGSizeProxy {
}
}

extension CGRect {
func scaled(_ scale: CGFloat) -> CGRect {
return CGRect(x: origin.x * scale, y: origin.y * scale,
width: size.width * scale, height: size.height * scale)
}
}

extension Comparable {
func clamped(to limits: ClosedRange<Self>) -> Self {
return min(max(self, limits.lowerBound), limits.upperBound)
Expand Down

0 comments on commit 54160d9

Please sign in to comment.