Skip to content

v1.1.0

Latest

Choose a tag to compare

@Weixi779 Weixi779 released this 22 Jun 12:52

WICompress 1.0.0 and 1.1.0 together mark the v1 rebuild of the library: a data-first, ImageIO-backed image compression core with a simpler public API and stronger output control.

The old UIImage-oriented API has been replaced by Data and file URL entry points. WICompress now inspects and encodes original image bytes directly through ImageIO, including format, dimensions, orientation, alpha, metadata, color profile, and destination writability.

Highlights

  • Data-first API: Data / file URL in, compressed Data out
  • ImageIO-backed compression pipeline
  • UIKit/AppKit-free core
  • JPEG, PNG, and HEIC/HEIF format detection
  • Source format preservation by default
  • Explicit JPEG, PNG, and HEIC output policies
  • Luban resize policy
  • .maxPixel(Int) longest-side resize cap
  • Metadata stripping or preservation
  • Lossy quality control for JPEG and HEIC
  • Alpha-safe JPEG conversion through explicit background handling
  • Typed errors through WICompressError
  • Swift Testing coverage with real image fixtures
  • SwiftUI example app

What Changed Since 0.x

New Data API

The old image-object-based APIs have been removed. The recommended API now works directly with original image bytes:

let compressedData = try WICompress.compress(originalData)

File URLs are also supported:

let compressedData = try WICompress.compress(contentsOf: imageURL)

Upload-Oriented Defaults

The default options are tuned for common upload compression:

WICompressOptions(
    resize: .luban,
    format: .preserve,
    metadata: .strip,
    quality: .compression(0.6)
)

ImageIO Core

The new core uses ImageIO instead of UIKit/AppKit image rendering. This allows WICompress to preserve and reason about container format, orientation, metadata, alpha, color profile, and runtime destination support from the original image data.

New In 1.1.0

Explicit Output Format

Callers can now request a concrete output container:

let uploadData = try WICompress.compress(
    originalData,
    options: WICompressOptions(
        resize: .maxPixel(1600),
        format: .jpeg(background: .white),
        metadata: .strip,
        quality: .compression(0.7)
    )
)

Supported format policies:

  • .preserve
  • .jpeg(background:)
  • .png
  • .heic

JPEG Background Handling

Transparent sources are no longer silently flattened when writing JPEG.

WIJPEGBackground supports:

  • .disallow
  • .white
  • .black

If a transparent source is encoded as JPEG with .disallow, WICompress throws:

WICompressError.transparentSourceRequiresBackground

Max Pixel Resize

.maxPixel(Int) caps the longest display side without upscaling smaller images:

WICompressOptions(
    resize: .maxPixel(1600)
)

This complements Luban: Luban remains the default one-pass upload heuristic, while .maxPixel gives callers a concrete dimension contract.

Changelog

Added

  • Data-first compression APIs for Data and file URL
  • ImageIO-backed JPEG, PNG, and HEIC/HEIF detection
  • UIKit/AppKit-free compression pipeline
  • Luban resize policy
  • Metadata strip / preserve policy
  • Lossy quality policy for JPEG and HEIC
  • Explicit output format policies for JPEG, PNG, and HEIC
  • WIJPEGBackground
  • .maxPixel(Int) resize policy
  • WICompressError.transparentSourceRequiresBackground
  • SwiftUI example app
  • Real-image Swift Testing coverage

Changed

  • Replaced old UIImage-oriented APIs with Data / URL APIs
  • Preserves source container format by default instead of implicitly falling back to JPEG
  • Reports failures through typed WICompressError
  • Explicit format conversion always rewrites output instead of returning original bytes through the size guard
  • Redraw paths bake orientation into pixels and reset the orientation tag to 1

Removed

  • WICompress.resizeImage(_:)
  • WICompress.compressImage(_:quality:formatData:)

Full Changelog: v0.2.2...v1.1.0

Contributors