npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@dynlabs/react-native-image-to-webp

v0.1.1

Published

Convert images to WebP format with presets and resizing options

Readme

@dynlabs/react-native-image-to-webp

A production-ready React Native library for converting images to WebP format with presets, resizing, and high-performance native implementations.

Features

  • 🚀 TurboModule (New Architecture only) for optimal performance
  • 🎨 5 Presets: balanced, small, fast, lossless, document
  • 📐 Smart Resizing: Preserve aspect ratio with maxLongEdge
  • 🔒 Privacy-First: Strips EXIF metadata by default
  • High Performance: Native decoders + libwebp encoding, all off main thread
  • 📱 iOS & Android: Platform-optimized implementations
  • 🛡️ Type-Safe: Full TypeScript support with strict types

Requirements

  • React Native >= 0.68
  • New Architecture (TurboModules) enabled
  • iOS 11.0+ / Android API 24+

Installation

npm install @dynlabs/react-native-image-to-webp
# or
yarn add @dynlabs/react-native-image-to-webp

iOS

cd ios && pod install && cd ..

Android

No additional setup required. The library uses CMake for native builds.

Quick Start

import { convertImageToWebP } from '@dynlabs/react-native-image-to-webp';

const result = await convertImageToWebP({
  inputPath: '/path/to/image.jpg',
  preset: 'balanced',
  maxLongEdge: 2048,
});

console.log(`Output: ${result.outputPath}`);
console.log(`Size: ${result.sizeBytes} bytes`);
console.log(`Dimensions: ${result.width}×${result.height}`);

API

convertImageToWebP(options: ConvertOptions): Promise<ConvertResult>

Options

| Parameter | Type | Required | Default | Description | | --------------- | --------------- | -------- | -------------- | ----------------------------------------- | | inputPath | string | ✅ | - | Path to input image file | | outputPath | string | ❌ | Auto-derived | Output WebP file path | | preset | ConvertPreset | ❌ | 'balanced' | Preset configuration | | maxLongEdge | number | ❌ | - | Max dimension (preserves aspect ratio) | | quality | number | ❌ | Preset default | Quality 0-100 (overrides preset) | | method | number | ❌ | Preset default | Compression method 0-6 (overrides preset) | | lossless | boolean | ❌ | Preset default | Use lossless encoding (overrides preset) | | stripMetadata | boolean | ❌ | true | Strip EXIF metadata |

Result

{
  outputPath: string; // Path to created WebP file
  width: number; // Image width in pixels
  height: number; // Image height in pixels
  sizeBytes: number; // Output file size in bytes
}

Presets

| Preset | Quality | Method | Use Case | | ---------- | ------- | ------ | ------------------------------------------------------- | | balanced | 80 | 3 | Default. General-purpose, good quality/size balance | | small | 74 | 5 | Optimized for smaller file sizes | | fast | 78 | 1 | Faster encoding, slightly larger files | | lossless | - | 4 | Perfect quality, larger files | | document | 82 | 4 | Documents, images with text/transparency |

Examples

// Balanced (default)
await convertImageToWebP({
  inputPath: '/path/to/image.jpg',
  preset: 'balanced',
});

// Small file size
await convertImageToWebP({
  inputPath: '/path/to/image.jpg',
  preset: 'small',
  maxLongEdge: 1024,
});

// Lossless
await convertImageToWebP({
  inputPath: '/path/to/image.jpg',
  preset: 'lossless',
});

// Custom quality
await convertImageToWebP({
  inputPath: '/path/to/image.jpg',
  quality: 90,
  method: 4,
  maxLongEdge: 2048,
});

Resizing

Use maxLongEdge to resize images while preserving aspect ratio:

// Resize so longest edge is max 2048px
await convertImageToWebP({
  inputPath: '/path/to/large-image.jpg',
  maxLongEdge: 2048, // If image is 4000×3000, becomes 2048×1536
});

Recommendation: Always use maxLongEdge for better performance and smaller files. Common values:

  • Thumbnails: 512
  • Mobile display: 1024
  • Retina display: 2048 (recommended default)
  • High-res: 3072

Error Handling

import {
  convertImageToWebP,
  ImageToWebPError,
  ERROR_CODES,
} from '@dynlabs/react-native-image-to-webp';

try {
  const result = await convertImageToWebP({ inputPath: '/path/to/image.jpg' });
} catch (error) {
  if (error instanceof ImageToWebPError) {
    switch (error.code) {
      case ERROR_CODES.FILE_NOT_FOUND:
        console.error('File not found');
        break;
      case ERROR_CODES.DECODE_FAILED:
        console.error('Failed to decode image');
        break;
      case ERROR_CODES.ENCODE_FAILED:
        console.error('Failed to encode WebP');
        break;
      // ... other error codes
    }
  }
}

Error Codes

  • INVALID_INPUT: Invalid parameters
  • FILE_NOT_FOUND: Input file doesn't exist
  • DECODE_FAILED: Failed to decode input image
  • ENCODE_FAILED: Failed to encode WebP
  • IO_ERROR: File I/O error
  • UNSUPPORTED_FORMAT: Unsupported image format

Supported Formats

iOS

  • JPEG, PNG, HEIC/HEIF, TIFF, GIF (first frame), WebP

Android

  • JPEG, PNG, WebP, HEIF (API 28+), GIF (first frame)

Performance

  • All processing runs off the main thread (background queue/executor)
  • Uses platform-native decoders (ImageIO on iOS, ImageDecoder/BitmapFactory on Android)
  • Resize before encoding for best performance
  • Typical encoding time: 0.5-2s for 2000×1500 images (varies by device/preset)

See PERFORMANCE.md for detailed performance guidance.

Architecture

This library uses React Native's New Architecture (TurboModules):

  • Type-safe Codegen interfaces
  • Native implementations for iOS (ObjC++) and Android (Kotlin + JNI)
  • Shared C++ code using libwebp for encoding
  • Background threading for non-blocking operations

See ARCHITECTURE.md for details.

Documentation

Example App

See the example app for a complete usage example.

# Run example on iOS
yarn example:ios

# Run example on Android
yarn example:android

Contributing

See CONTRIBUTING.md for development setup and guidelines.

License

MIT

Related


Made with ❤️ for the React Native community