-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 06f8d22
Showing
6 changed files
with
94 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
components | ||
build | ||
node_modules | ||
npm-debug.log |
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,5 @@ | ||
{ | ||
"asi": true, | ||
"laxcomma": true, | ||
"laxbreak": true | ||
} |
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,22 @@ | ||
|
||
# rotate-image | ||
|
||
rotate images in 90° increments | ||
|
||
## Installation | ||
|
||
$ npm install nathan7/rotate-image | ||
|
||
or | ||
|
||
$ component install nathan7/rotate-image | ||
|
||
## API | ||
|
||
### rotateImage(image, rotation) | ||
|
||
Rotates an image by the given rotation. Rotation is given as a number from 0 to 3 (out-of-range numbers are modulus'd) | ||
|
||
## License | ||
|
||
MIT |
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,19 @@ | ||
{ | ||
"name": "rotate-image", | ||
"repo": "nathan7/rotate-image", | ||
"description": "rotate images in 90° increments", | ||
"version": "1.0.0", | ||
"keywords": [ | ||
"rotate", | ||
"image", | ||
"utility" | ||
], | ||
"dependencies": { | ||
"nathan7/canvas": "*" | ||
}, | ||
"license": "MIT", | ||
"main": "index.js", | ||
"scripts": [ | ||
"index.js" | ||
] | ||
} |
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 @@ | ||
var Canvas = require('canvas') | ||
, Image = Canvas.Image | ||
module.exports = | ||
function rotateImage(image, rotation) { | ||
rotation = (+rotation + 4) % 4 | ||
var mod = rotation & 1 | ||
, width = mod | ||
? image.height | ||
: image.width | ||
, height = mod | ||
? image.width | ||
: image.height | ||
var canvas = new Canvas(width, height) | ||
, ctx = canvas.getContext('2d') | ||
ctx.rotate(rotation * Math.PI / 2) | ||
ctx.drawImage(image, image.width * -(rotation === 2 || rotation === 3), image.height * -(rotation === 1 || rotation === 2)) | ||
var newImage = new Image() | ||
newImage.src = typeof canvas.toBuffer == 'function' ? canvas.toBuffer() : canvas.toDataURL() | ||
return newImage | ||
} |
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,24 @@ | ||
{ | ||
"name": "rotate-image", | ||
"version": "1.0.0", | ||
"description": "rotate images in 90° increments", | ||
"main": "index.js", | ||
"repository": { | ||
"type": "git", | ||
"url": "git://github.com/nathan7/rotate-image.git" | ||
}, | ||
"keywords": [ | ||
"rotate", | ||
"image", | ||
"utility" | ||
], | ||
"author": "Nathan Zadoks", | ||
"license": "MIT", | ||
"bugs": { | ||
"url": "https://github.com/nathan7/rotate-image/issues" | ||
}, | ||
"readmeFilename": "Readme.md", | ||
"dependencies": { | ||
"canvas": "nathan7/canvas" | ||
} | ||
} |