2014-11-25 67 views
1

我正在构建一个web应用程序,为此我正在使用HTML5Raphael js构建一个基本的图像编辑器。我已经实现像一些特点:
如何使用HTML5和Raphael JS构建图像编辑器?

  1. 调整大小
    水平翻转和/或垂直

一些更多的功能,我需要实现的是:

  1. 作物
    撤消/重做
    更改背景颜色和不透明度。

我主要是在寻找作物和撤消功能。任何人都可以帮助我实现这个使用RaphaelJsHTML5

我的代码:

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 
      }) 
     } 
    } 
+0

我认为这会有帮助,如果你可以提供一个更简洁的问题/答案,以一个简明的例子来说明问题。 – Ian 2014-11-25 10:45:42

+0

我想用Raphael js裁剪图像。我没有找到办法做到这一点。 – Ved 2014-11-25 10:55:18

+1

是的,但是您需要实际定义您想要的作物。一个新的图像,要保存的东西,或者只是看起来像剪辑或其他东西一样裁剪。这是一个SVG图像,任何图像或任何其他。 – Ian 2014-11-25 11:11:42

回答

1

UPDATE:只是用Fabric.js http://fabricjs.com/kitchensink/,虽然你可能需要添加暗室http://mattketmo.github.io/darkroomjs/进行裁剪。


为RaphaelJS一些建议:

退房东西像画板http://ianli.com/sketchpad/或评论暗室http://mattketmo.github.io/darkroomjs/的想法。

您可以随时尝试探索现有网络编辑器的源代码,例如Google +(这主要是一个笑话)。