High-performance image manipulation utilities for macOS and iOS built with Core Graphics and Core Image. Efficiently resize, scale, and apply perspective transformations to images with minimal memory overhead.
- ImageResizer: Fast image resizing and scaling using CGImageSource thumbnail generation
- ImageSkewer: Perspective transformation (skewing) using Core Image filters
- Memory-efficient processing without loading full images into memory
- Support for multiple image formats (JPEG, PNG, TIFF, BMP, GIF, and more)
- Direct-to-disk operations to minimize memory usage
- Full Swift Package Manager support
- iOS 11.0+ / macOS 10.15+
- Swift 5.1+
- Xcode 11+
Add HPImageUtils to your project through Xcode:
- Go to File > Add Package Dependencies...
- Enter the package URL:
https://github.com/henrik-dmg/HPImageUtils - Select the version you want to use
Or add it to your Package.swift dependencies:
dependencies: [
.package(url: "https://github.com/henrik-dmg/HPImageUtils", from: "1.0.0")
]Then add it to your target:
targets: [
.target(
name: "YourTarget",
dependencies: ["HPImageUtils"]
)
]The ImageResizer class provides high-performance image resizing and scaling.
import HPImageUtils
// Initialize with source image URL
let resizer = try ImageResizer(sourceURL: imageURL)
// Resize to specific dimensions
let resizedImage = try resizer.resizeImage(to: CGSize(width: 800, height: 600))
// Or save directly to disk
try resizer.resizeImage(
to: CGSize(width: 800, height: 600),
destinationURL: outputURL,
format: .jpeg
)let resizer = try ImageResizer(sourceURL: imageURL)
// Scale to 50% of original size
let scaledImage = try resizer.scaleImage(to: 0.5)
// Or save directly to disk
try resizer.scaleImage(
to: 0.5,
destinationURL: outputURL,
format: .png
)The ImageSkewer class applies perspective transformations to images. Available on iOS 13.0+ and macOS 10.15+.
import HPImageUtils
let skewer = try ImageSkewer(sourceURL: imageURL)
// Define where the four corners should appear in the output
let corners = ImageSkewer.CornerConfiguration(
topLeft: Point(x: 100, y: 100),
topRight: Point(x: 700, y: 120),
bottomRight: Point(x: 680, y: 900),
bottomLeft: Point(x: 120, y: 880)
)
// Create configuration with target size
let config = ImageSkewer.Configuration(
targetImageSize: Size(width: 800, height: 1000),
cornerConfiguration: corners
)
// Apply transformation and save
try skewer.skewImage(configuration: config, outputURL: outputURL)let skewer = try ImageSkewer(sourceURL: imageURL)
let corners = ImageSkewer.CornerConfiguration(
topLeft: Point(x: 50, y: 50),
topRight: Point(x: 450, y: 50),
bottomRight: Point(x: 450, y: 650),
bottomLeft: Point(x: 50, y: 650)
)
// Get CGImage directly without writing to disk
let skewedImage = try skewer.skewImage(
targetImageSize: CGSize(width: 500, height: 700),
cornerConfiguration: corners
)HPImageUtils supports a wide range of image formats:
// Common formats
.jpeg, .png, .gif, .tiff, .bmp
// Advanced formats
.jpeg2000, .raw, .svg
// Apple formats
.appleICNS, .quickTimeImage, .pict
// Other formats
.ico- Memory Efficient: Uses
CGImageSourceto avoid loading full images into memory - Fast Thumbnail Generation: Leverages Core Graphics' optimized thumbnail creation
- Direct File I/O: Write results directly to disk without intermediate memory buffers
- Hardware Acceleration: Core Image transformations utilize GPU acceleration when available
All operations can throw errors. Common error scenarios:
do {
let resizer = try ImageResizer(sourceURL: imageURL)
try resizer.resizeImage(to: targetSize, destinationURL: outputURL, format: .jpeg)
} catch {
// Handle errors:
// - File not found at source URL
// - Invalid image format
// - Unable to read image dimensions
// - Disk write failures
print("Image processing failed: \(error)")
}[Add your license information here]
Contributions are welcome! Please feel free to submit a Pull Request.
Henrik Panhans