mirror of
https://github.com/hyperoslo/Cache.git
synced 2026-04-07 19:17:36 +00:00
Replaced the method UIImagePNGRepresentation(self) with self.pngData() Replaced the method UIImageJPEGRepresentation(self, 1.0) with self.jpegData(compressionQuality: 1.0)
30 lines
526 B
Swift
30 lines
526 B
Swift
import UIKit
|
|
|
|
/// Helper UIImage extension.
|
|
extension UIImage {
|
|
/// Checks if image has alpha component
|
|
var hasAlpha: Bool {
|
|
let result: Bool
|
|
|
|
guard let alpha = cgImage?.alphaInfo else {
|
|
return false
|
|
}
|
|
|
|
switch alpha {
|
|
case .none, .noneSkipFirst, .noneSkipLast:
|
|
result = false
|
|
default:
|
|
result = true
|
|
}
|
|
|
|
return result
|
|
}
|
|
|
|
/// Convert to data
|
|
func cache_toData() -> Data? {
|
|
return hasAlpha
|
|
? self.pngData()
|
|
: self.jpegData(compressionQuality: 1.0)
|
|
}
|
|
}
|