This repository has been archived by the owner on Jul 15, 2019. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #7 from yahoo/add_rotate
Add rotation methods
- Loading branch information
Showing
12 changed files
with
128 additions
and
67 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
// Copyright 2015, Yahoo! Inc. | ||
// Copyrights licensed under the Mit License. See the accompanying LICENSE file for terms. | ||
|
||
var PNGImage = require('../index'); | ||
|
||
PNGImage.readImage(__dirname + '/squirrel.png', function (err, image) { | ||
|
||
if (err) { | ||
throw err; | ||
} | ||
|
||
image = image.rotateCCW(); | ||
//image = image.rotateCW(); | ||
|
||
image.writeImage(__dirname + '/rotatedSquirrel.png', function (err) { | ||
if (err) throw err; | ||
|
||
console.log('Done'); | ||
}); | ||
}); |
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
// Copyright 2015, Yahoo! Inc. | ||
// Copyrights licensed under the Mit License. See the accompanying LICENSE file for terms. | ||
|
||
var PNGImage = require('../index'); | ||
|
||
var image = PNGImage.readImageSync(__dirname + '/eye.png'); | ||
|
||
// Black-out an area | ||
image.fillRect(17, 10, 15, 20, { | ||
red: 0, green: 0, blue: 0, alpha: 255 | ||
}); | ||
|
||
console.log('Modified!'); | ||
|
||
image.writeImageSync(__dirname + '/eye_ouput.png'); | ||
|
||
console.log('Done'); |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
// Copyright 2015 Yahoo! Inc. | ||
// Copyrights licensed under the Mit License. See the accompanying LICENSE file for terms. | ||
|
||
/** | ||
* Image manipulation functions | ||
* | ||
* @class PNGImage | ||
* @type {object} | ||
*/ | ||
module.exports = { | ||
|
||
/** | ||
* Rotates the current image 90 degree counter-clockwise | ||
* | ||
* @method rotateCCW | ||
* @return {PNGImage} Rotated image | ||
*/ | ||
rotateCCW: function () { | ||
var Class = this.constructor, | ||
x, y, | ||
width = this.getWidth(), | ||
height = this.getHeight(), | ||
image = Class.createImage(height, width); | ||
|
||
for (x = 0; x < width; x++) { | ||
for (y = 0; y < height; y++) { | ||
image.setPixel(y, width - x - 1, this.getPixel(x, y)); | ||
} | ||
} | ||
|
||
return image; | ||
}, | ||
|
||
/** | ||
* Rotates the current image 90 degree clockwise | ||
* | ||
* @method rotateCW | ||
* @return {PNGImage} Rotated image | ||
*/ | ||
rotateCW: function () { | ||
var Class = this.constructor, | ||
x, y, | ||
width = this.getWidth(), | ||
height = this.getHeight(), | ||
image = Class.createImage(height, width); | ||
|
||
for (x = 0; x < width; x++) { | ||
for (y = 0; y < height; y++) { | ||
image.setPixel(height - y - 1, x, this.getPixel(x, y)); | ||
} | ||
} | ||
|
||
return image; | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters