html5画布保存背景

时间:2015-03-10 17:00:00

标签: javascript jquery canvas

我正在使用画布...我修改了一个选择背景,什么时候完成了绘图保存它与背景...直到在后台选择一切都好......现在我有一些问题说实话,我不知道怎么做

以下是我工作的网址:canvas

第一个问题是光标...我需要画布显示在制表符内部,当我在画布中绘制光标而不是显示0,0时,在页面上是0,0所以当我开始绘制时该行显示为下一个图像:

error in cursor

第二个问题是当我尝试保存结果时......当只绘制线条时画布成功保存但背景不是时...你可以尝试使用我在上面添加的链接。

最后一个问题是,当我点击橡皮擦或撤消...背景和我绘制的所有内容都被删除...我只需要删除最后一行,而不是全部...这可以修复吗?

我在这里添加了js:canvas js

这里是grabado.php:

<?php
/**
* -------------------------------
* Customizable Settings
* -------------------------------
*/
$dd_savePath=str_replace('\\','/',dirname(__FILE__))."/tmp";
$prependSig="diag_";
/**
* -------------------------------
* End of customizable settings
* -------------------------------
*/
/**
* Attempt to create the needed save dir if not exist
*/
if(!is_dir($dd_savePath)) {
    @mkdir($dd_savePath,0777);
    @chmod($dd_savePath,0777);
}
//
$action=strip_tags(trim($_POST['action']));
$fileName=strip_tags(trim($_POST['file_name']));
$width=strip_tags(trim($_POST['width']));
$height=strip_tags(trim($_POST['height']));
$download=(isset($_POST['download']) ? strip_tags(trim($_POST['download'])) : strip_tags(trim($_GET['download'])));
/**
* @desc 
*/
class createSignature {
    private $img, $file, $dest;

    public function __construct($i,$d) {
        $this->file=$i;
        $this->dest=$d;
    }

    public function makePNG($w,$h) {
        $this->img=@imagecreatefrompng($this->file);
        //
        imagealphablending($this->img, true);   // setting alpha blending on
        imagesavealpha($this->img, true);       // save alphablending setting (important)
        //
        $canvas=self::makeCanvas('png',$w,$h);
        // Let's get our dims for original image
        $trueSize=getimagesize($this->file);
        //
        imagecopyresampled($canvas,$this->img,0,0,0,0,$w,$h,$trueSize[0],$trueSize[1]);
        //
        if(imagepng($canvas,$this->dest)) {
            @chmod($this->dest,0777);
            @imagedestroy($this->img);
            @imagedestroy($canvas);
            return true;
        }else{
            return false;
        }
    }

    private function makeCanvas($t,$w,$h) {
        switch($t) {
            case "png":
                $canvas=imagecreatetruecolor($w,$h);
                imagecolortransparent($canvas, imagecolorallocatealpha($canvas, 0, 0, 0, 127));
                imagealphablending($canvas, false); // setting alpha blending on
                imagesavealpha($canvas, true);      // save alphablending setting (important)
                break;
            default:
        }
        //
        return $canvas;
    }
}
/**
* If download flag, then we're downloading a created signature image
*/
if($download!="") {
    //
    $downloadFile="{$dd_savePath}/{$download}";
    //
    $ctype="application/force-download";
    header("Pragma: public");
    header("Expires: 0");
    header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
    header("Content-Type: $ctype");
    header("Content-Length: ".filesize($downloadFile));
    header("Content-Disposition: attachment; filename=\"".basename($downloadFile)."\"");
    header("Accept-Range: bytes");
    set_time_limit(0);
    readfile("{$downloadFile}");
    header("Connection: close");

/**
* Else we're building a new signature image
*/
}else{
    $data=$_POST['data'];
    $data=str_replace(' ','+',$data);   // convert any whitespace
    /**
    * Now let's decode it so it's recognized as an img
    */
    $decodeData=@base64_decode($data);
    /**
    * Finally, save her
    */
    $file="{$dd_savePath}/".($action=="sig" ? "{$prependSig}{$fileName}" : "{$prependTxt}{$fileName}");
    if(@file_put_contents($file, $decodeData)) {
        @chmod($file,0777);
        /**
        * If we've saved a signature, let's replicate it to proper size
        * since our signature object is bigger (in real dimensions) than what we want
        * See our css+html notes
        */
        switch($action) {
            case "sig":
                $newFile=$dd_savePath.'/tmp_'.$fileName;
                $newSig=new createSignature($file,$newFile);
                $result=$newSig->makePNG($width,$height);
                if($result==true) {
                    // Finally, we want to delete the original and replace it with the new resized one
                    @unlink($file);
                    $finalName=str_replace('tmp_',$prependSig,$newFile);
                    @rename($newFile,$finalName);
                    //
                    $finalName=substr(strrchr($finalName,'/'),1);
                    echo "success|{$finalName}";
                }else{
                    echo "failed";
                }
                break;
            default:
                echo "success";
        }

    }else{
        echo "{$file}";
    }
}
?>

0 个答案:

没有答案