per il jpg è ok, ma adesso mi serve per il PNG, in effetti la funzione imagecreatetruecolor funziona solo per il formato JPG!
la funzione aggiornata ora è:
Codice PHP:
function resampimagejpg($forcedwidth, $forcedheight, $sourcefile, $destfile, $imgcomp,$type) {
$g_imgcomp=100-$imgcomp;
$g_srcfile=$sourcefile;
$g_dstfile=$destfile;
$g_fw=$forcedwidth;
$g_fh=$forcedheight;
if(file_exists($g_srcfile))
{
$g_is=getimagesize($g_srcfile);
if(($g_is[0]-$g_fw)>=($g_is[1]-$g_fh))
{
$g_iw=$g_fw;
$g_ih=($g_fw/$g_is[0])*$g_is[1];
}
else
{
$g_ih=$g_fh;
$g_iw=($g_ih/$g_is[1])*$g_is[0];
}
if (ereg("jpeg",$type)) $img_src=imagecreatefromjpeg($g_srcfile);
if (ereg("gif",$type)) $img_src=imagecreatefromgif($g_srcfile);
if (ereg("png",$type)) $img_src=imagecreatefrompng($g_srcfile);
if (ereg("jpeg",$type)) {
$img_dst=imagecreatetruecolor($g_iw,$g_ih);
} else {
$img_dst=imagecreate($g_iw,$g_ih);
}
imagecopyresampled($img_dst, $img_src, 0, 0, 0, 0, $g_iw, $g_ih, $g_is[0], $g_is[1]);
imagejpeg($img_dst, $g_dstfile, $g_imgcomp);
imagedestroy($img_dst);
return true;
}
else
return false;
}