convert: function()
	{
		var convertParams = ['-size', '', 'xc:' + this.options.background, '-strip'];
		var size = this.size = { w: 0, h: 0 };
		var block;
		var outputFile = this.options.outfile;

		for(var i = 0 ; i < this.blocks.length ; i++)
		{
			block = this.blocks[i];
			if(block.fit)
			{
				if(block.fit.x + block.w > size.w) size.w = block.fit.x + block.w;
				if(block.fit.y + block.h > size.h) size.h = block.fit.y + block.h;

				convertParams.push(block.filePath);
				convertParams.push('-geometry');
				convertParams.push('+' + (block.fit.x + this.options.padding) + '+' + (block.fit.y + this.options.padding));
				convertParams.push('-composite');
			}
		}

		convertParams[1] = size.w + 'x' + size.h;

		if('quality' in this.options)
		{
			convertParams.push('-quality');
			convertParams.push(this.options.quality);
		}
		convertParams.push(this.options.format + ':' + outputFile);
		im.convert(convertParams, this.convertDone.bind(this));
	},
Example #2
0
				}, function (err, stdout, stderr) {
					if (err) {
						winston.err(err);
						res.send({
							error: 'Invalid image file!'
						});
						return;
					}

					var imageUrl = nconf.get('upload_url') + filename;

					user.setUserField(uid, 'uploadedpicture', imageUrl);
					user.setUserField(uid, 'picture', imageUrl);

					if (convertToPNG) {
						im.convert([uploadPath, 'png:-'], 
							function(err, stdout){
								if (err) {
									winston.err(err);
									res.send({
										error: 'Unable to convert image to PNG.'
									});
									return;
								}

								fs.writeFileSync(uploadPath, stdout, 'binary');  
							});
					}
					

					res.json({
						path: imageUrl
					});
				});
Example #3
0
			is.on('end', function () {
				fs.unlinkSync(tempPath);

				function done(err) {
					if (err) {
						winston.err(err);
						res.send({
							error: 'Invalid image file!'
						});
						return;
					}

					var imageUrl = nconf.get('upload_url') + filename;

					user.setUserField(uid, 'uploadedpicture', imageUrl);
					user.setUserField(uid, 'picture', imageUrl);

					if (convertToPNG && extension !== '.png') {
						im.convert([uploadPath, 'png:-'], function(err, stdout) {
							if (err) {
								winston.err(err);
								res.send({
									error: 'Unable to convert image to PNG.'
								});
								return;
							}

							fs.writeFileSync(uploadPath, stdout, 'binary');
							res.json({
								path: imageUrl
							});
						});
					} else {
						res.json({
							path: imageUrl
						});
					}
				}

				if(extension === '.gif') {
					im.convert([uploadPath, '-coalesce', '-repage', '0x0', '-crop', '128x128+0+0', '+repage', 'uploadPath'], function(err, stdout) {
						done(err);
					});
				} else {
					im.crop({
						srcPath: uploadPath,
						dstPath: uploadPath,
						width: 128,
						height: 128
					}, function (err, stdout, stderr) {
						done(err);
					});
				}
			});