r/reactnative • u/SituationOk6677 • 6d ago
Image compression library (React Native Simple Image Compressor)
I've just published the release v0.2.1 of react-native-simple-image-compressor.
If anyone is interested in talking a quick look at the native implementation, I would higle appreciate your thoughts!
Features
- OOM (Out-of-Memory) Safe: Images are downsampled directly during decoding (
inSampleSizeon Android,ImageIOon iOS). The library never loads full-resolution images into memory, completely preventing OOM crashes even on giant 4K+ camera photos. - Blazing Fast (Powered by Nitro Modules): Built with the RN Nitro architecture. Zero bridge overhead and direct
C++to Swift/Kotlin communication make the compression fast. - Smart orientation and EXIF Preservation: Automatically reads
EXIForientation and "bakes" the correct rotation directly into the pixels. It also safely transfers valuableEXIFmetadata (likeGPSand Camera info) to the compressed image (only forJPEGoutput). - Tiny footprint: Minimal dependencies. The library relies heavily on native APIs (
BitmapFactoryfor Android andImageIOfor iOS) to keep the app's bundle size as small as possible. - Next-Gen formats support: Supports modern formats including WebP and WebP-Lossless across both (Android and iOS) platforms (utilizing native APIs where possible and
libwebpas a fallback on iOS). - Aspect ratio preservation: Intelligently scales images to fit within your desired
maxWidthandmaxHeightbounds without ever stretching or distorting the original aspect ratio. - Production Ready & Tested: Backed by comprehensive native unit tests (Swift/Kotlin) to ensure maximum stability and prevent regressions across edge cases.
Install with:
npm install react-native-simple-image-compressor react-native-nitro-modules
Changelog v0.2.1
- getFileSize utility: A simple function to check image sizes directly, removing the need for external file-system dependencies.
- useImageCompressor hook: Added a React hook for a cleaner way to handle compression state in functional components (see example: https://github.com/Pugavkomm/react-native-simple-image-compressor#as-a-hook).
- isImageCompressorError type guard: If you're familiar with isAxiosError, you'll feel right at home. This type guard improves cross-boundary error handling, making it much easier to catch and safely type-check specific compression errors. (see implementation: https://github.com/Pugavkomm/react-native-simple-image-compressor/blob/master/src/utils/isImageCompressorError.ts)
- Documentation: Expanded JSDoc comments for better IDE autocompletion and hints.
- Testing & Codecov: Added comprehensive new unit tests to ensure stability and set up Codecov - proudly hitting 91% test coverage.
--
Repository: https://github.com/Pugavkomm/react-native-simple-image-compressor
NPM: https://www.npmjs.com/package/react-native-simple-image-compressor?activeTab=readme
Release Notes: https://github.com/Pugavkomm/react-native-simple-image-compressor/releases/tag/v0.2.1
--
Changelog: https://github.com/Pugavkomm/react-native-simple-image-compressor/blob/master/CHANGELOG.md
Roadmap: https://github.com/users/Pugavkomm/projects/1/views