2017-09-04 14 views
0

AngularJsで開発するのが初めてで、Angular-Base64-Uploadを使用して画像をベース64に変換する機能があります。画像のサイズを変更する方法を知りたい標準サイズは約500ピクセルです。Angular-base-64で画像サイズを変更

$scope.upload = function (file) { 
    Upload.base64DataUrl(file).then(
    function (url){ 
     $scope.data['usu_foto'] = url; 
    }); 
}; 
+0

https://stackoverflow.com/questions/20958078/resize-a-base-64image-in-javascript-without-using-canvas –

答えて

0
app.controller('ctrl', function ($scope, $q) { 

    $scope.resizeImage = function (file, base64_object) { 
    // file is an instance of File constructor. 
    // base64_object is an object that contains compiled base64 image data from file. 
    var deferred = $q.defer(); 
    var url = URL.createObjectURL(file);// creates url for file object. 
    Jimp.read(url) 
    .then(function (item) { 
     item 
     .resize(1280, Jimp.AUTO)// width of 1280px, auto-adjusted height 
     .quality(50)//drops the image quality to 50% 
     .getBase64(file.type, function (err, newBase64) { 
     if (err) {throw err;} 
     var bytes = Math.round((3/4)*newBase64.length); 
     base64Object.filetype = file.type; 
     base64Object.filesize = bytes; 
     base64Object.base64 = newBase64; 
     // Note that base64 in this package doesn't contain "data:image/jpeg;base64," part, 
     // while base64 string from Jimp does. It should be taken care of in back-end side. 
     deferred.resolve(base64Object); 
     }); 
    }) 
    .catch(function (err) { 
     return console.log(err);// error handling 
    }); 
    return deferred.promise; 
    }; 

}); 

基本的に、あなただけの機能のサイズを変更することができます。 さらに詳しい情報が見つかりました:https://github.com/adonespitogo/angular-base64-upload

関連する問題