diff --git a/harness/native-compressor.harness.ts b/harness/native-compressor.harness.ts index 4cd89a2..32e39a3 100644 --- a/harness/native-compressor.harness.ts +++ b/harness/native-compressor.harness.ts @@ -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(); diff --git a/ios/Image/ImageCompressorOptions.swift b/ios/Image/ImageCompressorOptions.swift index d45b88d..ded6951 100644 --- a/ios/Image/ImageCompressorOptions.swift +++ b/ios/Image/ImageCompressorOptions.swift @@ -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":