@uni/image v1.1.3
@uni/image
Install
$ npm install @uni/image --save
or
$ npm install @uni/apis --save
chooseImage
Selects an image from the local album or takes a photo with the camera.
Supported
Usage
import { chooseImage } from '@uni/image';
chooseImage({
count: 1,
sourceType: ['album', 'camera'],
success (res) {
const tempFilePaths = res.tempFilePaths
}
});
// promise
chooseImage({
count: 1,
sourceType: ['album', 'camera']
}).then(res => {
const tempFilePaths = res.tempFilePaths
});
You can also import from the big package:
import { image } from '@uni/apis';
image.chooseImage({
count: 1,
sourceType: ['album', 'camera'],
success (res) {
const tempFilePaths = res.tempFilePaths
}
});
// promise
image.chooseImage({
count: 1,
sourceType: ['album', 'camera']
}).then(res => {
const tempFilePaths = res.tempFilePaths
});
Methods
chooseImage(options)
Arguments
Property | Type | Description | required | Default |
---|---|---|---|---|
options | object | ✘ | - | |
options.count | number | The maximum number of images allowed | ✘ | 1 |
options.sourceType | Array<string> | The source of the image | ✘ | 'album', 'camera' |
options.success | Function | The callback function for a successful API call | ✘ | - |
options.fail | Function | The callback function for a failed API call | ✘ | - |
options.complete | Function | The callback function used when the API call completed (always executed whether the call succeeds or fails) | ✘ | - |
Special Arguments
Property | Type | Description | required | Default | Supported |
---|---|---|---|---|---|
options.sizeType | Array.<string> | The size of the select image | ✘ | 'original', 'compressed' |
Return
Property | Type | Description |
---|---|---|
tempFilePaths | Array<string> | The list of local temporary file paths to images |
tempFiles | Array<Object> | The local temporary file list for images |
res.tempFiles
Property | Type | Description |
---|---|---|
path | string | The path to the local temporary file |
size | number | The size of a local temporary file, in bytes |
compressImage
Compresses images. Multiple types of compression quality are available.
Supported
Usage
import { compressImage } from '@uni/image';
compressImage({
src: 'http://img.icon.com/a.png',
quality: 1,
success: (res) => {
console.log('success', res);
},
fail: (res) => {
console.log('fail', res);
},
complete: (res) => {
console.log('complete', res);
}
});
// promise
compressImage({
src: 'http://img.icon.com/a.png',
quality: 1
}).then(response => {})
.catch(error => {})
.finally(res => {});
You can also import from the big package:
import { image } from '@uni/apis';
image.compressImage({
src: 'http://img.icon.com/a.png',
quality: 1,
success: (res) => {
console.log('success', res);
},
fail: (res) => {
console.log('fail', res);
},
complete: (res) => {
console.log('complete', res);
}
});
// promise
image.compressImage({
src: 'http://img.icon.com/a.png',
quality: 1
}).then(response => {})
.catch(error => {})
.finally(res => {});
Methods
compressImage(options)
Arguments
Property | Type | Description | required | Default |
---|---|---|---|---|
options | object | ✔️ | - | |
options.src | string | The path to the image. It can be a relative path, a temporary file path, or a file compress-image path | ✔️ | - |
options.quality | number | Compression quality. The value range is 0-3. | ✘ | - |
options.success | Function | The callback function for a successful API call | ✘ | - |
options.fail | Function | The callback function for a failed API call | ✘ | - |
options.complete | Function | The callback function used when the API call completed (always executed whether the call succeeds or fails) | ✘ | - |
Return
Property | Type | Description |
---|---|---|
tempFilePath | string | The temporary file path to the compressed image |
getImageInfo
Obtains image information. For network images, it only takes effect when the download domain name is configured.
Supported
Usage
import { getImageInfo } from '@uni/image';
getImageInfo({
src: 'http://img.icon.com/a.png',
success: (res) => {
console.log('success', res);
},
fail: (res) => {
console.log('fail', res);
},
complete: (res) => {
console.log('complete', res);
}
});
// promise
getImageInfo({
src: 'http://img.icon.com/a.png'
}).then(response => {})
.catch(error => {})
.finally(res => {});
You can also import from the big package:
import { image } from '@uni/apis';
image.getImageInfo({
src: 'http://img.icon.com/a.png',
success: (res) => {
console.log('success', res);
},
fail: (res) => {
console.log('fail', res);
},
complete: (res) => {
console.log('complete', res);
}
});
// promise
image.getImageInfo({
src: 'http://img.icon.com/a.png'
}).then(response => {})
.catch(error => {})
.finally(res => {});
Methods
getImageInfo(options)
Arguments
Property | Type | Description | required | Default |
---|---|---|---|---|
options | object | ✔️ | - | |
options.src | string | The path to the image. It can be a relative path or a path to a network image. | ✔️ | - |
options.success | Function | The callback function for a successful API call | ✘ | - |
options.fail | Function | The callback function for a failed API call | ✘ | - |
options.complete | Function | The callback function used when the API call completed (always executed whether the call succeeds or fails) | ✘ | - |
Return
Property | Type | Description |
---|---|---|
width | number | The original width of the image (in px). |
height | number | The original height of the image (in px). |
path | number | The local path to the image |
Special Return
Property | Type | Description | Supported |
---|---|---|---|
orientation | string | Device orientation when taking photos | |
type | string | Image format | no Dingding |
orientation
Value | Description |
---|---|
up | Default orientation (landscape) |
up-mirrored | Mirrored orientation of up |
down | Rotates the device 180 degrees |
down-mirrored | Mirrored orientation of down |
left-mirrored | Mirrored orientation of left |
right | Rotates the device 90 degrees clockwise |
right-mirrored | Mirrored orientation of right |
left | Rotates the device 90 degrees counterclockwise |
previewImage
Previews the image in full screen on a new page. You can save or send it to others while preview.
Supported
Usage
import { previewImage } from '@uni/image';
previewImage({
urls: ['url1', 'url2'],
current: 1,
});
You can also import from the big package:
import { image } from '@uni/apis';
image.previewImage({
urls: ['url1', 'url2'],
current: 1,
});
Methods
previewImage(options)
Arguments
Property | Type | Description | required | Default |
---|---|---|---|---|
options | object | ✘ | - | |
options.urls | Array<string> | The URLs of images to preview | ✘ | |
options.current | number | The index of the current image in urls list | ✘ | 0 |
options.success | Function | The callback function for a successful API call | ✘ | - |
options.fail | Function | The callback function for a failed API call | ✘ | - |
options.complete | Function | The callback function used when the API call completed (always executed whether the call succeeds or fails) | ✘ | - |
Special Arguments
Property | Type | Description | required | Default | Supported |
---|---|---|---|---|---|
options.showmenu | boolean | show longpress menu | ✘ | true | 2.13.0 |
options.images | Array<object> | Support the picture link list of the original picture. Note that the order must be consistent with the urls. images: {url:'Small image address', origin_url:'Original image address'},... | ✘ | - |
saveImage
Saves images to the system album.
Supported
Usage
import { saveImage } from '@uni/image';
saveImage({
url: 'http://img.icon.com/a.png',
});
You can also import from the big package:
import { image } from '@uni/apis';
image.saveImage({
url: 'http://img.icon.com/a.png',
});
Methods
saveImage(options)
Arguments
Property | Type | Description | required | Default |
---|---|---|---|---|
options | object | ✔️ | - | |
options.url | string | The path to the image file. It can be a temporary or permanent file path. The path to a network image is not supported | ✔️ | - |
options.success | Function | The callback function for a successful API call | ✘ | - |
options.fail | Function | The callback function for a failed API call | ✘ | - |
options.complete | Function | The callback function used when the API call completed (always executed whether the call succeeds or fails) | ✘ | - |
Special Arguments
Property | Type | Description | required | Default | Supported |
---|---|---|---|---|---|
options.showActionSheet | boolean | show operation menus for image | ✘ | true |
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago