Gathering detailed insights and metrics for cordova-plugin-camera-preview
Gathering detailed insights and metrics for cordova-plugin-camera-preview
Gathering detailed insights and metrics for cordova-plugin-camera-preview
Gathering detailed insights and metrics for cordova-plugin-camera-preview
npm install cordova-plugin-camera-preview
Module System
Unable to determine the module system for this package.
Min. Node Version
Typescript Support
Node Version
NPM Version
569 Stars
606 Commits
564 Forks
49 Watching
1 Branches
60 Contributors
Updated on 08 Nov 2024
Java (52.04%)
Objective-C (42.3%)
JavaScript (5.66%)
Cumulative downloads
Total Downloads
Last day
-25.4%
337
Compared to previous day
Last week
-2%
2,301
Compared to previous week
Last month
24.8%
10,223
Compared to previous month
Last year
0.5%
139,309
Compared to previous year
Cordova plugin that allows camera interaction from Javascript and HTML
Releases are being kept up to date when appropriate. However, this plugin is under constant development. As such it is recommended to use master to always have the latest fixes & features.
PR's are greatly appreciated.
Use any one of the installation methods listed below depending on which framework you use.
To install the master version with latest fixes and features
cordova plugin add https://github.com/cordova-plugin-camera-preview/cordova-plugin-camera-preview.git
ionic cordova plugin add https://github.com/cordova-plugin-camera-preview/cordova-plugin-camera-preview.git
meteor add cordova:cordova-plugin-camera-preview@https://github.com/cordova-plugin-camera-preview/cordova-plugin-camera-preview.git#[latest_commit_id]
<plugin spec="https://github.com/cordova-plugin-camera-preview/cordova-plugin-camera-preview.git" source="git" />
or if you want to use the last released version on npm
cordova plugin add cordova-plugin-camera-preview
ionic cordova plugin add cordova-plugin-camera-preview
meteor add cordova:cordova-plugin-camera-preview@X.X.X
<gap:plugin name="cordova-plugin-camera-preview" />
1<config-file platform="ios" target="*-Info.plist" parent="NSCameraUsageDescription" overwrite="true"> 2 <string>Allow the app to use your camera</string> 3</config-file> 4 5<!-- or for Phonegap --> 6 7<gap:config-file platform="ios" target="*-Info.plist" parent="NSCameraUsageDescription" overwrite="true"> 8 <string>Allow the app to use your camera</string> 9</gap:config-file>
onBackButton
)Starts the camera preview instance.
Options: All options stated are optional and will default to values here
x
- Defaults to 0y
- Defaults to 0width
- Defaults to window.screen.widthheight
- Defaults to window.screen.heightcamera
- See CAMERA_DIRECTION
- Defaults to front cameratoBack
- Defaults to false - Set to true if you want your html in front of your previewtapPhoto
- Defaults to true - Does not work if toBack is set to false in which case you use the takePicture methodtapFocus
- Defaults to false - Allows the user to tap to focus, when the view is in the foregroundpreviewDrag
- Defaults to false - Does not work if toBack is set to falsestoreToFile
- Defaults to false - Capture images to a file and return back the file path instead of returning base64 encoded data.disableExifHeaderStripping
- Defaults to false - Android Only - Disable automatic rotation of the image, and let the browser deal with it (keep reading on how to achieve it)1let options = { 2 x: 0, 3 y: 0, 4 width: window.screen.width, 5 height: window.screen.height, 6 camera: CameraPreview.CAMERA_DIRECTION.BACK, 7 toBack: false, 8 tapPhoto: true, 9 tapFocus: false, 10 previewDrag: false, 11 storeToFile: false, 12 disableExifHeaderStripping: false 13}; 14 15CameraPreview.startCamera(options);
When setting toBack
to true, remember to add the style below on your app's HTML or body element:
1html, body, .ion-app, .ion-content { 2 background-color: transparent; 3}
When both tapFocus
and tapPhoto
are true, the camera will focus, and take a picture as soon as the camera is done focusing.
If you capture large images in Android you may notice that performace is poor, in those cases you can set disableExifHeaderStripping
to true and instead just add some extra Javascript/HTML to get a proper display of your captured images without risking your application speed.
When capturing large images you may want them to be stored into a file instead of having them base64 encoded, as enconding at least on Android is very expensive. With the feature storeToFile
enabled the plugin will capture the image into a temporary file inside the application temporary cache (the same place where Cordova will extract your assets). This method is better used with disableExifHeaderStripping
to get the best possible performance.
1CameraPreview.stopCamera();
1CameraPreview.switchCamera();
1CameraPreview.show();
1CameraPreview.hide();
quality
defaults to 85
and specifies the quality/compression value: 0=max compression
, 100=max quality
.
1CameraPreview.takePicture({width:640, height:640, quality: 85}, function(base64PictureData|filePath) { 2 /* 3 if the storeToFile option is false (the default), then base64PictureData is returned. 4 base64PictureData is base64 encoded jpeg image. Use this data to store to a file or upload. 5 Its up to the you to figure out the best way to save it to disk or whatever for your application. 6 */ 7 8 /* 9 if the storeToFile option is set to true, then a filePath is returned. Note that the file 10 is stored in temporary storage, so you should move it to a permanent location if you 11 don't want the OS to remove it arbitrarily. 12 */ 13 14 // One simple example is if you are going to use it inside an HTML img src attribute then you would do the following: 15 imageSrcData = 'data:image/jpeg;base64,' + base64PictureData; 16 $('img#my-img').attr('src', imageSrcData); 17}); 18 19// OR if you want to use the default options. 20 21CameraPreview.takePicture(function(base64PictureData){ 22 /* code here */ 23});
startCamera
options. The argument quality
defaults to 85
and specifies the quality/compression value: 0=max compression
, 100=max quality
.
1CameraPreview.takeSnapshot({quality: 85}, function(base64PictureData){ 2 /* 3 base64PictureData is base64 encoded jpeg image. Use this data to store to a file or upload. 4 */ 5 6 // One simple example is if you are going to use it inside an HTML img src attribute then you would do the following: 7 imageSrcData = 'data:image/jpeg;base64,' +base64PictureData; 8 $('img#my-img').attr('src', imageSrcData); 9});
FOCUS_MODE
for possible values that can be returned.
1CameraPreview.getSupportedFocusModes(function(focusModes){ 2 focusModes.forEach(function(focusMode) { 3 console.log(focusMode + ', '); 4 }); 5});
focusMode
- FOCUS_MODE
1CameraPreview.setFocusMode(CameraPreview.FOCUS_MODE.CONTINUOUS_PICTURE);
FOCUS_MODE
for possible values that can be returned.
1CameraPreview.getFocusMode(function(currentFocusMode){ 2 console.log(currentFocusMode); 3});
FLASH_MODE
for possible values that can be returned
1CameraPreview.getSupportedFlashModes(function(flashModes){ 2 flashModes.forEach(function(flashMode) { 3 console.log(flashMode + ', '); 4 }); 5});
FLASH_MODE
for details about the possible values for flashMode.
1CameraPreview.setFlashMode(CameraPreview.FLASH_MODE.ON);
FLASH_MODE
for possible values that can be returned
1CameraPreview.getFlashMode(function(currentFlashMode){ 2 console.log(currentFlashMode); 3});
1CameraPreview.getHorizontalFOV(function(getHorizontalFOV){ 2 console.log(getHorizontalFOV); 3});
Currently this feature is for Android only. A PR for iOS support would be happily accepted
COLOR_EFFECT
for possible values that can be returned.
1CameraPreview.getSupportedColorEffects(function(colorEffects){ 2 colorEffects.forEach(function(color) { 3 console.log(color + ', '); 4 }); 5});
COLOR_EFFECT
for details about the possible values for colorEffect.
1CameraPreview.setColorEffect(CameraPreview.COLOR_EFFECT.NEGATIVE);
1CameraPreview.setZoom(2);
1CameraPreview.getZoom(function(currentZoom){ 2 console.log(currentZoom); 3});
1CameraPreview.getMaxZoom(function(maxZoom){ 2 console.log(maxZoom); 3});
WHITE_BALANCE_MODE
for details about the possible values returned.
1CameraPreview.getSupportedWhiteBalanceModes(function(whiteBalanceModes){ 2 console.log(whiteBalanceModes); 3});
WHITE_BALANCE_MODE
for details about the possible values returned.
1CameraPreview.getWhiteBalanceMode(function(whiteBalanceMode){ 2 console.log(whiteBalanceMode); 3});
WHITE_BALANCE_MODE
for details about the possible values for whiteBalanceMode.
1CameraPreview.setWhiteBalanceMode(CameraPreview.WHITE_BALANCE_MODE.CLOUDY_DAYLIGHT);
EXPOSURE_MODE
for details about the possible values returned.
1CameraPreview.getExposureModes(function(exposureModes){ 2 console.log(exposureModes); 3});
EXPOSURE_MODE
for details about the possible values returned.
1CameraPreview.getExposureMode(function(exposureMode){ 2 console.log(exposureMode); 3});
EXPOSURE_MODE
for details about the possible values for exposureMode.
1CameraPreview.setExposureMode(CameraPreview.EXPOSURE_MODE.CONTINUOUS);
1CameraPreview.getExposureCompensationRange(function(expoxureRange){ 2 console.log("min: " + exposureRange.min); 3 console.log("max: " + exposureRange.max); 4});
1CameraPreview.getExposureCompensation(function(expoxureCompensation){ 2 console.log(exposureCompensation); 3});
1CameraPreview.setExposureCompensation(-2); 2CameraPreview.setExposureCompensation(3);
1CameraPreview.setPreviewSize({width: window.screen.width, height: window.screen.height});
1CameraPreview.getSupportedPictureSizes(function(dimensions){ 2 // note that the portrait version, width and height swapped, of these dimensions are also supported 3 dimensions.forEach(function(dimension) { 4 console.log(dimension.width + 'x' + dimension.height); 5 }); 6});
Currently this feature is for Android only. A PR for iOS support would be happily accepted
1CameraPreview.getCameraCharacteristics(function(characteristics){ 2 console.log(characteristics); 3});
Example Characteristics:
{
"CAMERA_CHARACTERISTICS": [
{
"INFO_SUPPORTED_HARDWARE_LEVEL": 1,
"LENS_FACING": 1,
"SENSOR_INFO_PHYSICAL_SIZE_WIDTH": 5.644999980926514,
"SENSOR_INFO_PHYSICAL_SIZE_HEIGHT": 4.434999942779541,
"SENSOR_INFO_PIXEL_ARRAY_SIZE_WIDTH": 4032,
"SENSOR_INFO_PIXEL_ARRAY_SIZE_HEIGHT": 3024,
"LENS_INFO_AVAILABLE_FOCAL_LENGTHS": [
{
"FOCAL_LENGTH": 4.199999809265137
}
]
},
{
"INFO_SUPPORTED_HARDWARE_LEVEL": 0,
"LENS_FACING": 0,
"SENSOR_INFO_PHYSICAL_SIZE_WIDTH": 3.494999885559082,
"SENSOR_INFO_PHYSICAL_SIZE_HEIGHT": 2.625999927520752,
"SENSOR_INFO_PIXEL_ARRAY_SIZE_WIDTH": 2608,
"SENSOR_INFO_PIXEL_ARRAY_SIZE_HEIGHT": 1960,
"LENS_INFO_AVAILABLE_FOCAL_LENGTHS": [
{
"FOCAL_LENGTH": 2.0999999046325684
}
]
}
]
}
1let xPoint = event.x; 2let yPoint = event.y 3CameraPreview.tapToFocus(xPoint, yPoint);
1CameraPreview.onBackButton(function() { 2 console.log('Back button pushed'); 3});
When working with local files you may want to display those on certain containers like canvas, given that file:// is not always a valid url type, you need to first convert it explicitly to a blob, before you push it further into the display side. The function getBlob will do the proper conversion for you, and if succedeed will pass the content on it's callback function as first argument.
1 2function displayImage(content) { 3 var ctx = $("canvas").getContext('2d'); 4 5 img.onload = function(){ 6 ctx.drawImage(img, 0, 0) 7 } 8 9 img.src = URL.createObjectURL(blob); 10} 11 12function takePicture() { 13 CameraPreview.takePicture({width: app.dimension.width, height: app.dimension.height}, function(data){ 14 if (cordova.platformId === 'android') { 15 CameraPreview.getBlob('file://' + data, function(image) { 16 displayImage(image); 17 }); 18 } else { 19 displayImage('data:image/jpeg;base64,' + data); 20 } 21 }); 22}
Currently this feature is for Android only. A PR for iOS support would be happily accepted
1var opts = { 2 cameraDirection: CameraPreview.CAMERA_DIRECTION.BACK, 3 width: (window.screen.width / 2), 4 height: (window.screen.height / 2), 5 quality: 60, 6 withFlash: false 7} 8 9CameraPreview.startRecordVideo(opts, function(filePath){ 10 console.log(filePath) 11});
Currently this feature is for Android only. A PR for iOS support would be happily accepted
1CameraPreview.stopRecordVideo(function(filePath) { 2 console.log(filePath); 3});
Name | Type | Default | Note |
---|---|---|---|
FIXED | string | fixed | |
AUTO | string | auto | |
CONTINUOUS | string | continuous | IOS Only |
CONTINUOUS_PICTURE | string | continuous-picture | Android Only |
CONTINUOUS_VIDEO | string | continuous-video | Android Only |
EDOF | string | edof | Android Only |
INFINITY | string | infinity | Android Only |
MACRO | string | macro | Android Only |
Name | Type | Default | Note |
---|---|---|---|
OFF | string | off | |
ON | string | on | |
AUTO | string | auto | |
RED_EYE | string | red-eye | Android Only |
TORCH | string | torch |
Name | Type | Default |
---|---|---|
BACK | string | back |
FRONT | string | front |
Name | Type | Default | Note |
---|---|---|---|
AQUA | string | aqua | Android Only |
BLACKBOARD | string | blackboard | Android Only |
MONO | string | mono | |
NEGATIVE | string | negative | |
NONE | string | none | |
POSTERIZE | string | posterize | |
SEPIA | string | sepia | |
SOLARIZE | string | solarize | Android Only |
WHITEBOARD | string | whiteboard | Android Only |
Name | Type | Default | Note |
---|---|---|---|
AUTO | string | auto | IOS Only |
CONTINUOUS | string | continuous | |
CUSTOM | string | custom | |
LOCK | string | lock | IOS Only |
Note: Use AUTO to allow the device automatically adjusts the exposure once and then changes the exposure mode to LOCK.
Name | Type | Default | Note |
---|---|---|---|
LOCK | string | lock | |
AUTO | string | auto | |
CONTINUOUS | string | continuous | IOS Only |
INCANDESCENT | string | incandescent | |
CLOUDY_DAYLIGHT | string | cloudy-daylight | |
DAYLIGHT | string | daylight | |
FLUORESCENT | string | fluorescent | |
SHADE | string | shade | |
TWILIGHT | string | twilight | |
WARM_FLUORESCENT | string | warm-fluorescent |
cordova-plugin-camera-preview-sample-app for a complete working Cordova example for Android and iOS platforms.
Maintained by Weston Ganger - @westonganger
Created by Marcel Barbosa Pinto @mbppower
No vulnerabilities found.
Reason
no binaries found in the repo
Reason
license file detected
Details
Reason
0 existing vulnerabilities detected
Reason
Found 10/24 approved changesets -- score normalized to 4
Reason
2 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 1
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
security policy file not detected
Details
Reason
project is not fuzzed
Details
Reason
branch protection not enabled on development/release branches
Details
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
Score
Last Scanned on 2024-11-25
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More