Skip to content

Commit

Permalink
initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
edef1c committed May 28, 2013
0 parents commit 06f8d22
Show file tree
Hide file tree
Showing 6 changed files with 94 additions and 0 deletions.
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
components
build
node_modules
npm-debug.log
5 changes: 5 additions & 0 deletions .jshintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"asi": true,
"laxcomma": true,
"laxbreak": true
}
22 changes: 22 additions & 0 deletions Readme.md
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
19 changes: 19 additions & 0 deletions component.json
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"
]
}
20 changes: 20 additions & 0 deletions index.js
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
}
24 changes: 24 additions & 0 deletions package.json
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"
}
}

0 comments on commit 06f8d22

Please sign in to comment.