compress-image.js 514 字节
Newer Older
fxy060608's avatar
fxy060608 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
import {
  TEMP_PATH
} from '../constants'

import {
  invoke
} from '../../bridge'

export function compressImage ({
  src,
  quality
}, callbackId) {
  var dst = TEMP_PATH + '/compressed/' + Date.now() + (src.match(/\.\S+$/) || [''])[0]
  plus.zip.compressImage({
    src,
    dst,
    quality
  }, () => {
    invoke(callbackId, {
fxy060608's avatar
fxy060608 已提交
20
      errMsg: 'compressImage:ok',
fxy060608's avatar
fxy060608 已提交
21 22 23 24
      tempFilePath: dst
    })
  }, () => {
    invoke(callbackId, {
fxy060608's avatar
fxy060608 已提交
25
      errMsg: 'compressImage:fail'
fxy060608's avatar
fxy060608 已提交
26 27 28
    })
  })
}