1.0.1 • Published 4 years ago
universal-image v1.0.1
universal-image
Image operation.
Support
Install
$ npm install universal-image --save
Methods
choose(options)
Take a photo or select an image from a local album.
Parameters
Property | Type | Default | Required | Description | Support |
---|---|---|---|---|---|
count | Number | 1 | x | Maximum number of optional photos | |
sizeType | String Array | 'original', 'compressed' | x | Compressed original picture, compressed picture | |
sourceType | String Array | 'camera', 'album' | x | Photo album selection or photo taking |
preview(options)
preview image.
Parameters
Property | Type | Default | Required | Description | Support |
---|---|---|---|---|---|
urls | String Array | √ | A list of images to preview | ||
current | Number | 0 | x | Currently displays image index |
getInfo(options)
Get image information.
Parameters
Property | Type | Default | Required | Description | Support |
---|---|---|---|---|---|
src | String | √ | Image path, can be relative path, temporary file path, storage file path, network image path |
compress(options)
Compress image.
Parameters
Property | Type | Default | Required | Description | Support |
---|---|---|---|---|---|
filePaths | String Array | √ | An array of image addresses to compress | ||
src | String | √ | Image path, can be relative path, temporary file path, storage file path, network image path | ||
compressLevel | Number | 4 | x | Compression level, support 0 ~ 4 integer | |
quality | Number | 80 | x | Compression mass, range 0 ~ 100, the smaller the value, the lower the mass |
save(options)
Save Image.
Parameters
Property | Type | Default | Required | Description | Support |
---|---|---|---|---|---|
url | String | √ | Image file path | ||
showActionSheet | Boolean | true | x | Whether to display picture action menu |
Example
import Image from 'universal-image';
Image.choose({
sourceType: ['camera','album'],
count: 2,
success: (res) => {
console.log(res.filePaths);
},
fail: () => {
console.log('fail');
}
});
Image.preview({
current: 2,
urls: [
'https://img.alicdn.com/tps/TB1sXGYIFXXXXc5XpXXXXXXXXXX.jpg',
'https://img.alicdn.com/tps/TB1pfG4IFXXXXc6XXXXXXXXXXXX.jpg',
'https://img.alicdn.com/tps/TB1h9xxIFXXXXbKXXXXXXXXXXXX.jpg'
],
});
Image.getInfo({
src:'https://img.alicdn.com/tps/TB1sXGYIFXXXXc5XpXXXXXXXXXX.jpg',
success: (res) => {
console.log(JSON.stringify(res))
}
});
Image.compress({
filePaths: [''],
success: data => {
console.log(data);
}
});
Image.choose({
sourceType: ['camera','album'],
success: (res) => {
console.log(res);
Image.save({
url: res.filePaths[0],
success: () => {
console.log('success: ');
},
});
},
fail: (err) => {
console.log('fail: ', err);
}
});