{"_id":"@akbeniwal/react-native-image-compressor","_rev":"3-06102b25e607b96f2496fc25f0b13ee8","name":"@akbeniwal/react-native-image-compressor","dist-tags":{"latest":"1.1.1"},"versions":{"1.0.0":{"name":"@akbeniwal/react-native-image-compressor","version":"1.0.0","keywords":["react-native","image","compressor","image-compression"],"author":{"name":"Abhishek Beniwal"},"license":"MIT","_id":"@akbeniwal/react-native-image-compressor@1.0.0","maintainers":[{"name":"akbeniwal","email":"abhishekbeniwal363@gmail.com"}],"dist":{"shasum":"39becb7a630808f0312520a58fe6086a947c68ad","tarball":"https://registry.npmjs.org/@akbeniwal/react-native-image-compressor/-/react-native-image-compressor-1.0.0.tgz","fileCount":8,"integrity":"sha512-3oO9VlRxMcgHpD2pzmSlRzeM/uHUxhslKI3ZDosDpiDzn++MZarMXd7RBDgukkkkCP/hy/uH/kcecBETtanxsw==","signatures":[{"sig":"MEQCIDwsCTkevKwTPD77eKC4BvybcwZudyJRy6dSbjmYny4/AiA1CSxORSQLSBiclgjmsooyVeeZJzuhgOs7t25fdWmTCg==","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":2652},"main":"dist/index.js","types":"dist/index.d.ts","scripts":{"build":"tsc"},"_npmUser":{"name":"akbeniwal","email":"abhishekbeniwal363@gmail.com"},"_npmVersion":"10.9.8","description":"A lightweight image compression utility for React Native","directories":{},"_nodeVersion":"22.22.3","_hasShrinkwrap":false,"peerDependencies":{"react":">=18.0.0","react-native":">=0.72.0"},"_npmOperationalInternal":{"tmp":"tmp/react-native-image-compressor_1.0.0_1780557494376_0.18117308828670353","host":"s3://npm-registry-packages-npm-production"}},"1.1.0":{"name":"@akbeniwal/react-native-image-compressor","version":"1.1.0","keywords":["react-native","image","compressor","image-compression","image-resize","react-native-image","image-optimizer","compression"],"author":{"name":"Abhishek Beniwal"},"license":"MIT","_id":"@akbeniwal/react-native-image-compressor@1.1.0","maintainers":[{"name":"akbeniwal","email":"abhishekbeniwal363@gmail.com"}],"homepage":"https://www.npmjs.com/package/@akbeniwal/react-native-image-compressor","dist":{"shasum":"d6fa492243f93e787027376010ddd4109b513717","tarball":"https://registry.npmjs.org/@akbeniwal/react-native-image-compressor/-/react-native-image-compressor-1.1.0.tgz","fileCount":12,"integrity":"sha512-2vXM8kaMTJtHB6RlYnGuVHYCQfYe9RBIhUnAtZyOFqa3uB/v54fOrBMc9JzkMVaKQum0KXfNdsIGKXj8Evz/BQ==","signatures":[{"sig":"MEYCIQCkKg77I9KKPN9WDYzZY5J6v7vCiuaVxb3B92bELCmejwIhAP4YSJlcBof4wDLnCrD7Znf8tdoopMA5RJ0+gJSIC3oX","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":7295},"main":"dist/index.js","types":"dist/index.d.ts","scripts":{"build":"tsc","prepublishOnly":"yarn build"},"_npmUser":{"name":"akbeniwal","email":"abhishekbeniwal363@gmail.com"},"_npmVersion":"10.9.8","description":"A lightweight image compression utility for React Native with quality-based and target-size-based compression.","directories":{},"_nodeVersion":"22.22.3","dependencies":{"react-native-compressor":"^1.18.2"},"_hasShrinkwrap":false,"devDependencies":{"typescript":"^6.0.3"},"peerDependencies":{"react":">=18.0.0","react-native":">=0.72.0","react-native-compressor":">=1.10.0"},"_npmOperationalInternal":{"tmp":"tmp/react-native-image-compressor_1.1.0_1780559515576_0.704940733768282","host":"s3://npm-registry-packages-npm-production"}},"1.1.1":{"name":"@akbeniwal/react-native-image-compressor","version":"1.1.1","description":"A lightweight image compression utility for React Native with quality-based and target-size-based compression.","main":"dist/index.js","types":"dist/index.d.ts","keywords":["react-native","image","compressor","image-compression","image-resize","react-native-image","image-optimizer","compression"],"author":{"name":"Abhishek Beniwal"},"license":"MIT","repository":{"type":"git","url":"git+https://github.com/AKBeniwal1700/react-native-image-compressor.git"},"bugs":{"url":"https://github.com/AKBeniwal1700/react-native-image-compressor/issues"},"homepage":"https://github.com/AKBeniwal1700/react-native-image-compressor#readme","scripts":{"build":"tsc","prepublishOnly":"yarn build"},"peerDependencies":{"react":">=18.0.0","react-native":">=0.72.0","react-native-compressor":">=1.10.0"},"devDependencies":{"react-native-compressor":"^1.18.2","typescript":"^6.0.3"},"_id":"@akbeniwal/react-native-image-compressor@1.1.1","gitHead":"340cecaf7335f9fc3814a1b0083f0ace5cf88031","_nodeVersion":"22.22.3","_npmVersion":"10.9.8","dist":{"integrity":"sha512-C2xyDaKITqSy9ixRng3hdBJ255ZeFr0X3GxomUZuan/apKvwfKdvOIwq4UsCLDpD990KNQBr+MTP9/TUHWSurA==","shasum":"520fb1b47def4affbc7a5e8d2fca8c2c449bb6be","tarball":"https://registry.npmjs.org/@akbeniwal/react-native-image-compressor/-/react-native-image-compressor-1.1.1.tgz","fileCount":12,"unpackedSize":12182,"signatures":[{"keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U","sig":"MEUCIQCx5zFa6wfxlJKwZhfcn2J7RaYgBVs4dr3SHbN5E/mS3AIgfmUvqpuUPUaXQTY1qKz7A473lu4wopQBo/1izF3ECdM="}]},"_npmUser":{"name":"akbeniwal","email":"abhishekbeniwal363@gmail.com"},"directories":{},"maintainers":[{"name":"akbeniwal","email":"abhishekbeniwal363@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages-npm-production","tmp":"tmp/react-native-image-compressor_1.1.1_1780572321683_0.6105787302298289"},"_hasShrinkwrap":false}},"time":{"created":"2026-06-04T07:18:14.212Z","modified":"2026-06-04T11:25:21.991Z","1.0.0":"2026-06-04T07:18:14.556Z","1.1.0":"2026-06-04T07:51:55.722Z","1.1.1":"2026-06-04T11:25:21.840Z"},"author":{"name":"Abhishek Beniwal"},"license":"MIT","homepage":"https://github.com/AKBeniwal1700/react-native-image-compressor#readme","keywords":["react-native","image","compressor","image-compression","image-resize","react-native-image","image-optimizer","compression"],"description":"A lightweight image compression utility for React Native with quality-based and target-size-based compression.","maintainers":[{"name":"akbeniwal","email":"abhishekbeniwal363@gmail.com"}],"readme":"# ⚡ React Native Image Compressor\n\n<p align=\"center\">\n  <a href=\"https://www.npmjs.com/package/@akbeniwal/react-native-image-compressor\">\n    <img src=\"https://img.shields.io/npm/v/@akbeniwal/react-native-image-compressor.svg?style=flat-square&color=blue\" alt=\"npm version\" />\n  </a>\n  <a href=\"https://www.npmjs.com/package/@akbeniwal/react-native-image-compressor\">\n    <img src=\"https://img.shields.io/npm/dm/@akbeniwal/react-native-image-compressor.svg?style=flat-square\" alt=\"npm downloads\" />\n  </a>\n  <a href=\"https://github.com/AKBeniwal1700/react-native-image-compressor/blob/main/LICENSE\">\n    <img src=\"https://img.shields.io/npm/l/@akbeniwal/react-native-image-compressor.svg?style=flat-square&color=green\" alt=\"license\" />\n  </a>\n  <a href=\"https://github.com/AKBeniwal1700/react-native-image-compressor/pulls\">\n    <img src=\"https://img.shields.io/badge/PRs-welcome-brightgreen.svg?style=flat-square\" alt=\"PRs Welcome\" />\n  </a>\n</p>\n\nA high-performance, lightweight, and fully type-safe image compression library for React Native. Keep your application fast, save users' bandwidth, and reduce server load by optimizing and compressing images on the client side before uploading them.\n\n---\n\n## ✨ Features\n\n- 🚀 **Quality-Based Compression**: Compress images quickly by specifying a quality factor between `0.0` and `1.0`.\n- 📦 **Target-Size-Based Compression**: Automatically and iteratively compress images to fit under a target file size (in KB).\n- 📊 **Compression Statistics**: Get detailed results including compressed file URI, original size, compressed size, and percentage saved.\n- ⚡ **Lightweight & Efficient**: Thin TypeScript/JavaScript wrapper built on top of native compression APIs.\n- 📱 **Cross-Platform**: Supports both iOS and Android.\n- 🛠 **Type-Safe**: Written in TypeScript with full autocompletion and type definitions.\n\n---\n\n## 📦 Installation\n\nThis library relies on [react-native-compressor](https://github.com/numandev1/react-native-compressor) as a peer dependency for native image optimization.\n\n### 1. Install the packages\n\nUsing **Yarn**:\n```bash\nyarn add @akbeniwal/react-native-image-compressor react-native-compressor\n```\n\nUsing **NPM**:\n```bash\nnpm install @akbeniwal/react-native-image-compressor react-native-compressor\n```\n\n### 2. Native Setup (iOS only)\n\nFor iOS, you must link the native parts of `react-native-compressor` by installing the pods:\n\n```bash\ncd ios && pod install && cd ..\n```\n\n*Note: For Android, the native code is linked automatically via React Native Auto-Linking.*\n\n---\n\n## 🚀 Usage\n\n### 1. Compress by Quality\nCompress an image to a specific quality factor (0.0 to 1.0). Useful when you want a quick, single-pass compression.\n\n```typescript\nimport { compressImageByQuality } from '@akbeniwal/react-native-image-compressor';\n\nconst handleCompress = async (imageUri: string) => {\n  try {\n    const result = await compressImageByQuality(imageUri, {\n      quality: 0.7, // Quality level between 0.0 (max compression) and 1.0 (best quality)\n    });\n\n    console.log('Compressed Image Uri:', result.uri);\n    console.log('Original Size:', result.originalSizeKB, 'KB');\n    console.log('Compressed Size:', result.compressedSizeKB, 'KB');\n    console.log('Saved:', result.savedPercentage, '%');\n  } catch (error) {\n    console.error('Compression failed:', error);\n  }\n};\n```\n\n### 2. Compress by Target Size\nAutomatically scale down image quality iteratively until the image fits under your specified target size in KB. Ideal for upload limits (e.g., maximum 300KB profile picture).\n\n```typescript\nimport { compressImageBySize } from '@akbeniwal/react-native-image-compressor';\n\nconst handleCompressToSize = async (imageUri: string) => {\n  try {\n    const result = await compressImageBySize(imageUri, {\n      targetSizeKB: 300, // Target size in Kilobytes (KB)\n    });\n\n    console.log('Compressed Image Uri:', result.uri);\n    console.log('Saved:', result.savedPercentage, '%');\n  } catch (error) {\n    console.error('Target-size compression failed:', error);\n  }\n};\n```\n\n---\n\n## 📊 Response Structure\n\nBoth compression functions return a promise that resolves to a `CompressResult` object:\n\n```typescript\ninterface CompressResult {\n  uri: string;              // Path/URI to the newly compressed image file\n  originalSizeKB: number;   // Original image file size in Kilobytes\n  compressedSizeKB: number; // Compressed image file size in Kilobytes\n  savedPercentage: number;  // The percentage of file size saved (e.g., 86.89)\n}\n```\n\n### Example Response:\n```json\n{\n  \"uri\": \"file:///data/user/0/com.example/cache/ReactNative-Compressor/compressed-image.jpg\",\n  \"originalSizeKB\": 2450.32,\n  \"compressedSizeKB\": 321.18,\n  \"savedPercentage\": 86.89\n}\n```\n\n---\n\n## 📘 API Reference\n\n### `compressImageByQuality(uri, options)`\n\nCompresses an image file based on a fixed quality factor.\n\n#### Parameters:\n- `uri` (`string`): The local path or web URL of the image to compress.\n- `options` (`CompressByQualityOptions`):\n  | Property | Type | Required | Description |\n  | :--- | :--- | :--- | :--- |\n  | `quality` | `number` | Yes | Compression quality from `0.0` (highest compression) to `1.0` (highest quality). |\n\n---\n\n### `compressImageBySize(uri, options)`\n\nIteratively compresses an image file until its file size is less than or equal to the target size in KB (or quality reaches `0.1`).\n\n#### Parameters:\n- `uri` (`string`): The local path or web URL of the image to compress.\n- `options` (`CompressBySizeOptions`):\n  | Property | Type | Required | Description |\n  | :--- | :--- | :--- | :--- |\n  | `targetSizeKB` | `number` | Yes | Target output image size in KB. |\n\n---\n\n## ⚙️ How It Works Under the Hood\n\n1. **Size Detection**: It fetches the image URI using a lightweight `fetch` call and extracts the file size via its blob representation.\n2. **Iterative Reduction (for `compressImageBySize`)**: The library starts with a high quality (`0.9`) and compresses the image. If the resulting size is still larger than your target size, it decreases the quality in steps of `0.1` and retries, stopping once the target is met or it reaches the minimum quality threshold (`0.1`).\n3. **Optimized for React Native**: Leveraging `react-native-compressor` ensures that actual encoding/decoding is performed in native threads (Objective-C/Swift for iOS, Java/Kotlin for Android), preventing UI blockages.\n\n---\n\n## Changelog\n\n### v1.1.0\n\n- Added `compressImageByQuality` function.\n- Added `compressImageBySize` function.\n- Added detailed compression statistics (original size, compressed size, saved percentage).\n\n---\n\n## 📄 License\n\nThis project is licensed under the [MIT License](LICENSE).\n\n---\n\n## 👤 Author\n\n**Abhishek Beniwal**\n- GitHub: [@AKBeniwal1700](https://github.com/AKBeniwal1700)\n","readmeFilename":"README.md","repository":{"type":"git","url":"git+https://github.com/AKBeniwal1700/react-native-image-compressor.git"},"bugs":{"url":"https://github.com/AKBeniwal1700/react-native-image-compressor/issues"}}