FileKit Core
Image utilities
Utilities for working with images in Kotlin Multiplatform
Supported on Android, iOS, macOS, JVM targets
FileKit Core provides powerful utilities for working with images across platforms. These utilities enable common image operations like compression, resizing, and saving to the device gallery, with a consistent API across all supported platforms.
Compressing Images
You can compress images to reduce their file size while maintaining acceptable quality:
The compressImage
function provides several key features:
- Quality control: Reduces the image quality based on the
quality
parameter (0-100) - Resizing: Resizes the image if
maxWidth
ormaxHeight
is specified, maintaining the aspect ratio - Format conversion: Converts the image to the specified format (JPEG or PNG)
- Metadata handling: On Android, automatically handles EXIF orientation metadata
Saving Images to Gallery
FileKit provides a way to save images to the device’s photo gallery:
The behavior of saveImageToGallery
varies slightly by platform:
Platform | Behavior |
---|---|
Android | Saves to the device’s Pictures directory and makes it visible in the gallery app |
iOS | Saves to the device’s Camera Roll |
macOS/JVM | Saves to the user’s Pictures directory |
JS/WASM | Not supported (no-op) |
Example: Creating a Thumbnail
This function creates a thumbnail version of an image by resizing it to a maximum dimension while maintaining the aspect ratio.