Added color histogram, flip, resize and rotate actions + a few changes to core
This commit is contained in:
parent
f3bbbff92c
commit
20fdb50db0
3 changed files with 102 additions and 0 deletions
33
actions/resize.js
Executable file
33
actions/resize.js
Executable file
|
@ -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();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
48
actions/rotate.js
Executable file
48
actions/rotate.js
Executable file
|
@ -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();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
21
license.txt
Executable file
21
license.txt
Executable file
|
@ -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.
|
Loading…
Add table
Add a link
Reference in a new issue