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

capacitor-camera-crop

v2.0.0

Published

A Capacitor plugin providing native camera and crop support.

Readme

capacitor-camera-crop

A Capacitor plugin providing native camera and crop support for iOS and Android.

Features

  • ✅ Open native camera or gallery
  • ✅ Native image cropping with customizable aspect ratios
  • ✅ Returns file URI or base64 encoded string
  • ✅ Image resizing support
  • ✅ TypeScript support
  • ✅ iOS (Swift) and Android (Kotlin) implementations

Installation

npm install capacitor-camera-crop
# or
bun install capacitor-camera-crop

Then sync your Capacitor project:

npx cap sync

Requirements

  • Capacitor 7 or 8
  • iOS 14.0+
  • Android API 23+ (Android 6.0+)

Platform support

| Platform | Supported | Notes | |----------|-----------|-------| | iOS | ✅ | UIImagePicker / PHPicker + TOCropViewController | | Android | ✅ | ACTION_IMAGE_CAPTURE / ACTION_PICK + uCrop | | Web | ❌ | captureAndCrop() rejects with an unimplemented error |

Cropping is available on both native platforms. useSystemEditingIfAvailable affects iOS only (see the options table); on Android, free-vs-locked cropping is controlled solely by nativeCropping.

iOS Setup

Add the following keys to your Info.plist:

<key>NSCameraUsageDescription</key>
<string>We need camera access to take pictures.</string>
<key>NSPhotoLibraryUsageDescription</key>
<string>We need access to your photo library.</string>
<key>NSPhotoLibraryAddUsageDescription</key>
<string>We need to save cropped photos to your library.</string>

Android Setup

This plugin uses uCrop for cropping, which is published on JitPack. Add the JitPack repository to your app's root android/build.gradle (or settings.gradle if you use centralized repositories):

allprojects {
    repositories {
        google()
        mavenCentral()
        maven { url 'https://jitpack.io' }
    }
}

Permissions

This plugin does not require the CAMERA or READ_MEDIA_IMAGES permissions. It uses delegated intents — ACTION_IMAGE_CAPTURE (system camera app) and ACTION_PICK (system gallery) — which run in those apps and hand back a URI your app is temporarily granted to read.

⚠️ Do not add <uses-permission android:name="android.permission.CAMERA" /> to your manifest for this plugin. Declaring CAMERA without requesting it at runtime causes Android to block ACTION_IMAGE_CAPTURE with a permission-denial crash. Only add CAMERA if some other part of your app uses the camera directly, and then you must request it at runtime yourself.

FileProvider

You need a FileProvider in your app's AndroidManifest.xml (used to hand the camera app a URI to write the captured photo into):

<provider
    android:name="androidx.core.content.FileProvider"
    android:authorities="${applicationId}.fileprovider"
    android:exported="false"
    android:grantUriPermissions="true">
    <meta-data
        android:name="android.support.FILE_PROVIDER_PATHS"
        android:resource="@xml/file_paths" />
</provider>

Create android/app/src/main/res/xml/file_paths.xml:

<?xml version="1.0" encoding="utf-8"?>
<paths xmlns:android="http://schemas.android.com/apk/res/android">
    <cache-path name="cache" path="." />
    <external-cache-path name="external_cache" path="." />
</paths>

Usage

import { CapacitorCameraCrop } from 'capacitor-camera-crop';

// Open camera with cropping
async function takePicture() {
  try {
    const result = await CapacitorCameraCrop.captureAndCrop({
      source: 'camera',
      enableCropping: true,
      aspectRatio: '1:1',
      resultType: 'uri',
      quality: 90,
    });

    console.log('Image URI:', result.value);
    console.log('Dimensions:', result.width, 'x', result.height);
  } catch (error) {
    console.error('Error:', error);
  }
}

// Open gallery without cropping
async function selectImage() {
  try {
    const result = await CapacitorCameraCrop.captureAndCrop({
      source: 'gallery',
      enableCropping: false,
      resultType: 'uri',
    });

    console.log('Image URI:', result.value);
  } catch (error) {
    console.error('Error:', error);
  }
}

// Get base64 encoded image with custom aspect ratio
async function captureBase64() {
  try {
    const result = await CapacitorCameraCrop.captureAndCrop({
      source: 'camera',
      enableCropping: true,
      aspectRatio: { x: 16, y: 9 },
      resultType: 'base64',
      width: 1920,
      height: 1080,
      quality: 85,
    });

    console.log('Base64 image:', result.value);
  } catch (error) {
    console.error('Error:', error);
  }
}

// Use native crop controller (TOCropViewController on iOS, UCrop on Android)
async function captureWithNativeCropper() {
  try {
    const result = await CapacitorCameraCrop.captureAndCrop({
      source: 'camera',
      enableCropping: true,
      nativeCropping: true, // Uses TOCropViewController on iOS, UCrop on Android
      aspectRatio: '1:1',
      resultType: 'uri',
      quality: 90,
    });

    console.log('Cropped image:', result.value);
  } catch (error) {
    console.error('Error:', error);
  }
}

API

captureAndCrop(options?: CaptureAndCropOptions): Promise<CaptureAndCropResult>

Opens the camera or gallery, optionally crops the image, and returns the result.

CaptureAndCropOptions

| Property | Type | Default | Description | |----------|------|---------|-------------| | source | 'camera' \| 'gallery' | 'camera' | Source to pick the image from | | enableCropping | boolean | false | Enable cropping after capturing/selecting | | aspectRatio | 'free' \| '1:1' \| '4:3' \| '16:9' \| { x: number; y: number } | 'free' | Aspect ratio for cropping | | resultType | 'uri' \| 'base64' | 'uri' | Result type: file URI or base64 encoded string | | width | number | - | Maximum width (px) for the output image. Honored on both platforms; may be set independently of height | | height | number | - | Maximum height (px) for the output image. Honored on both platforms; may be set independently of width | | quality | number | 90 | JPEG quality (clamped to 0-100) | | useSystemEditingIfAvailable | boolean | true | iOS only. Use the built-in UIImagePicker editor when cropping. Ignored when nativeCropping=true. Has no effect on Android (free-vs-locked is controlled by nativeCropping) | | nativeCropping | boolean | false | Use the native crop controller (TOCropViewController on iOS, locked-aspect uCrop on Android). Overrides useSystemEditingIfAvailable on iOS |

CaptureAndCropResult

| Property | Type | Description | |----------|------|-------------| | value | string | The file URI or base64 encoded string | | mimeType | string | MIME type of the returned image | | width | number | Width of the image in pixels | | height | number | Height of the image in pixels |

Development

Building

bun install
bun run build

Example app

A runnable test harness lives in example/. It installs the plugin from the repo root and exercises captureAndCrop across every option on iOS and Android. See example/README.md for setup and the acceptance-test matrix.

License

MIT

Contributing

Contributions are welcome! See CONTRIBUTING.md for local setup, how to test native changes with the example/ app, and conventions.