Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions harness/native-compressor.harness.ts
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,9 @@ describe('react-native-compressor native harness', () => {
const metadata = await getImageMetaData(output);
expect(metadata.ImageWidth).toBeGreaterThan(0);
expect(metadata.ImageHeight).toBeGreaterThan(0);
// the fixture is 16×16, so maxWidth/maxHeight must shrink it (#417)
expect(metadata.ImageWidth).toBeLessThanOrEqual(8);
expect(metadata.ImageHeight).toBeLessThanOrEqual(8);
expect(metadata.size).toBeGreaterThan(0);
expect(metadata.exif).toBeTruthy();

Expand Down
12 changes: 8 additions & 4 deletions ios/Image/ImageCompressorOptions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,18 @@ class ImageCompressorOptions: NSObject {
switch key {
case "compressionMethod":
options.autoCompress = (value as? String ?? "") != "manual"
// Nitro hands every JS number over as a Swift Double, which `as? Int` and
// `as? Float` never match, so these options silently fell back to their
// defaults (#417). NSNumber bridges a Double, an Int and an NSNumber alike,
// the same cast VideoMain uses for its numeric options.
case "maxWidth":
options.maxWidth = (value as? Int) ?? 1280
options.maxWidth = (value as? NSNumber)?.intValue ?? 1280
case "maxHeight":
options.maxHeight = (value as? Int) ?? 1280
options.maxHeight = (value as? NSNumber)?.intValue ?? 1280
case "progressDivider":
options.progressDivider = (value as? Int) ?? 0
options.progressDivider = (value as? NSNumber)?.intValue ?? 0
case "quality":
options.quality = (value as? Float) ?? 0.8
options.quality = (value as? NSNumber)?.floatValue ?? 0.8
case "input":
options.parseInput(value as? String)
case "output":
Expand Down