Permalink
Browse files

Move size plugins to core library

  • Loading branch information...
1 parent 664b3fb commit f86008bc60c1750ccf62a888e87a7670a41195ae @meltingice committed Jan 10, 2013
Showing with 0 additions and 55 deletions.
  1. +0 −55 src/size.coffee
View
@@ -1,55 +0,0 @@
-# Allows us to crop the canvas and produce a new smaller
-# canvas.
-Caman.Plugin.register "crop", (width, height, x = 0, y = 0) ->
- # Create our new canvas element
- if exports?
- canvas = new Canvas width, height
- else
- canvas = document.createElement 'canvas'
- canvas.width = width
- canvas.height = height
-
- ctx = canvas.getContext '2d'
-
- # Perform the cropping by drawing to the new canvas
- ctx.drawImage @canvas, x, y, width, height, 0, 0, width, height
-
- # Update all of the references
- @replaceCanvas canvas
-
-# Resize the canvas and the image to a new size
-Caman.Plugin.register "resize", (newDims = null) ->
- # Calculate new size
- if newDims is null or (!newDims.width? and !newDims.height?)
- Log.error "Invalid or missing dimensions given for resize"
- return
-
- if not newDims.width?
- # Calculate width
- newDims.width = @canvas.width * newDims.height / @canvas.height
- else if not newDims.height?
- # Calculate height
- newDims.height = @canvas.height * newDims.width / @canvas.width
-
- if exports?
- canvas = new Canvas newDims.width, newDims.height
- else
- canvas = document.createElement 'canvas'
- canvas.width = newDims.width
- canvas.height = newDims.height
-
- ctx = canvas.getContext '2d'
-
- ctx.drawImage @canvas,
- 0, 0,
- @canvas.width, @canvas.height,
- 0, 0,
- newDims.width, newDims.height
-
- @replaceCanvas canvas
-
-Caman.Filter.register "crop", (width, height, x = 0, y = 0) ->
- @processPlugin "crop", Array.prototype.slice.call(arguments, 0)
-
-Caman.Filter.register "resize", (width, height) ->
- @processPlugin "resize", Array.prototype.slice.call(arguments, 0)

0 comments on commit f86008b

Please sign in to comment.