コード例 #1
0
ファイル: resize.js プロジェクト: rhavill/js
    }).forEach(function (file) {
    	var extension = path.extname(file);
    	var basename = path.basename(file, '.jpg');
    	var newPath = destDir + '/' + basename + '_1920' + extension;
        console.log("%s (%s)", file, newPath);
		gd.openJpeg(file, function(err, img) {
		  if (err) {
		  	console.log(file,'error!', err);
		    //throw err;
		  }
		  else {
			  var newImg = img.saveJpeg(newPath, 100, function(err) {
			    if (err) {
			      throw err;
			    }
			  });
			  img.copyResized(newImg, 0, 0, 0, 0, 1920, 1080, 1920*2, 1080*2);
			}
		});	
    });
コード例 #2
0
ファイル: compressor.js プロジェクト: y-a-v-a/maxcompressor
exports.compress = function(image, callback) {
    'use strict';
    gd.openJpeg(image, function(err, img) {
        if (err) {
            throw err;
        }
        var newName = './cache/' + md5(image) + '.jpg';

        fs.exists(newName, function(exists) {
            if (!exists) {
                img.saveJpeg(newName, 0, function() {
                    if (typeof callback === 'function') {
                        callback(null, newName);
                    }
                });
            } else {
                callback(null, newName);
            }
        });
    });
};