Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

I enabled gravity to be specified. #54

Merged
merged 1 commit into from

2 participants

@pbrumm

I updated test case and documentation.

@rsms rsms merged commit 04bc6c9 into rsms:master
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Sep 4, 2012
  1. @pbrumm
This page is out of date. Refresh to see the latest.
Showing with 27 additions and 6 deletions.
  1. +3 −2 README.md
  2. +3 −2 imagemagick.js
  3. +21 −2 test-crop.js
View
5 README.md
@@ -122,7 +122,7 @@ Example with stdin/stdout:
});
### crop(options, callback) ###
-Convenience function for resizing and cropping an image. _crop_ uses the resize method, so _options_ and _callback_ are the same. _crop_ uses _options.srcPath_, so make sure you set it :) Using only _options.width_ or _options.height_ will create a square dimensioned image.
+Convenience function for resizing and cropping an image. _crop_ uses the resize method, so _options_ and _callback_ are the same. _crop_ uses _options.srcPath_, so make sure you set it :) Using only _options.width_ or _options.height_ will create a square dimensioned image. Gravity can also be specified, it defaults to Center. Available gravity options are [NorthWest, North, NorthEast, West, Center, East, SouthWest, South, SouthEast]
Example:
@@ -131,7 +131,8 @@ Example:
dstPath: 'cropped.jpg',
width: 800,
height: 600,
- quality: 1
+ quality: 1,
+ gravity: "North"
}, function(err, stdout, stderr){
// foo
})
View
5 imagemagick.js
@@ -298,10 +298,11 @@ exports.crop = function (options, callback) {
if ((arg != "-resize") && ignoreArg) {
var dSrc = meta.width / meta.height,
dDst = t.opt.width / t.opt.height,
- resizeTo = (dSrc < dDst) ? ''+t.opt.width+'x' : 'x'+t.opt.height;
+ resizeTo = (dSrc < dDst) ? ''+t.opt.width+'x' : 'x'+t.opt.height,
+ dGravity = options.gravity ? options.gravity : "Center";
args = args.concat([
'-resize', resizeTo,
- '-gravity', 'Center',
+ '-gravity', dGravity,
'-crop', ''+t.opt.width + 'x' + t.opt.height + '+0+0',
'+repage'
]);
View
23 test-crop.js
@@ -7,7 +7,7 @@ var timeStarted = new Date;
im.crop({
srcPath: path,
- dstPath: 'cropped.jpg',
+ dstPath: './cropped.jpg',
width: 2000,
height: 900,
quality: 1
@@ -16,7 +16,26 @@ im.crop({
sys.puts('real time taken for convert: ' + (new Date() - timeStarted) + ' ms')
- im.identify(['-format', '%b', path + '.cropped.jpg'], function(err, r){
+ im.identify(['-format', '%b', 'cropped.jpg'], function(err, r){
+ if (err) throw err;
+ sys.puts('size: ' + r.substr(0, r.length-2) + ' Bytes');
+ })
+})
+
+
+im.crop({
+ srcPath: path,
+ dstPath: './cropped2.jpg',
+ width: 2000,
+ height: 900,
+ gravity: "North",
+ quality: 1
+}, function(err, stdout, stderr){
+ if (err) return sys.error(err.stack || err);
+
+ sys.puts('real time taken for convert: ' + (new Date() - timeStarted) + ' ms')
+
+ im.identify(['-format', '%b', 'cropped2.jpg'], function(err, r){
if (err) throw err;
sys.puts('size: ' + r.substr(0, r.length-2) + ' Bytes');
})
Something went wrong with that request. Please try again.