1.0.1 • Published 4 years ago

universal-image v1.0.1

Weekly downloads
17
License
-
Repository
-
Last release
4 years ago

universal-image npm

Image operation.

Support

Install

$ npm install universal-image --save

Methods

choose(options)

Take a photo or select an image from a local album.

Parameters

PropertyTypeDefaultRequiredDescriptionSupport
countNumber1xMaximum number of optional photos
sizeTypeString Array'original', 'compressed'xCompressed original picture, compressed picture
sourceTypeString Array'camera', 'album'xPhoto album selection or photo taking

preview(options)

preview image.

Parameters

PropertyTypeDefaultRequiredDescriptionSupport
urlsString ArrayA list of images to preview
currentNumber0xCurrently displays image index

getInfo(options)

Get image information.

Parameters

PropertyTypeDefaultRequiredDescriptionSupport
srcStringImage path, can be relative path, temporary file path, storage file path, network image path

compress(options)

Compress image.

Parameters

PropertyTypeDefaultRequiredDescriptionSupport
filePathsString ArrayAn array of image addresses to compress
srcStringImage path, can be relative path, temporary file path, storage file path, network image path
compressLevelNumber4xCompression level, support 0 ~ 4 integer
qualityNumber80xCompression mass, range 0 ~ 100, the smaller the value, the lower the mass

save(options)

Save Image.

Parameters

PropertyTypeDefaultRequiredDescriptionSupport
urlStringImage file path
showActionSheetBooleantruexWhether 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);
  }
});