Io ho modificato la classe in questo modo
codice:
class Image
{
var $src_filename;
var $src_witdh;
var $src_height;
var $src_type;
var $src_attr;
var $src_image;
function Image($filename)
{
$this->src_filename = $filename;
$this->GetImageInfo();
}
function GetImageInfo()
{
list($this->src_width,$this->src_height, $this->src_type, $this->src_attr) = getimagesize($this->src_filename);
}
function CreateSourceImage()
{
switch ($this->src_type)
{
case 1:
$this->src_image =imagecreatefromgif($this->src_filename);
break;
case 2:
$this->src_image =imagecreatefromjpeg($this->src_filename);
break;
case 3:
$this->src_image =imagecreatefrompng($this->src_filename);
break;
default: return false;
}
return true;
}
function GetHeight ($height , $width, $side)
{
if ($height > $width)
{
$side = $side;
}
elseif ($height < $width)
{
$side = ($height*$side)/$width;
}
}
function SaveProportionateImage($filename, $quality, $height)
{
$dest_height = $this->GetHeight($this->src_height , $this->src_width , $height);
$ratio = $this->src_height / $dest_height;
$dest_image = imagecreatetruecolor( $this->src_width / $ratio,$dest_height);
imagecopyresampled($dest_image, $this->src_image, 0, 0, 0, 0,$this->src_width / $ratio,$this->src_height / $ratio,$this->src_width,$this->src_height);
imagejpeg($dest_image, $filename, $quality);
imagedestroy($dest_image);
}
function Free()
{
imagedestroy($this->src_image);
}
}
Ho preparato una pagina di test ma niente. La classe non funziona. L'errore sta nel modo in cui ho definito le variabili. Lo so perchè sia la classe che la funzione, prese singolarmente, funzionano. Il problema nasce nel momento in cui tento di implementare la funzione nella classe. Ho evidenziato in rosso la funzione in questione (quella da me creata) ed in arancione la funzione che crea l'immagine. Spero che qualcuno riesca a sistemare le variabili! Grazie mille!