Quickstart — Swift (iOS)
Add the SwiftPM package (see the repository packages/swift). The
bindings are generated by UniFFI from the core, so the API matches the
Rust core exactly. iOS builds need a macOS runner — see the repository CI.
Compress
Section titled “Compress”import Dusimagez
let input = try Data(contentsOf: URL(fileURLWithPath: "input.jpg"))let output = try compressImage(input: input, options: CompressOptions(quality: 80))try output.write(to: URL(fileURLWithPath: "output.jpg"))Compress to a target size
Section titled “Compress to a target size”// 200 KB or less, or a DusimagezError with code TARGET_SIZE_UNREACHABLE.let output = try compressToSize(input: input, targetBytes: 200_000, options: CompressOptions())Report and info
Section titled “Report and info”let info = try getImageInfo(input: input)// info.format, info.width, info.height
let report = try compressWithReport(input: input, options: CompressOptions(preset: .web))print("\(report.originalSize) -> \(report.outputSize) bytes, " + "saved \(report.savedPercent)%, quality \(report.qualityUsed)")let results = bulkCompress(inputs: [data1, data2, Data()], options: CompressOptions())for result in results { switch result { case .success(let report): print("saved \(report.savedBytes) bytes") case .failure(let error as DusimagezError): print(error.code) // per-item error }}Errors
Section titled “Errors”Failures throw DusimagezError with code, messageEn and messageHi —
see Error codes for all 9 codes.
Full option list: Options reference.