const resize = function (fileIn, fileOut, cb) { if (fs.existsSync(fileOut)) { return cb({ msg: 'Skip. Exists.', path: fileOut }) } let dir = fileOut.split('/') dir.pop() fs.ensureDirSync(dir.join('/')) lwip.open(fileIn, function(err, image) { if (err) { console.log('ERROR open picture', err) cb(err) } let width = 1000 let height = image.height() * width / image.width() + 1 image .batch() .resize(width, height, 'grid') .writeFile(fileOut, function(err) { if (err) { console.log('ERROR generating thumbnail', err) cb(err) } else { cb(null) } }) }) }
function printImage(filename) { var width, height, pix_line; lwip.open(filename, function parseImage(err, image) { width = image.width(); height = image.height(); pix_line = ""; for ( var i = 0; i < height; i++ ) { for ( var j = 0; j < width; j++ ) { var rgb = image.getPixel(i, j), color = rgb.r + rgb.g + rgb.b, bw = parseInt(0.2126 * rgb.r + 0.7152 * rgb.g + 0.0722 * rgb.b); if ( color > 255 ) { pix_line += "\xFF"; } else { pix_line += "\x00"; } } } append(S_RASTER_N); append("\x00\x00\xFA\x00"); append(pix_line); }); }
function queueImages (file, enc, cb) { if (file.isNull()) { cb(); return; // ignore } if (file.isStream()) { cb(new Error('Streaming not supported')); return; // ignore } if (imageinfo(file.contents)) { lwip.open(file.contents, imageinfo(file.contents).format.toLowerCase(), function(err, img) { if (!err) { queue(file, img); cb(); } else { console.log('Ignoring ' + file.relative + ' -> ' + err.toString()); cb(); } }); } else { console.log('Ignoring ' + file.relative + ' -> no image info'); cb(); } }
files.forEach(function(f) { numberfile++; if (f.indexOf("thumbnail-") >= 0) { } else { //console.log('Processing file '+ numberfile + ' : '+ backgroundPath+'/thumbnail-'+f); try { fs.accessSync(backgroundPath+'/thumbnail-'+f, fs.F_OK); //console.log('Thumbnail for file '+ numberfile + ' : '+ backgroundPath+'/thumbnail-'+f+ ' exists'); } catch (e) { console.log('Creating Thumbnail for file '+ numberfile + ' : '+ backgroundPath+'/thumbnail-'+f); lwip.open(backgroundPath+'/'+f, function(err, image) { if (err) return console.log(err); image.resize(300, 200 , function(err, imageres) { if (err) return console.log(err); imageres.writeFile(backgroundPath+'/thumbnail-'+f, function(err) { if (err) return console.log(err); }); }); }); } } if (numberfile===files.length){ var background = config.get('background_title') if (background === 'Initial') { self.selectRandomBacground(); } defer.resolve('Ok'); } });
function handle_default(img_status, userId, def, err, callback) { if (def && def !== "steve" && def !== "alex") { callback({ status: img_status, redirect: def, err: err }); } else { def = def || skins.default_skin(userId); lwip.open(path.join(__dirname, "..", "public", "images", def + "_skin.png"), function(lwip_err, image) { if (image) { image.toBuffer("png", function(buf_err, buffer) { callback({ status: img_status, body: buffer, type: "image/png", hash: def, err: buf_err || lwip_err || err }); }); } else { callback({ status: -1, err: lwip_err || err }); } }); } }
.pipe(gulpPlugins.tap(function (file) { //TODO if (!fs.existsSync('images/processed/' + file.relative)) { lwip.open('images/raw/' + file.relative, function (err, image) { if (err) { console.log(err); console.log('Err for image at: images/raw/' + file.relative); return; } image_utils.cropImage(image, function (image) { //TODO compress these images image.writeFile('images/processed/' + file.relative, function (err) { if (err) { console.log(err); console.log('Err writing image at: images/processed/' + file.relative); } }) }) }); } //file.contents = file.contents; }));
AWS.getS3().getObject( fileData, function( err, data ){ if( err ){ reject( err ); return; } var fileType = getFileTypeFromName( fileName ); lwip.open( data.Body, fileType, function( err, image ){ image.rotate( angle, 'white', function( err, image ){ image.toBuffer( fileType, function( err, buffer ){ var params = { Bucket: config.bucket, Key: fileName, Body: buffer, ACL: 'public-read' }; AWS.getS3().upload( params, function( err, data ){ if( err ){ reject( err ); } else{ logJobSuccess( fileName, angle ) .then( resolve, reject ); } } ); } ); } ); } ); } );
.subscribe(function() { lwip.open('./output/river.png', function(err, img) { assert(img.width() === cardSize.width * 5); assert(img.height() === cardSize.height); done(); }); });
return function(next){ var source = sizeOf(content); var ratio = source.width/source.height; var width = placeholder var height = Math.floor(placeholder / ratio) if (gm){ gm(content) .resize(width) .toBuffer(ext, function(err, buffer){ if (!buffer) return; debug("placeholder: ", height, width); var response = createBlur(buffer, ext, defaultBlur, height, width); next(response); }); } else { lwip.open(content, source.type, function(err, image) { image.batch() .resize(width, height) .toBuffer(source.type, function(err, buffer) { if (!buffer) return; debug("placeholder: " + JSON.stringify(source)); var response = createBlur(buffer, ext, defaultBlur, source.height, source.width); next(response); }); }); }; };
// applies a set of transformations to the image function transform(buffer, type, transformations=[]) { var defer = q.defer(); process.stdout.write("\t+ performing image transforms.."); lwip.open(buffer, type, (err, image) => { var transforms; // apply image transformations transforms = transformations.reduce((soFar, transform) => { return soFar.then(image => { process.stdout.write('.'); return dispatchTransform(image, transform); }); }, q(image)); // convert image back to buffer transforms.then(image => { console.log('done.'); process.stdout.write("\t+ converting to buffer..."); image.toBuffer(type, (err, buffer) => { if (err) { defer.reject(err); } else { console.log('done.'); defer.resolve(buffer); } }); }); }); return defer.promise; }
exports.findSimilar = function(videoFilePath, imageFilePath, outputPath, size, callback) { console.log('video path is ', videoFilePath); var videoHelper = new video.Video(videoFilePath, outputPath); lwip.open(imageFilePath, function(err, image) { image.resize(320, function(err, image) { var originHash = phash.imageHashSync(imageFilePath); var resultList = []; videoHelper.onProgress(function(filename) { var destHash = phash.imageHashSync(outputPath + "tmp.jpg"); var haming = phash.hammingDistance(originHash, destHash); //console.log('haming distance is ', haming); fs.copySync(outputPath + 'tmp.jpg', outputPath + filename + '.jpg'); resultList.push({ filename: filename, distance: haming }); resultList = resultList.sort(function(a, b) { return a.distance - b.distance; }); if (resultList.length > size) { var useless = resultList.pop(); console.log('useless one is ', useless); fs.removeSync(outputPath + useless.filename + '.jpg'); } }).start(); callback(resultList); }); }); };
tileStream.on('end', function() { lwip.open(buffer, 'png', function(err, dsImage) { image.paste(0, 0, dsImage, function(err, image) { callback(); }); }); });
}, function (err) { if (err) { console.log(err); throw err; } var canvas = new Canvas(a4Width,a4Height); var ctx = canvas.getContext('2d'); ctx.font = config.fontSize + ' simsun'; ctx.fillText(self.title, paddingLeft, paddingTop); if (self.text.length > 0 ) { ctx.fillText(self.text.match(/.{1,40}/g).join('\n'), paddingLeft, paddingTop + lineHeight); } // converting png to jpeg lwip.open(canvas.toBuffer(), 'png', function(err, image) { lwip.create(image.width(), image.height(), 'white', function(err, canvas){ // paste original image on top of the canvas canvas.paste(0, 0, image, function(err, image){ // now image has a white background... var batch = image.batch(); batch.toBuffer('jpg', function (err, buffer) { self.descriptionImage = 'data:image/jpeg;base64,' + buffer.toString('base64'); defer.resolve(self); }); }); }); }); });
var prepareFile = function (operations, file, callback){ var filename = file.Path; lwip.open(filename, function (err, image) { var batch = image.batch(); if (typeof operations.blur != "undefined") { batch.blur(parseInt(operations.blurvalue)); } if (typeof operations.flip != "undefined") { batch.mirror(operations.flipdir); } if (typeof operations.resize != "undefined") { batch.scale(parseFloat(operations.resizerange)); } if (typeof operations.rotate != "undefined") { batch.rotate(parseInt(operations.rotaterange)); } batch.writeFile("out_" + filename, function (err) { console.log(err); if (err) callback(null); else { file.Path = "out_" + filename; callback(file); } }); }); }
},function (err, files) { if (err) return cb(err); var array = files[0].fd.split("/"); var name = array[array.length - 1]; // Se ajusta el tamaño de la imagen lwip.open(files[0].fd, function(err, image){ if(err) return cb(err); image.batch() .resize(160, 160) .writeFile(folder + '/' + name, function(err){ if(err) return cb(err); // Se guarda el registro en el modelo photo y se actualiza el modelo user sails.models.photo.create({ name: name, filename: files[0].filename, user: userId }).exec(function(err, photo){ if(err) return cb(err); // Se actualiza la photo de usuario sails.models.user.update({ id: userId }, { photo: name }).exec(function(err, update){ if(err) return cb(err); res.json({avatar: update[0].getAvatar(), photo: photo}); }); }); }); }); });
.pipe(through2.obj(function (file, enc, cb) { lwip.open(file.contents, 'png', function (err, img) { should(err).not.be.ok; img.width().should.equal(552); img.height().should.equal(1224); cb(); }); }))
function openLwip(openLwipCallback) { lwip.open(pictureBuffer, pictureExtension, function (error, image) { if (error) { openLwipCallback(error); } else { openLwipCallback(null, image); } }); },
async.eachSeries(meta.info.items, function(item, callback) { lwip.open(item.meta.path, function(err, img) { image.paste(item.x, item.y, img, function(err, image){ image.writeFile(path.join(meta.imgPath, meta.spriteName + '.' + opts.format), function(err, file) { callback(null, image); }); }); }); });
lwip.open(png[0].contents, 'png', function (err, normal) { should(err).not.be.ok; lwip.open(png[1].contents, 'png', function (err, retina) { should(err).not.be.ok; retina.width().should.equal(normal.width() * 2); retina.height().should.equal(normal.height() * 2); done(); }); });
image.resizeImage = function(path, extension, width, height, callback, pathOut) { lwip.open(path, function(err, image) { image.batch() .cover(width, height) .crop(width, height) .writeFile(pathOut, function(err) { callback(err) }) }); };
.pipe(through2.obj(function (file, enc, cb) { file.path.should.equal(path.join('dist', 'img', 'sprites.png')); file.relative.should.equal('sprites.png'); lwip.open(file.contents, 'png', function (err, img) { should(err).not.be.ok; img.width().should.equal(656); img.height().should.equal(656); cb(); }); }))
return new Promise(function(resolve, reject) { lwip.open(src, 'jpg', function (err, image) { if (err) return reject(err); resolve({ width: image.width(), height: image.height(), _lwip: image }); }); });
function (error, stdout, stderr) { stderr.should.be.empty; fs.existsSync('./test/dist/sprite.jpg').should.be.true; lwip.open('./test/dist/sprite.jpg', function (err, img) { should(err).not.be.ok; img.width().should.equal(522); img.height().should.equal(1074); fs.unlinkSync('./test/dist/sprite.jpg'); fs.rmdirSync('./test/dist'); done(); }); });
image.convertImageToPng = function(path, extension, callback, pathOut) { if(extension !== '.png') { lwip.open(path, function(err, image) { if (err) { return callback(err); } image.writeFile(pathOut, 'png', callback) }); } else { callback(); } };
.on('finish', function(){ if (options.tile) { lwip.open(path, imageType, function(err, image){ if (err) { return cb(err) } tiledImageAtResolution(path, image, config.outputResolution.width, config.outputResolution.height, cb) }) } else { cb(null) } })
exports.process = function (fullImagePath, fullImagePathResult, size, callback) { var imgParams = []; lwip.open(fullImagePath, function(err, image){ var imgParams = calc.correctSize(image.width(), image.height(), size[0], size[1]); image.batch() .resize(imgParams['width'],imgParams['height']) .crop(imgParams['dx'], 0, size[0], size[1]) .writeFile(fullImagePathResult, function(err){ callback(); }); }) }
fs.readFile(image.path, function(err, buffer) { lwip.open(buffer, type, function(err, image) { if (err) reject(err); if (!image) reject('Image processing failed'); var size = Math.min(image.width(), image.height()); if (Array.isArray(dimension)) { const arrayToReturn = []; _.each(dimension, function(dim) { arrayToReturn.push(function(callback) { image.clone(function(err, newImage) { if (err) reject(err); newImage .batch() .crop(size, size) .scale((dim / size) || 0.5) .writeFile(_path.join(appRoot, `/server/uploads/${name}×${dim}.${type}`), function(err) { if (err) return callback(err); return callback(null, { path: _path.join(appRoot, `/server/uploads/${name}×${dim}.${type}`), name: `${name}×${dim}.${type}` }); }); }); }); }); async.series(arrayToReturn, function(err, results) { if (err) return reject(err); const FileHandler = new FileUtils(); FileHandler.delete(imageRef.path).then(function(res) { resolve(results); }, function(err) { reject(err); }); }); } else { image.batch() .crop(size, size) .scale((dimension / size) || 0.5) .writeFile(path, function(err) { if (err) reject(err); resolve({ path: path, name: name }); }); } }); });
function processFile(filePath, callback) { lwip.open(filePath, function(err, img) { if (err) { console.log('Error opening local tmp file: ' + err); } else { destruct.destruct(img, iterations, "verticalBlurWithSquareIncAndDecay", function() { files.saveProcessedFiles(img, function(err, localFiles) { if (localFiles) { callback(localFiles); } }); }); } }); }
file.write(jpegImageData.data, function() { img.open(path_1, function(err, image) { image.resize(image.width()*30/image.height(), 30, function(err, image) { image.writeFile(path_2, function() { nodecr.process(path_2, function(err, text) { fs.unlink(path_1); fs.unlink(path_2); if (callback != undefined) callback(err, text); }, 'eng', 7); }); }); }); });
async.eachSeries(imagedimensions, function iteratee(item, callback) { lwip.open(file.path, 'JPEG', function(err, img) { if (err) return callback(err); img .batch() .cover(item.w, item.h) .writeFile( __dirname + '/../../storage/images/news/' + item.w + '/' + _this._id + '.jpg', 'jpg', { quality: 60 }, callback); }); }, cb);