mirror of
https://github.com/Swiftgram/Telegram-iOS.git
synced 2025-08-18 03:20:09 +00:00
40 lines
1.4 KiB
Swift
40 lines
1.4 KiB
Swift
import TelegramCore
|
|
|
|
public 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]
|
|
}
|
|
}
|
|
|
|
public 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]
|
|
}
|
|
}
|