我正在構建一個web應用程序,爲此我正在使用HTML5
和Raphael js
構建一個基本的圖像編輯器。我已經實現像一些特點:
如何使用HTML5和Raphael JS構建圖像編輯器?
- 調整大小
水平翻轉和/或垂直
將
一些更多的功能,我需要實現的是:
- 作物
撤消/重做
更改背景顏色和不透明度。
我主要是在尋找作物和撤消功能。任何人都可以幫助我實現這個使用RaphaelJs
和HTML5
?
我的代碼:
var r, c, d;
var paper = Raphael("editor", 600,450);
var canvas = document.getElementById('editor');
canvas.style.backgroundColor='gray';
$scope.current;
var someFunction = function(e) {
e.data('dragged', false);
e.drag(dragmove, dragstart, dragend);
for(var i in elements) {
var thisShape = elements[i];
var ft = paper.freeTransform(thisShape,{draw:['bbox']});
ft.hideHandles();
thisShape.click(function(){
paper.forEach(function(el) {
if(el.freeTransform.handles.bbox != null)
el.freeTransform.hideHandles();
});
this.freeTransform.showHandles();
});
}
};
function dragmove(dx, dy, x, y, e) {
this.transform(this.current_transform+'T'+dx+','+dy);
}
function dragstart(x, y, e) {
this.current_transform = this.transform();
}
function dragend(e) {
this.current_transform = this.transform();
};
var elements = [];
$scope.raph = function() {
c= paper.circle(40,40,40).click(function() {
someFunction(this);
$scope.current= this;
});
r = paper.rect(50, 60, 100,100,25).click(function() {
someFunction(this);
$scope.current= this;
});
d = paper.rect(70, 60, 100,100,25).click(function() {
someFunction(this);
$scope.current= this;
});
elements.push(c,r,d);
c.attr({
fill:'red',
cursor:'pointer'
});
r.attr({
fill:'green',
cursor:'pointer'
});
d.attr({
fill:'blue',
cursor:'pointer'
});
};
$scope.back = function() {
$scope.current.toBack();
}
$scope.front = function() {
$scope.current.toFront();
}
$scope.clear = function() {
paper.clear();
};
$scope.flips = function() {
$scope.current.rotate(180);
};
//function for cloning element
$scope.clones = function() {
var n = $scope.current.clone();
n.attr("x",$scope.current.attr("x")+100);
$scope.current = n;
elements.push(n);
n.click(function() {
someFunction(this);
});
};
$scope.changing= function (e) {
$scope.opacity=event.target.value;
if($scope.current != null){
$scope.current.attr({
opacity:$scope.opacity
})
}
}
我認爲這會有幫助,如果你可以提供一個更簡潔的問題/答案,以一個簡明的例子來說明問題。 – Ian 2014-11-25 10:45:42
我想用Raphael js裁剪圖像。我沒有找到辦法做到這一點。 – Ved 2014-11-25 10:55:18
是的,但是您需要實際定義您想要的作物。一個新的圖像,要保存的東西,或者只是看起來像剪輯或其他東西一樣裁剪。這是一個SVG圖像,任何圖像或任何其他。 – Ian 2014-11-25 11:11:42