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>0 && $height>0){
$new = $this->createImage($width,$height);
$col = ImageColorAllocate($new, hexdec(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($handle, true);
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->handle, 0, 0, 0, 0, $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->handle, 0, 0, $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->handle, true);
imagesavealpha($this->handle,false);
imagesavealpha($this->handle,true);
$this->copyhandle($this->handle, $textimage->handle, $xpos, $ypos, 0, 0, $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($transcolor, 0, 2));
$g = hexdec(substr($transcolor, 2, 2));
$b = hexdec(substr($transcolor, 4, 2));
$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... |