Remove Kingfisher (#858)

* Replace image type detection

* Replace image processing

* Remove Kingfisher
This commit is contained in:
woxtu 2023-01-11 17:10:04 +09:00 committed by GitHub
parent ec2f819e63
commit 864ec73a9a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 12 additions and 25 deletions

View File

@ -13,7 +13,6 @@
- [Fuzi](https://github.com/cezheng/Fuzi)
- [Kanna](https://github.com/tid-kijyun/Kanna)
- [KeychainAccess](https://github.com/kishikawakatsumi/KeychainAccess.git)
- [Kingfisher](https://github.com/onevcat/Kingfisher)
- [MetaTextKit](https://github.com/TwidereProject/MetaTextKit)
- [Nuke-FLAnimatedImage-Plugin](https://github.com/kean/Nuke-FLAnimatedImage-Plugin)
- [Nuke](https://github.com/kean/Nuke)

View File

@ -73,15 +73,6 @@
"version": "4.2.2"
}
},
{
"package": "Kingfisher",
"repositoryURL": "https://github.com/onevcat/Kingfisher.git",
"state": {
"branch": null,
"revision": "44e891bdb61426a95e31492a67c7c0dfad1f87c5",
"version": "7.4.1"
}
},
{
"package": "MetaTextKit",
"repositoryURL": "https://github.com/TwidereProject/MetaTextKit.git",

View File

@ -56,7 +56,6 @@ let package = Package(
.package(url: "https://github.com/woxtu/UIHostingConfigurationBackport.git", from: "0.1.0"),
.package(url: "https://github.com/SDWebImage/SDWebImage.git", from: "5.12.0"),
.package(url: "https://github.com/eneko/Stripes.git", from: "0.2.0"),
.package(url: "https://github.com/onevcat/Kingfisher.git", from: "7.4.1"),
.package(url: "https://github.com/NextLevel/NextLevelSessionExporter.git", from: "0.4.6"),
],
targets: [
@ -131,7 +130,6 @@ let package = Package(
.product(name: "CropViewController", package: "TOCropViewController"),
.product(name: "PanModal", package: "PanModal"),
.product(name: "Stripes", package: "Stripes"),
.product(name: "Kingfisher", package: "Kingfisher"),
.product(name: "NextLevelSessionExporter", package: "NextLevelSessionExporter"),
]
),

View File

@ -10,7 +10,7 @@ import UIKit
import AVKit
import MastodonCore
import SessionExporter
import Kingfisher
import Nuke
extension AttachmentViewModel {
func compressVideo(url: URL) async throws -> URL {
@ -99,18 +99,18 @@ extension AttachmentViewModel {
func compressImage(data: Data, sizeLimit: SizeLimit) throws -> Output {
let maxPayloadSizeInBytes = max((sizeLimit.image ?? 10 * 1024 * 1024), 1 * 1024 * 1024)
guard let image = KFCrossPlatformImage(data: data)?.kf.normalized,
var imageData = image.kf.pngRepresentation()
guard let image = UIImage(data: data)?.normalized(),
var imageData = image.pngData()
else {
throw AttachmentError.invalidAttachmentType
}
repeat {
guard let image = KFCrossPlatformImage(data: imageData) else {
guard let image = UIImage(data: imageData) else {
throw AttachmentError.invalidAttachmentType
}
if imageData.kf.imageFormat == .PNG {
if AssetType(imageData) == .png {
// A. png image
if imageData.count > maxPayloadSizeInBytes {
guard let compressedJpegData = image.jpegData(compressionQuality: 0.8) else {
@ -126,7 +126,7 @@ extension AttachmentViewModel {
// B. other image
if imageData.count > maxPayloadSizeInBytes {
let targetSize = CGSize(width: image.size.width * 0.8, height: image.size.height * 0.8)
let scaledImage = image.kf.resize(to: targetSize)
let scaledImage = image.resized(size: targetSize)
guard let compressedJpegData = scaledImage.jpegData(compressionQuality: 0.8) else {
throw AttachmentError.invalidAttachmentType
}
@ -140,7 +140,7 @@ extension AttachmentViewModel {
} while (imageData.count > maxPayloadSizeInBytes)
return .image(imageData, imageKind: imageData.kf.imageFormat == .PNG ? .png : .jpg)
return .image(imageData, imageKind: AssetType(imageData) == .png ? .png : .jpg)
}
}

View File

@ -9,6 +9,7 @@ import os.log
import UIKit
import AVKit
import UniformTypeIdentifiers
import Nuke
extension AttachmentViewModel {
@ -55,7 +56,7 @@ extension AttachmentViewModel {
}
defer { url.stopAccessingSecurityScopedResource() }
let imageData = try Data(contentsOf: url)
return .image(imageData, imageKind: imageData.kf.imageFormat == .PNG ? .png : .jpg)
return .image(imageData, imageKind: AssetType(imageData) == .png ? .png : .jpg)
} else if uti.conforms(to: .movie) {
guard url.startAccessingSecurityScopedResource() else {
throw AttachmentError.invalidAttachmentType
@ -89,11 +90,12 @@ extension AttachmentViewModel {
}
let imageData = result.data
let assetType = AssetType(imageData)
if imageData.kf.imageFormat == .PNG {
if assetType == .png {
return .png
}
if imageData.kf.imageFormat == .JPEG {
if assetType == .jpeg {
return .jpg
}

View File

@ -7,7 +7,6 @@
import os.log
import UIKit
import Kingfisher
import UniformTypeIdentifiers
import MastodonCore
import MastodonSDK

View File

@ -9,7 +9,6 @@ import os.log
import UIKit
import Combine
import PhotosUI
import Kingfisher
import MastodonCore
import MastodonLocalization
import func QuartzCore.CACurrentMediaTime

View File

@ -11,7 +11,6 @@ import MastodonAsset
import MastodonCore
import MastodonLocalization
import Stripes
import Kingfisher
public struct ComposeContentView: View {