@jonz94/capacitor-image-picker
Capacitor plugin for multiple image selection.
npm install @jonz94/capacitor-image-picker
npx cap sync
This plugin uses a forked version of YPImagePicker under the hood.
In order to use this plugin, you need to manually modified ios/App/Podfile
as following:
target 'App' do
capacitor_pods
# Add your Pods here
+ pod 'YPImagePicker', :git => 'https://github.com/jonz94/YPImagePicker.git', :tag => '5.2.2.0'
end
After modified ios/App/Podfile
, make sure to run pod update
command to sync up the iOS project.
iOS requires the following usage description be added and filled out for your app in Info.plist
:
NSPhotoLibraryUsageDescription
(Privacy - Photo Library Usage Description
)
Read about Configuring Info.plist
in the iOS Guide for more information on setting iOS permissions in Xcode.
This plugin uses a forked version of TedImagePicker under the hood.
Setup JitPack Repository
Add following line to your android/build.gradle
:
allprojects {
repositories {
google()
mavenCentral()
+ maven { url "https://jitpack.io" }
}
}
Add following lines to your android/app/build.gradle
:
android {
compileSdkVersion rootProject.ext.compileSdkVersion
defaultConfig {
// ...
}
buildTypes {
// ...
}
+ dataBinding {
+ enabled true
+ }
}
After modified android/build.gradle
and android/app/build.gradle
, make sure to run Sync Project with Gradle Files
in Android Studio.
This plugin requires the following permissions be added to your AndroidManifest.xml
:
<uses-permission android:name="android.permission.READ_MEDIA_IMAGES" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" android:maxSdkVersion="32" />
The storage permissions are for reading photo files.
Read about Setting Permissions in the Android Guide for more information on setting Android permissions.
No configuration required for this plugin.
import { ImagePicker } from '@jonz94/capacitor-image-picker';
const pickSingleImage = async () => {
const { images } = await ImagePicker.present();
// console.log(images[0]);
return images[0];
}
const pickMultipleImages = async () => {
const { images } = await ImagePicker.present({ limit: 10 });
// console.log(images);
return images;
}
const pickMultipleImagesWithCustomText = async () => {
const { images } = await ImagePicker.present({
limit: 10,
surpassLimitMessage: 'You cannot select more than %d images.',
titleText: 'Pick a image',
albumsTitleText: 'Chose an album',
libraryTitleText: 'Click here to change library',
cancelText: 'Go Back',
doneText: 'OK',
});
// console.log(images);
return images;
}
present(options?: PresentOptions | undefined) => Promise<Images>
Param | Type |
---|---|
options |
PresentOptions |
Returns: Promise<Images>
Prop | Type | Description | Since |
---|---|---|---|
images |
Image[] |
Array of all the picked images. | 1.0.0 |
Prop | Type | Description | Since |
---|---|---|---|
path |
string |
The file path of the image. | 1.0.0 |
webPath |
string |
webPath returns a path that can be used to set the src attribute of an image for efficient loading and rendering. | 1.0.0 |
mimeType |
string |
The mime type of the image. | 1.0.0 |
Prop | Type | Description | Default | Since |
---|---|---|---|---|
limit |
number |
Maximum number of images the user will be able to choose. Note: If this is set to 1, upon selection of a single image. | 1 |
1.0.0 |
surpassLimitMessage |
string |
The message when user select more than maximum number of pictures. This message will not occur when limit is 1. Note: The message MUST INCLUDE ONE AND ONLY ONE %d as a placeholder for showing the value of limit . |
"You can only select %d images." |
1.0.0 |
titleText |
string |
Android only: The title of the image picker. | "Select Image" |
1.0.0 |
albumAllText |
string |
Android only: name of the all photos album. | "All" |
1.2.0 |
libraryTitleText |
string |
iOS only: The title of the library. | "Library" |
1.0.0 |
albumsTitleText |
string |
iOS only: The title of the albums. | "Albums" |
1.0.0 |
cancelText |
string |
iOS only: The text to display on the cancel button. Note: on Android, the cancel button is shown as icon-only back button with no text. | "Cancel" |
1.0.0 |
doneText |
string |
The text to display on the done button. | "Done" |
1.0.0 |
See CHANGELOG.md.
See LICENSE.
- EinfachHans's Advanced ImagePicker Cordova Plugin inspires this Capacitor plugin.
- YPImagePicker provides iOS implementation.
- TedImagePicker provides Android implementation.
- Official Capacitor Camera Plugin provides
saveTemporaryImage()
implementation on iOS. - Capawesome's Capacitor File Picker Plugin provides
getMimeTypeFromURL()
implementation on iOS.