Foros del Web » Programando para Internet » PHP »

Problema con PHP 5 y Truecolor mycanvas

Estas en el tema de Problema con PHP 5 y Truecolor mycanvas en el foro de PHP en Foros del Web. Hola a todos! He encontrado esta aplicación a base de PHP: [URL="http://allayers.com/mycanvas/"]Truecolor mycanvas[/URL] Es fantástica, me vendría de lujo para mi sitio. Mis conocimientos de ...
  #1 (permalink)  
Antiguo 09/08/2012, 06:43
 
Fecha de Ingreso: agosto-2012
Mensajes: 2
Antigüedad: 11 años, 8 meses
Puntos: 0
Pregunta Problema con PHP 5 y Truecolor mycanvas

Hola a todos!
He encontrado esta aplicación a base de PHP:
[URL="http://allayers.com/mycanvas/"]Truecolor mycanvas[/URL]

Es fantástica, me vendría de lujo para mi sitio.
Mis conocimientos de PHP son "medios" (no soy un figura, la verdad). El caso es que soy incapaz de hacer funcionar el script, creo que hay un problema con el código y PHP 5.x

Lo he instalado correctamente en mi servidor y no consigo que funcione... cuando intento cargar la imagen de "background", la página se actualiza pero no aparece la imagen.

El problema puede estar en el archivo image.class.php:

Código PHP:
<?
include("include/imagetext.class.php");

////////////////////////MAIN IMAGE CLASS//////////////////////////

class imageobject{

         var 
$handle;
         var 
$type="png";
         var 
$height=0;
         var 
$width=0;
         var 
$string;// for img height/width tags
         
var $square;
         
// output message
         
var $message;
         
// previous file
         
var $previous;
         
// current
         
var $directory;
         var 
$filename;
         
//output
         
var $resample false;
         var 
$quality="80";
         var 
$output=OUTPUT;// alternatives are png8 or png
         
var $transparent// only if output=png8
         // textobject
         
var $previewobject;
         
// option
         
var $savefile true;
         
//
         
var $newobj;

         
//constructor
         
function imageobject($directory,$filename,$width=0,$height=0,$color="FFFFFF")
                  {
                  
$this->directory $directory;
                  
$this->filename $filename;

                  if (
$filename=="" && $width>&& $height>0){

                     
$new $this->createImage($width,$height);
                     
$col ImageColorAllocate($newhexdec(substr($color,0,2)), hexdec(substr($color,2,2)),hexdec(substr($color,4,2)));
                     
ImageFilledRectangle($new,0,0,$width,$height,$col);
                     
$this->newobj $this->createUnique($new);
                     }elseif (
file_exists($directory.$filename)){
                       
$this->filesize ceil(filesize($directory.$filename)/1024);
                       
$size GetImageSize($directory.$filename);
                       if (
$size$this->handle $this->getHandle($directory.$filename,$size[2]);
                       
$this->width $size[0];
                       
$this->height $size[1];
                       
$this->string $size[3];
                       
$this->square $size[0]*$size[1];

                       if (
$this->handle)
                         
$this->message $GLOBALS["message_supported"];
                       else
                         
$this->message $GLOBALS["message_not_supported"];
                       }
                  }
// constructor

         // private methods
        
function getHandle($name,&$type)
        {
           switch (
$type){
              case 
1:
              
$im imagecreatefromgif($name);
              
$this->type"gif";
              break;
              case 
2:
              
$im imagecreatefromjpeg($name);
              break;
              case 
3:
              
$im imagecreatefrompng($name);
              
$this->type"png";
              break;
                      }
           return 
$im;
        }

        function 
saveAlpha(&$handle)
        {
         
ImageAlphaBlending($handletrue);
         
imagesavealpha($handle,false);
         
imagesavealpha($handle,true);
        }

        function 
getHexColor($xpos,$ypos)
        {
              
$color imagecolorat($this->handle$xpos$ypos);
              
$colorrgb imagecolorsforindex($this->handle,$color);

              if (
$colorrgb["red"]>0)$hred dechex($colorrgb["red"]); else $hred "00";
              if (
strlen($hred)<2)$hred "0".$hred;

              if (
$colorrgb["green"]>0)$hgreen dechex($colorrgb["green"]); else $hgreen "00";
              if (
strlen($hgreen)<2)$hgreen "0".$hgreen;

              if (
$colorrgb["blue"]>0)$hblue dechex($colorrgb["blue"]); else $hblue "00";
              if (
strlen($hblue)<2)$hblue "0".$hblue;

              return 
strtoupper($hred.$hgreen.$hblue);
        }

        function 
uniqueName()
        {
          
$add="";
          
$fileparts split("\.",$this->filename);
          
$nonchr = array("__","0","1","2","3","4","5","6","7","8","9");
          
$desc str_replace($nonchr,"",$fileparts[0]);
          
$name $desc."__".date("YmdHms");
          
// if exists add incremented number
          
if (file_exists($this->directory.$name.".".$this->type)){
            
$add 1;
            while(
file_exists($this->directory.$name.$add.".".$this->type)) $add++;
            }
          return 
$imgnew.$name.$add.".".$this->type;
        }

        function 
createUnique($imgnew)
        {
           
$this->type substr($this->output,0,3);

           
$unique_str $this->uniqueName();
           switch (
$this->type){
              case 
"png":
                  
imagepng($imgnew,RES_DIR.$unique_str);
              break;
              default:
                  
imagejpeg($imgnew,RES_DIR.$unique_str,$this->quality);
              break;
              }

           
$this->handle && imagedestroy($this->handle);
           
$newobject = new imageobject(RES_DIR,$unique_str,$this->type);
           return 
$newobject;
        }

        function 
createImage($new_w,$new_h)
        {
           if (
function_exists("imagecreatetruecolor") && $this->output!="png8"){
             return 
imagecreatetruecolor($new_w,$new_h);
             }else{
                return 
imagecreate($new_w,$new_h);
                }
        }

        function 
copyhandle(&$dst_im$src_im$dst_x$dst_y$src_x$src_y$dst_w$dst_h$src_w$src_h)
        {

         if (
$this->output=="png8" && $this->type="jpg"){
            
imagecopyresized($dst_im$src_im$dst_x$dst_y$src_x$src_y$dst_w$dst_h$src_w$src_h);
            
$this->resample==true;
            }

         if (
function_exists("imagecopyresampled") && $this->resample==true)
            
imagecopyresampled($dst_im$src_im$dst_x$dst_y$src_x$src_y$dst_w$dst_h$src_w$src_h);
         else
            
imagecopy($dst_im$src_im$dst_x$dst_y$src_x$src_y$src_w$src_h);

        }

        function 
copycreatehandle(&$src_im$dst_x$dst_y$src_x$src_y$dst_w$dst_h$src_w$src_h)
        {

          
$dst_im $this->createImage($dst_w,$dst_h);

          
$this->copyhandle($dst_im$src_im$dst_x$dst_y$src_x$src_y$dst_w$dst_h$src_w$src_h);

          return 
$dst_im;
        }


         
// public methods
        
function resizeImage($scale,$newwidth=0,$newheight=0)
        {
           
$new_w $this->width;
           
$new_h $this->height;
           
$aspect_ratio = (int) $new_h $new_w;
           if (
$scale$new_w $new_w $scale;
           if (
$newwidth>0$new_w $newwidth;
           if (
$newheight>0){
                
$new_h $newheight;
                
$new_w = (int) $new_h $aspect_ratio;
                }else{
                   
$new_h abs($new_w $aspect_ratio);
                   }
           
$dst_img $this->copycreatehandle($this->handle0000$new_w$new_h$this->width,$this->height);

           return 
$this->createUnique($dst_img);
        }


        function 
cropImage($top,$right,$bottom,$left)
        {
           
$new_w $right $left;
           
$new_h $bottom $top;

           
$dst_img $this->copycreatehandle($this->handle00$left$top$new_w$new_h$new_w$new_h);
           return 
$this->createUnique($dst_img);
        }


        function 
writeText($label$xpos=0$ypos=0$textstring$fontsize$truetype$fontcolor="FFFFFF",$fontangle)
        {
              
$fontbgcolor$this->getHexColor($xpos,$ypos);
              
$textimage = new imagetext($truetype,$fontsize,$fontcolor,$textstring,$fontbgcolor,$fontangle);
              
ImageAlphaBlending($this->handletrue);
              
imagesavealpha($this->handle,false);
              
imagesavealpha($this->handle,true);
              
$this->copyhandle($this->handle$textimage->handle$xpos$ypos00$textimage->dx$textimage->dy,$textimage->dx$textimage->dy);

              return 
$this->createUnique($this->handle);
        }

        function 
mergeImage($dir,$placedfile,$mergewidth,$mergeheight,$offx,$offy,$transcolor="")
        {
              
$source = new imageobject($dir,$placedfile);
              
$source->saveAlpha($source->handle);

              if (
$transcolor){
                
$r hexdec(substr($transcolor02));
                
$g hexdec(substr($transcolor22));
                
$b hexdec(substr($transcolor42));
                
$color imagecolorallocate($source->handle$r$g$b);
                
imagecolortransparent($source->handle,$color);
                }

              
$this->saveAlpha($this->handle);
              
ImageCopyResized($this->handle$source->handle,$offx,$offy,0,0,$mergewidth,$mergeheight,$source->width,$source->height);

              return 
$this->createUnique($this->handle);
        }



   }
// class
?>



¿Alguna ayuda? Sinceramente es una aplicación buenísima, si alguien es capaz de hacerla funcionar en PHP 5...
  #2 (permalink)  
Antiguo 09/08/2012, 06:53
Avatar de KsrZ  
Fecha de Ingreso: abril-2011
Ubicación: /home/KsrZ/Desktop
Mensajes: 156
Antigüedad: 13 años
Puntos: 26
Respuesta: Problema con PHP 5 y Truecolor mycanvas

Antes de leer el cacho de código.. te fijaste si te guarda una "imagen"? o archivo?
los permisos de escritura están correctos en tu host?

no se lo que buscas hacer.. no conozco el script, pero
pasa por acá:
http://php.net/manual/en/imagick.examples-1.php
__________________
for (var i = 0; i < 2; i++){
i = !confirm("Trata a tu código como a ti mismo.. este te esta representando.. no te dejes mal parado")? 0 : i;
}

Última edición por KsrZ; 09/08/2012 a las 07:09
  #3 (permalink)  
Antiguo 09/08/2012, 07:43
 
Fecha de Ingreso: agosto-2012
Mensajes: 2
Antigüedad: 11 años, 8 meses
Puntos: 0
Respuesta: Problema con PHP 5 y Truecolor mycanvas

Tengo asignados los permisos de escritura en las carpetas que lo requieren.
Intento hacer utilizar esta aplicación para mi web, si consigo hacerla funcionar retocaré el código fuente para orientarla a mi sitio... es perfecta.

Etiquetas: mycanvas, php4, php5
Atención: Estás leyendo un tema que no tiene actividad desde hace más de 6 MESES, te recomendamos abrir un Nuevo tema en lugar de responder al actual.
Respuesta




La zona horaria es GMT -6. Ahora son las 01:52.