react-native-image-picker vs react-native-image-crop-picker vs react-native-camera
React Native 画像処理ライブラリ
react-native-image-pickerreact-native-image-crop-pickerreact-native-camera類似パッケージ:
React Native 画像処理ライブラリ

これらのライブラリは、React Nativeアプリケーションにおける画像の取得、加工、表示を容易にするためのツールです。これらのパッケージは、カメラ機能や画像の選択、トリミング、クロッピングなどの機能を提供し、ユーザーが画像を操作する際の利便性を向上させます。

npmのダウンロードトレンド
3 年
GitHub Starsランキング
統計詳細
パッケージ
ダウンロード数
Stars
サイズ
Issues
公開日時
ライセンス
react-native-image-picker369,8348,620189 kB3307ヶ月前MIT
react-native-image-crop-picker124,7976,3202.2 MB6371ヶ月前MIT
react-native-camera59,6799,650-1444年前MIT AND Apache-2.0 AND BSD-3-Clause
機能比較: react-native-image-picker vs react-native-image-crop-picker vs react-native-camera

カメラ機能

  • react-native-image-picker:

    このライブラリは、カメラを起動して画像を撮影する機能を提供しますが、リアルタイムのプレビューや高度なカメラ機能はありません。シンプルな画像選択が主な目的です。

  • react-native-image-crop-picker:

    このライブラリはカメラ機能を持っていませんが、画像を選択する際にカメラを起動するオプションを提供します。主に画像のトリミングやクロッピングに特化しています。

  • react-native-camera:

    このライブラリは、リアルタイムでカメラを使用するための強力な機能を提供します。QRコードやバーコードのスキャン、カメラのフラッシュ、ズーム機能など、さまざまなカスタマイズが可能です。また、カメラのプレビューを直接表示することができ、ユーザーが撮影する際の体験を向上させます。

画像トリミング

  • react-native-image-picker:

    このライブラリにはトリミング機能はありませんが、選択した画像をそのまま使用することができます。

  • react-native-image-crop-picker:

    このライブラリは、選択した画像をトリミングするための直感的なインターフェースを提供します。ユーザーは簡単に画像を選択し、必要な部分だけを切り取ることができます。

  • react-native-camera:

    このライブラリにはトリミング機能はありませんが、撮影した画像を後処理するためのフレームワークを提供します。

ユーザーインターフェース

  • react-native-image-picker:

    シンプルなユーザーインターフェースを提供し、ユーザーがカメラまたはフォトライブラリから画像を簡単に選択できるようにします。

  • react-native-image-crop-picker:

    ユーザーが画像を選択し、トリミングするための使いやすいインターフェースを提供します。

  • react-native-camera:

    カスタマイズ可能なカメラUIを提供しますが、実装には追加の作業が必要です。

パフォーマンス

  • react-native-image-picker:

    シンプルな画像選択機能のため、パフォーマンスは良好です。

  • react-native-image-crop-picker:

    画像のトリミング処理はデバイスの性能に依存しますが、一般的に高いパフォーマンスを発揮します。

  • react-native-camera:

    リアルタイムでの画像処理を行うため、パフォーマンスが重要です。最適化されたカメラ機能により、スムーズな撮影体験を提供します。

サポートとメンテナンス

  • react-native-image-picker:

    このライブラリは広く使用されており、サポートが充実していますが、更新頻度は他のライブラリに比べて少ない場合があります。

  • react-native-image-crop-picker:

    このライブラリも活発にメンテナンスされており、ユーザーからのフィードバックに基づいて改善が行われています。

  • react-native-camera:

    アクティブなコミュニティと定期的な更新があり、最新のReact Nativeバージョンに対応しています。

選び方: react-native-image-picker vs react-native-image-crop-picker vs react-native-camera
  • react-native-image-picker:

    シンプルに画像を選択したい場合は、react-native-image-pickerを選択してください。このライブラリは、カメラまたはフォトライブラリから画像を選択するための基本的な機能を提供します。

  • react-native-image-crop-picker:

    画像のトリミングやクロッピングを重視する場合は、react-native-image-crop-pickerが最適です。このライブラリは、ユーザーが選択した画像を簡単にトリミングできるインターフェースを提供します。

  • react-native-camera:

    カメラ機能を直接使用したい場合や、リアルタイムでの画像処理が必要な場合は、react-native-cameraを選択してください。特に、QRコードスキャンやバーコードスキャンなどの機能が必要な場合に適しています。

react-native-image-picker のREADME

react-native-image-picker 🎆

A React Native module that allows you to select a photo/video from the device library or camera.

npm downloads npm package License

Installation

yarn add react-native-image-picker

New Architecture

To take advantage of the new architecture run-

iOS

RCT_NEW_ARCH_ENABLED=1 npx pod-install ios

Android

Set newArchEnabled to true inside android/gradle.properties

Pre-Fabric (AKA not using the new architecture)

npx pod-install ios

Post-install Steps

iOS

Add the appropriate keys to your Info.plist depending on your requirement:

RequirementKey
Select image/video from photosNSPhotoLibraryUsageDescription
Capture ImageNSCameraUsageDescription
Capture VideoNSCameraUsageDescription & NSMicrophoneUsageDescription

Android

No permissions required (saveToPhotos requires permission check).

Note: This library does not require Manifest.permission.CAMERA, if your app declares as using this permission in manifest then you have to obtain the permission before using launchCamera.

Targeting Android API Levels Below 30

If your app's minSdkVersion is set to below 30 and it does not already include or depend on androidx.activity:activity:1.9.+ or a newer version, you'll need to add the following line to the dependencies section of your app/build.gradle file to ensure support for the backported AndroidX Photo Picker:

dependencies {
    ...
    implementation("androidx.activity:activity:1.9.+")
    ...
}

Additionally, you may need to update your AndroidManifest.xml to trigger the installation of the backported Photo Picker. For reference, you can check the example app's configuration in example/android/app/src/main/AndroidManifest.xml and example/android/app/build.gradle.

For more details, consult the Android documentation on AndroidX Photo Picker: https://developer.android.com/training/data-storage/shared/photopicker

API Reference

Methods

import {launchCamera, launchImageLibrary} from 'react-native-image-picker';

launchCamera()

Launch camera to take photo or video.

launchCamera(options?, callback);

// You can also use as a promise without 'callback':
const result = await launchCamera(options?);

See Options for further information on options.

The callback will be called with a response object, refer to The Response Object.

launchImageLibrary

Launch gallery to pick image or video.

launchImageLibrary(options?, callback)

// You can also use as a promise without 'callback':
const result = await launchImageLibrary(options?);

See Options for further information on options.

The callback will be called with a response object, refer to The Response Object.

Options

OptioniOSAndroidWebDescription
mediaTypeOKOKOKphoto or video or mixed(launchCamera on Android does not support 'mixed'). Web only supports 'photo' for now.
restrictMimeTypesNOOKNOArray containing the mime-types allowed to be picked. Default is empty (everything).
maxWidthOKOKNOTo resize the image.
maxHeightOKOKNOTo resize the image.
videoQualityOKOKNOlow, medium, or high on iOS, low or high on Android.
durationLimitOKOKNOVideo max duration (in seconds).
qualityOKOKNO0 to 1, photos.
conversionQualityNOOKNOFor conversion from HEIC/HEIF to JPEG, 0 to 1. Default is 0.92
cameraTypeOKOKNO'back' or 'front' (May not be supported in few android devices).
includeBase64OKOKOKIf true, creates base64 string of the image (Avoid using on large image files due to performance).
includeExtraOKOKNOIf true, will include extra data which requires library permissions to be requested (i.e. exif data).
saveToPhotosOKOKNO(Boolean) Only for launchCamera, saves the image/video file captured to public photo.
selectionLimitOKOKOKSupports providing any integer value. Use 0 to allow any number of files on iOS version >= 14 & Android version >= 13. Default is 1.
presentationStyleOKNONOControls how the picker is presented. currentContext, pageSheet, fullScreen, formSheet, popover, overFullScreen, overCurrentContext. Default is currentContext.
formatAsMp4OKNONOConverts the selected video to MP4 (iOS Only).
assetRepresentationModeOKOKNOA mode that determines which representation to use if an asset contains more than one on iOS or disables HEIC/HEIF to JPEG conversion on Android if set to 'current'. Possible values: 'auto', 'current', 'compatible'. Default is 'auto'.

|

The Response Object

keyiOSAndroidWebDescription
didCancelOKOKOKtrue if the user cancelled the process
errorCodeOKOKOKCheck ErrorCode for all error codes
errorMessageOKOKOKDescription of the error, use it for debug purpose only
assetsOKOKOKArray of the selected media, refer to Asset Object

Asset Object

keyiOSAndroidWebPhoto/VideoRequires PermissionsDescription
base64OKOKOKPHOTO ONLYNOThe base64 string of the image (photos only)
uriOKOKOKBOTHNOThe file uri in app specific cache storage. Except when picking video from Android gallery where you will get read only content uri, to get file uri in this case copy the file to app specific storage using any react-native library. For web it uses the base64 as uri.
originalPathNOOKNOBOTHNOThe original file path.
widthOKOKOKBOTHNOAsset dimensions
heightOKOKOKBOTHNOAsset dimensions
fileSizeOKOKNOBOTHNOThe file size
typeOKOKNOBOTHNOThe file type
fileNameOKOKNOBOTHNOThe file name
durationOKOKNOVIDEO ONLYNOThe selected video duration in seconds
bitrate---OKNOVIDEO ONLYNOThe average bitrate (in bits/sec) of the selected video, if available. (Android only)
timestampOKOKNOBOTHYESTimestamp of the asset. Only included if 'includeExtra' is true
idOKOKNOBOTHYESlocal identifier of the photo or video. On Android, this is the same as fileName

Note on file storage

Image/video captured via camera will be stored in temporary folder allowing it to be deleted any time, so don't expect it to persist. Use saveToPhotos: true (default is false) to save the file in the public photos. saveToPhotos requires WRITE_EXTERNAL_STORAGE permission on Android 28 and below (The permission has to obtained by the App manually as the library does not handle that).

For web, this doesn't work.

ErrorCode

CodeDescription
camera_unavailableCamera not available on device
permissionPermission not satisfied
othersOther errors (check errorMessage for description)

License

MIT