使用ng-file-upload通知图像大小调整

时间:2016-03-31 11:11:37

标签: ng-file-upload

图像调整大小需要很长时间,我实现了类似这样的东西来挂钩图像大小调整的开始和结束。

https://github.com/chiller/ng-file-upload/commit/f6d2a12fe58f768a549b184b112aa7bff0ab2df4#diff-6eeed726084131b9a38134f8f89c2d4f

src / model.js:108我的补充是范围。$ emit ones

function handleFile(f, i) {
  if (f.type.indexOf('image') === 0) {
    if (param.pattern && !upload.validatePattern(f, param.pattern)) return;
    scope.$emit('resizeStarted');
    var promise = upload.resize(f, param.width, param.height, param.quality,
      param.type, param.ratio, param.centerCrop, function (width, height) {
        return upload.attrGetter('ngfResizeIf', attr, scope,
          {$width: width, $height: height, $file: f});
      }, param.restoreExif !== false);
    promises.push(promise);
    promise.then(function (resizedFile) {
      scope.$emit('resizeFinished');
      files.splice(i, 1, resizedFile);
    }, function (e) {
      scope.$emit('resizeFinished');
      f.$error = 'resize';
      f.$errorParam = (e ? (e.message ? e.message : e) + ': ' : '') + (f && f.name);
    });
  }
}

我想知道是否有更好的方法?

0 个答案:

没有答案