node wrapper for ImageMagick commands
JavaScript
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
lib
test
.eslintrc
.gitignore
.travis.yml
CHANGELOG.md
README.md
index.js
package.json

README.md

node-imagickal

node wrapper for ImageMagick commands

Build Status

Installation

npm install imagickal

Examples

	var im = require('imagickal');

	//get image dimensions
	im.dimensions('image.jpg').then(function (dim) {
		console.log(dim.width);
		console.log(dim.height);
	});

	//get image dimensions and type
	im.identify('image.jpg').then(function (data) {
		console.log(data);
	});

	//Add true as second argument on identify to check if the image is corrupt.
	im.identify('image.jpg', true).then(function (data) {
		console.log(data);
	});

	//Don't like using promises, use regular node style callbacks for all functions that returns promises.
	im.identify('image.jpg', function (err, data) {
		console.log(data);
	});

	//Using streams instead of filepath
	im.identify(fs.createReadStream('image.jpg'), function (err, data) {
		console.log(data);
	});

	im.transform(fs.createReadStream('image.jpg'), fs.createWriteStream('out.jpg', {encoding: 'binary'}), {strip: true}).then(function () {
		console.log('Done')
	});


	//transform image with action object,
	//actions is applied in the same order as they are recevied
	var actions =  {
		resize: { width: 100 },
		crop: { width: 10, height: 10, x: 10, y: 10 },
		quality: 90,
		strip: true
	};

	im.transform('src.jpg', 'dst.jpg', actions).then(function () {
		console.log('Done')
	});

	//transform image with command object
	im.commands()
		.resize({ width: 100 })
		.crop({ width: 10, height: 10, x: 10, y: 10 })
		.quality(90)
		.strip()
		.exec('src.jpg', 'dst.jpg').then(function () {
			console.log('done');
		});

	//specify executable path
	im.commands({ executable: 'MAGICK_MEMORY_LIMIT=256MB /tmp/convert' }).exec('src.jpg', 'dst.png');

	//or set global for im.
	im.setDefaults({ executable: 'MAGICK_MEMORY_LIMIT=256MB /tmp/convert' });

Available image actions / commands

  • rotate Rotate image, properties { angle: 0, x: 0, y: 0 }
  • crop - Crop image, properties { width: 2560, height: 1013, x: 0, y: 0 }
  • extent - Directly adjust image size, properties { width: 2560, height: 1013 }
  • resize - Resize image, properties { width: 470, height: 186, flag: '>' }, available flags <,>,!,^ for more info read about them in the imagemagick resize docs
  • sharpen - Sharpen image, properties { mode: 'variable' }, available modes are: light, moderate, strong, extreme, off.
  • strip - Strip image of all profiles and comments.
  • quality - Compression quality, defaults to 85.

Run Tests

npm test

Enable debugging output

Set DEBUG environment variable to imagickal

DEBUG=imagickal node ./app.js