1.1.3 • Published 4 years ago

@uni/image v1.1.3

Weekly downloads
44
License
BSD-3-Clause
Repository
github
Last release
4 years ago

@uni/image

npm

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

PropertyTypeDescriptionrequiredDefault
optionsobject -
options.countnumberThe maximum number of images allowed1
options.sourceTypeArray<string> The source of the image'album', 'camera'
options.successFunction The callback function for a successful API call-
options.failFunction The callback function for a failed API call-
options.completeFunction The callback function used when the API call completed (always executed whether the call succeeds or fails)-

Special Arguments

PropertyTypeDescriptionrequiredDefaultSupported
options.sizeTypeArray.<string> The size of the select image'original', 'compressed'

Return

PropertyTypeDescription
tempFilePathsArray<string> The list of local temporary file paths to images
tempFilesArray<Object>The local temporary file list for images
res.tempFiles
PropertyTypeDescription
pathstring The path to the local temporary file
sizenumber 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

PropertyTypeDescriptionrequiredDefault
optionsobject ✔️-
options.srcstring The path to the image. It can be a relative path, a temporary file path, or a file compress-image path✔️-
options.qualitynumber Compression quality. The value range is 0-3.-
options.successFunction The callback function for a successful API call-
options.failFunction The callback function for a failed API call-
options.completeFunction The callback function used when the API call completed (always executed whether the call succeeds or fails)-

Return

PropertyTypeDescription
tempFilePathstringThe 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

PropertyTypeDescriptionrequiredDefault
optionsobject ✔️-
options.srcstring The path to the image. It can be a relative path or a path to a network image.✔️-
options.successFunction The callback function for a successful API call-
options.failFunction The callback function for a failed API call-
options.completeFunction The callback function used when the API call completed (always executed whether the call succeeds or fails)-

Return

PropertyTypeDescription
widthnumber The original width of the image (in px).
heightnumber The original height of the image (in px).
pathnumber The local path to the image

Special Return

PropertyTypeDescriptionSupported
orientationstring Device orientation when taking photos
typestring Image format no Dingding
orientation
ValueDescription
upDefault orientation (landscape)
up-mirroredMirrored orientation of up
downRotates the device 180 degrees
down-mirroredMirrored orientation of down
left-mirroredMirrored orientation of left
rightRotates the device 90 degrees clockwise
right-mirroredMirrored orientation of right
leftRotates 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

PropertyTypeDescriptionrequiredDefault
optionsobject -
options.urlsArray<string>The URLs of images to preview
options.currentnumber The index of the current image in urls list0
options.successFunction The callback function for a successful API call-
options.failFunction The callback function for a failed API call-
options.completeFunction The callback function used when the API call completed (always executed whether the call succeeds or fails)-

Special Arguments

PropertyTypeDescriptionrequiredDefaultSupported
options.showmenuboolean show longpress menutrue 2.13.0
options.imagesArray<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

PropertyTypeDescriptionrequiredDefault
optionsobject ✔️-
options.urlstring 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.successFunction The callback function for a successful API call-
options.failFunction The callback function for a failed API call-
options.completeFunction The callback function used when the API call completed (always executed whether the call succeeds or fails)-

Special Arguments

PropertyTypeDescriptionrequiredDefaultSupported
options.showActionSheetboolean show operation menus for imagetrue
1.1.3

4 years ago

1.1.2

4 years ago

1.1.1

4 years ago

1.1.0

4 years ago

1.0.9

4 years ago

1.0.8

4 years ago

1.0.7

4 years ago

1.0.6

4 years ago

1.0.5

4 years ago

1.0.5-beta

4 years ago

1.0.5-beta1

4 years ago

1.0.4

4 years ago

1.0.4-beta

4 years ago

1.0.3

4 years ago

1.0.2

4 years ago

1.0.1

4 years ago

1.0.0

4 years ago

1.0.0-beta

4 years ago