Skip to content

feat: add support for compressing images - #12

Merged
surajkumar merged 4 commits into
mainfrom
image-compression
Apr 16, 2026
Merged

feat: add support for compressing images#12
surajkumar merged 4 commits into
mainfrom
image-compression

Conversation

@surajkumar

@surajkumar surajkumar commented Apr 15, 2026

Copy link
Copy Markdown
Contributor

This PR adds image compression support to the KMP image selector so consumers can reduce image size before upload storage. It includes both quality-based compression and a best-effort target-size mode for requirements like keeping images under 5 MB.

What Changed

  • Added a shared compression API for ByteArray and ImageData
    Introduced ImageCompressionOptions and ImageCompressionFormat
  • Added compress(...) for quality-based compression
  • Added compressToMaxBytes(...) for best-effort size targeting
  • Implemented platform-specific compression for Android, iOS, and Desktop/JVM
  • Documented the new API in the README

Examples:

val compressed = imageData.compress(
    ImageCompressionOptions(
        quality = 88
    )
)
val underFiveMb = imageData.compressToMaxBytes(
    maxBytes = 5L * 1024L * 1024L
)

Additionally, fixes a bug with iOS hanging.

…ative 2.2.x. The replacement uses NSMutableData.appendBytes:length:, an instance method that has stable Kotlin/Native bindings across versions. NSMutableData is a subclass of NSData so the return type is compatible.
@surajkumar
surajkumar merged commit 5c98808 into main Apr 16, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants