Files
openclaw/apps/shared/OpenClawKit/Sources/OpenClawKit/ShareImageProcessor.swift
lin-hongkuan 522e253c53 fix(ios): resize oversized shared images (#103860)
* fix(ios): resize oversized shared images

* fix(ios): satisfy SwiftFormat await rules

* fix(ios): integrate share image processing

* fix(ios): type share attachment failures

---------

Co-authored-by: lin-hongkuan <lin-hongkuan@users.noreply.github.com>
Co-authored-by: Peter Steinberger <steipete@gmail.com>
2026-07-11 15:16:45 -07:00

31 lines
1.0 KiB
Swift

import Foundation
/// Share Extension image policy built on the shared, orientation-normalizing JPEG transcoder.
public enum ShareImageProcessor {
public static let maxLongEdgePx = 2560
public static let jpegQuality = 0.9
public static let maxPayloadBytes = 5_000_000
public enum ProcessError: Error, Equatable, Sendable {
case invalidImage
case encodeFailed
case sizeLimitExceeded
}
public static func processForUpload(data: Data) throws -> Data {
do {
return try JPEGTranscoder.transcodeToJPEG(
imageData: data,
maxLongEdgePx: self.maxLongEdgePx,
quality: self.jpegQuality,
maxBytes: self.maxPayloadBytes).data
} catch JPEGTranscodeError.decodeFailed, JPEGTranscodeError.propertiesMissing {
throw ProcessError.invalidImage
} catch JPEGTranscodeError.sizeLimitExceeded {
throw ProcessError.sizeLimitExceeded
} catch {
throw ProcessError.encodeFailed
}
}
}