diff --git a/actions/resize.js b/actions/resize.js new file mode 100755 index 0000000..9fa7685 --- /dev/null +++ b/actions/resize.js @@ -0,0 +1,33 @@ +/* + * Pixastic Lib - Resize - v0.1.0 + * Copyright (c) 2009 Jacob Seidelin, jseidelin@nihilogic.dk, http://blog.nihilogic.dk/ + * License: [http://www.pixastic.com/lib/license.txt] + */ + +Pixastic.Actions.resize = { + process : function(params) { + if (Pixastic.Client.hasCanvas()) { + var width = params.options.width; + var height = params.options.height; + var canvas = params.canvas; + + var copy = document.createElement("canvas"); + copy.width = width; + copy.height = height; + copy.getContext("2d").drawImage(canvas,0,0,width,height); + + canvas.width = width; + canvas.height = height; + + canvas.getContext("2d").drawImage(copy,0,0); + + params.useData = false; + return true; + } + }, + checkSupport : function() { + return Pixastic.Client.hasCanvas(); + } +} + + diff --git a/actions/rotate.js b/actions/rotate.js new file mode 100755 index 0000000..61c4f12 --- /dev/null +++ b/actions/rotate.js @@ -0,0 +1,48 @@ +/* + * Pixastic Lib - Rotate - v0.1.0 + * Copyright (c) 2009 Jacob Seidelin, jseidelin@nihilogic.dk, http://blog.nihilogic.dk/ + * License: [http://www.pixastic.com/lib/license.txt] + */ + +Pixastic.Actions.rotate = { + process : function(params) { + if (Pixastic.Client.hasCanvas()) { + var canvas = params.canvas; + + var width = params.width; + var height = params.height; + + var copy = document.createElement("canvas"); + copy.width = width; + copy.height = height; + copy.getContext("2d").drawImage(canvas,0,0,width,height); + + var angle = parseFloat(params.options.angle) * Math.PI / 180; + + var diag = Math.sqrt(width*width + height*height); + + var diagAngle = Math.atan2(height, width); + + if (angle < 0) diagAngle = -diagAngle; + + var newHeight = Math.abs(Math.sin(diagAngle + angle) * diag); + var newWidth = Math.abs(Math.cos(-diagAngle + angle) * diag); + + canvas.width = newWidth; + canvas.height = newHeight; + + var ctx = canvas.getContext("2d"); + ctx.translate(newWidth/2, newHeight/2); + ctx.rotate(angle); + ctx.drawImage(copy,-width/2,-height/2); + + params.useData = false; + return true; + } + }, + checkSupport : function() { + return Pixastic.Client.hasCanvas(); + } +} + + diff --git a/license.txt b/license.txt new file mode 100755 index 0000000..02fa197 --- /dev/null +++ b/license.txt @@ -0,0 +1,21 @@ +The MIT License + +Copyright (c) 2008-2009 Jacob Seidelin + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE.