mirror of
https://github.com/Swiftgram/Telegram-iOS.git
synced 2025-08-17 19:09:56 +00:00
44 lines
1.4 KiB
Swift
44 lines
1.4 KiB
Swift
#if os(macOS)
|
|
import PostboxMac
|
|
#else
|
|
import Postbox
|
|
#endif
|
|
|
|
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]
|
|
}
|
|
}
|