Giúp đỡ về crop image (easyimage)
-
mình crop image dưới local thì chạy bthg. nhưng khi đưa lên server thì k crop được. chỉ nhận được file hình gốc ( vd: folder product có 1 hình chính, 1 folder small, 1 folder thumb. mà small vs thum lại k nhận hình). Anh/chị giúp em với.
exports.resize=function(T_src,T_dis,T_width,T_height){
var easyimg = require('easyimage'); easyimg.resize({ src:T_src, dst:T_dis, width:T_width, height:T_height, cropwidth:128, cropheight:128, x:0, y:0 }).then( function(image) { console.log('Resized and cropped: ' + image.width + ' x ' + image.height); // console.log(image); }, function (err) { throw err; console.log(err); } );
}
exports.uploadFile=function(file,name_picture,path = __dirname+'../public/upload/', pathImg = '/public/upload'){
var fs=require("fs");
var originalFilename = file.name;
var fileType = file.type.split('/')[1];
var fileSize = file.size;
var pathUpload = path + name_picture;
var pathImg = pathImg + originalFilename;
var data = fs.readFileSync(file.path);
fs.writeFileSync(pathUpload, data);
var imgUrl = '';
if( fs.existsSync(pathUpload) ) {
imgUrl = pathImg;this.resize(pathUpload,path + "small/" + name_picture,100,100); this.resize(pathUpload,path + "thumb/" + name_picture,250,250); } return imgUrl;
}