ayoub
ayoub

Reputation: 37

Swift 4 -Check if image HD or no

I have app Upload images to firebase and I want check if image 720p HD or no because I want show user only available 720p or 1080p.

If anyone know how to do this please let me know.

Upvotes: 1

Views: 202

Answers (1)

Razi Tiwana
Razi Tiwana

Reputation: 1435

Use this extention method if you have an UIImage

extension UIImage {

    func isImageHD() -> Bool {

        let heightInPoints = self.size.height
        let heightInPixels = heightInPoints * self.scale

        return heightInPixels >= 720
    }
}

you can use this where you have the UIImage

let image = // Your image 

if image.isImageHD() {

// Upload Image 

} else {

// Show Pop up or something

}

Upvotes: 1

Related Questions