mirror of
https://github.com/Swiftgram/Telegram-iOS.git
synced 2025-08-17 19:09:56 +00:00
39 lines
1.3 KiB
Swift
39 lines
1.3 KiB
Swift
|
|
func smallestImageRepresentation(_ representations: [TelegramMediaImageRepresentation]) -> TelegramMediaImageRepresentation? {
|
|
if representations.count == 0 {
|
|
return nil
|
|
} else {
|
|
var dimensions = representations[0].dimensions
|
|
var index = 0
|
|
|
|
for i in 1 ..< representations.count {
|
|
let representationDimensions = representations[i].dimensions
|
|
if representationDimensions.width < dimensions.width && representationDimensions.height < dimensions.height {
|
|
dimensions = representationDimensions
|
|
index = i
|
|
}
|
|
}
|
|
|
|
return representations[index]
|
|
}
|
|
}
|
|
|
|
func largestImageRepresentation(_ representations: [TelegramMediaImageRepresentation]) -> TelegramMediaImageRepresentation? {
|
|
if representations.count == 0 {
|
|
return nil
|
|
} else {
|
|
var dimensions = representations[0].dimensions
|
|
var index = 0
|
|
|
|
for i in 1 ..< representations.count {
|
|
let representationDimensions = representations[i].dimensions
|
|
if representationDimensions.width > dimensions.width && representationDimensions.height > dimensions.height {
|
|
dimensions = representationDimensions
|
|
index = i
|
|
}
|
|
}
|
|
|
|
return representations[index]
|
|
}
|
|
}
|