mirror of
https://github.com/neon443/StickerSlack.git
synced 2026-11-30 12:44:51 +00:00
updated resizing and gonna do gifs
fix crazy lag when changing pack name fix ui sizing issue on stickerpicker
This commit is contained in:
5 files changed
+41
-14
No files matched your search
@@ -61,6 +61,7 @@ extension StickerProtocol {
|
||||
|
||||
nonisolated
|
||||
func downloadImage() async throws {
|
||||
let targetSize = CGSize(width: 500, height: 500)
|
||||
if let data = try? await Data(contentsOf: localImageURL),
|
||||
let _ = UIImage(data: data) {
|
||||
return
|
||||
@@ -68,15 +69,20 @@ extension StickerProtocol {
|
||||
|
||||
var (data, _) = try await URLSession.shared.data(from: remoteImageURL)
|
||||
|
||||
print(await GifManager.gifFrom(data: data).count)
|
||||
|
||||
if let uiImage = UIImage(data: data),
|
||||
let cgImage = uiImage.cgImage,
|
||||
await !self.localImageURLString.contains(".gif"),
|
||||
cgImage.width < 500 || cgImage.height < 500 {
|
||||
if await self.localImageURLString.suffix(4) == ".gif" {
|
||||
|
||||
} else {
|
||||
data = await resize(image: uiImage, to: CGSize(width: 500, height: 500)).pngData()!
|
||||
await GifManager.gifFrom(data: data).count == 1 {
|
||||
data = await resize(image: uiImage, to: targetSize).pngData()!
|
||||
} else {
|
||||
var frames: [(frame: CGImage, showFor: Double)] = []
|
||||
for frame in await GifManager.gifFrom(data: data) {
|
||||
frames.append((
|
||||
await resize(image: UIImage(cgImage: frame.frame), to: targetSize).cgImage!,
|
||||
frame.showFor
|
||||
))
|
||||
}
|
||||
data = await GifManager.dataFrom(frames: frames)!
|
||||
}
|
||||
try! await data.write(to: localImageURL)
|
||||
return
|
||||
|
||||