Skip to content

Commit

Permalink
Merge pull request #91 from Automattic/andrewdmontgomery/cleanup-Imag…
Browse files Browse the repository at this point in the history
…eSize

Move pixels conversion into ImageSize extension
  • Loading branch information
andrewdmontgomery authored Mar 5, 2024
2 parents 258ac46 + 64d8e6b commit 8bc0c39
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 9 deletions.
10 changes: 1 addition & 9 deletions Sources/Gravatar/Options/ImageQueryOptions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -45,15 +45,7 @@ public struct ImageQueryOptions {
self.rating = rating
self.forceDefaultImage = forceDefaultImage
self.defaultImage = defaultImage

switch preferredSize {
case .pixels(let pixels):
preferredPixelSize = pixels
case .points(let points):
preferredPixelSize = Int(points * scaleFactor)
case .none:
preferredPixelSize = nil
}
self.preferredPixelSize = preferredSize?.pixels(scaleFactor: scaleFactor)
}
}

Expand Down
11 changes: 11 additions & 0 deletions Sources/Gravatar/Options/ImageSize.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,14 @@ public enum ImageSize {
/// The returned image's size in pixels will be of the exact value passed here.
case pixels(Int)
}

extension ImageSize {
func pixels(scaleFactor: CGFloat) -> Int {
switch self {
case .pixels(let pixels):
pixels
case .points(let points):
Int(points * scaleFactor)
}
}
}

0 comments on commit 8bc0c39

Please sign in to comment.