English | 简体中文
WICompress is a lightweight iOS image compression library that supports JPEG, PNG, and HEIC formats, using the Luban algorithm for intelligent compression and efficient image processing.
-
Luban Algorithm Compression - Calculates optimal compression ratios to reduce file size while maintaining quality
-
Multi-format Support - Supports JPEG, PNG, and HEIC formats with automatic format-specific compression methods
-
High Performance - Optimized processing using
UIImageandCGImageDestination -
iOS 14+ Compatible - Built with Swift Package Manager for modern iOS development
- Open your project in Xcode, select File → Add Packages
- Enter the repository URL: https://github.com/Weixi779/WICompress
- Select the latest version and click Add Package
Resize images using the Luban algorithm, which only compresses resolution:
import WICompress
let resizedImage = WICompress.resizeImage(originalImage)Compress images with quality control and format preservation:
import WICompress
let compressedData = WICompress.compressImage(
originalImage,
quality: 0.7,
formatData: imageData
)image: TheUIImageto be compressedquality: Compression quality (0.0 - 1.0), default is 0.6formatData: Original image data used for format detection. If nil, defaults to JPEG compression
Important Notes:
- If
formatDatais nil, the library defaults to JPEG compression - For HEIC images, providing
formatDatais strongly recommended for optimal compression results
- Quality Compression: Input (
UIImage+Data) → Quality-compressedData - Resolution Adjustment: Quality-compressed
Data→UIImage→ ResizedUIImage(based on business requirements) - Format Conversion: Convert
UIImageto requiredDataformat for backend processing
The repository includes a comprehensive SwiftUI example project demonstrating WICompress functionality:
- PhotosPicker Integration: Select images from photo library with HEIC format preservation
- PHPickerViewController: UIKit-based picker for advanced use cases
- Real-time Comparison: Side-by-side comparison of original vs compressed images
- Format Detection: Automatic detection of JPEG, PNG, and HEIC formats
- Live Photo Support: Special handling for HEIC Live Photos
- Compression Metrics: File size reduction and compression ratio display
- Open
Example/WICompressExample/WICompressExample.xcodeproj - Build and run on iOS device or simulator
- Select images from your photo library to test compression
The example includes two main tabs:
- PhotosPicker: SwiftUI-based image selection
- PHPicker: UIKit-based image selection with enhanced debugging
| PNG Result | HEIC Result 1 | HEIC Result 2 |
|---|---|---|
![]() |
![]() |
![]() |
WICompress is available under the MIT license. See the LICENSE file for more info.


