Skip to content

Commit

Permalink
replaced lwip by jimp
Browse files Browse the repository at this point in the history
  • Loading branch information
ldarren committed May 25, 2018
1 parent 88d322c commit 54d45bc
Show file tree
Hide file tree
Showing 4 changed files with 556 additions and 62 deletions.
1 change: 0 additions & 1 deletion lib/fileinfo.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ function FileInfo(file, opts, storage, fields) {
this.name = opts.saveFile ? safeFile(file.name, storage) : file.name;
this.size = file.size;
this.type = file.type;
this.ext = path.extname(file.name).substr(1);
this.modified = file.lastMod;
this.deleteType = 'DELETE';
this.versions = {};
Expand Down
14 changes: 7 additions & 7 deletions lib/thumbnail.js
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
var lwip = require('pajk-lwip');
var Jimp = require('jimp');

function processVersionFile(versionObj, fileInfo, buffer, cbk) {
lwip.open(buffer, fileInfo.ext, function(err, image) {
Jimp.read(buffer, function(err, image) {
if (err) return cbk(err, versionObj);

//update pics width and height
if (!fileInfo.width) {
fileInfo.width = image.width() || 50; //incase we don't get a valid width
fileInfo.height = image.height() || fileInfo.width;
fileInfo.width = image.bitmap.width || 50; //incase we don't get a valid width
fileInfo.height = image.bitmap.height || fileInfo.width;
}

var vo = versionObj;
var width = 'auto' === vo.width ? (vo.height / fileInfo.height) * fileInfo.width: vo.width;
var height = 'auto' === vo.height ? (vo.width / fileInfo.width) * fileInfo.height : vo.height;
image.batch().resize(width, height).toBuffer(fileInfo.ext, function(err, output){
var width = 'auto' === vo.width ? Jimp.AUTO : vo.width;
var height = 'auto' === vo.height ? Jimp.AUTO : vo.height;
image.resize(width, height, Jimp.RESIZE_NEAREST_NEIGHBOR).getBuffer(fileInfo.type, function(err, output){
cbk(err, output, width, height);
});
});
Expand Down
Loading

0 comments on commit 54d45bc

Please sign in to comment.