Ver Mensaje Individual
  #2 (permalink)  
Antiguo 06/08/2012, 12:56
Avatar de Panino5001
Panino5001
Me alejo de Omelas
 
Fecha de Ingreso: mayo-2004
Ubicación: -34.637167,-58.462984
Mensajes: 5.148
Antigüedad: 20 años
Puntos: 834
Respuesta: Guardar canvas como imagen .png (download)

Fijate si te sirve:
Código PHP:
<?php 
if(isset($_POST['x']) && !empty($_POST['x'])){
    
$file=base64_decode($_POST['x']);
    
$ctype="image/png";
    
header("Pragma: public"); 
    
header("Expires: 0"); 
    
header("Cache-Control: must-revalidate, post-check=0, pre-check=0"); 
    
header("Cache-Control: private",false);
    
header("Content-Type: $ctype"); 
    
header("Content-Disposition: attachment; filename=\"archivo.png\";" ); 
    
header("Content-Transfer-Encoding: binary"); 
    
header("Content-Length: ".strlen($file))/1024
    echo 
$file;
    exit;
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Documento sin título</title>
<script type="text/javascript">
onload=function(){
    var c=document.getElementsByTagName('canvas')[0];
    c.style.cursor="pointer";
    var ctx=c.getContext('2d');
    ctx.fillStyle="rgb(255,0,0)";
    ctx.fillRect(0,0,100,100);
    (function(c){c.onclick=function(){
        document.getElementById('x').value=c.toDataURL().split('base64,')[1];
        document.getElementById('f1').submit();
    }})(c);
}
</script>
</head>

<body>
<canvas width="100" height="100" id="canvas"></canvas>
<form id="f1" action="<?php echo basename($_SERVER['PHP_SELF']) ?>" method="post"><input name="x" id="x" type="hidden"></form>
</body>
</html>