Salve a tutti, sul manuale PHP si dice che i due comandi, imagecopyresampled e imagecopyresized lavorano partendo dallo steso set di variabili
Codice PHP:
imagecopyresampled ( resource dst_image, resource src_image, int dst_x, int dst_y, int src_x, int src_y, int dst_w, int dst_h, int src_w, int src_h )
imagecopyresized ( resource dst_image, resource src_image, int dst_x, int dst_y, int src_x, int src_y, int dst_w, int dst_h, int src_w, int src_h )
tuttavia se intendo creare una versione ridotta della porzione centrale, la classica 100x100 resyzed lavora correttamente, resampled no!
ecco il codice:
Codice PHP:
//variabili----------
$imageDirectory = " ";
$imageName = $icona;
$thumbDirectory = " ";
$thumbWidth = $ico_size;
$thumbHeight = $ico_size;
$thumbName = "ico_$imageName";
$thumbComp = "100";
//resyzer
$tnsize_x = (integer) $thumbWidth; //100
$tnsize_y = (integer) $thumbHeight; //100
$sz = getimagesize("$imageDirectory/$imageName");
$x = $sz[0]; // big image width
$y = $sz[1]; // big image height
$w = $tnsize_x;
$h = $tnsize_y;
if ($x>$y) {//se è orizzontale
$cw = 0;
$ch = 0;
$cx = ($x-$y)/2;
$cy = 0;
$x = $y;
} elseif ($y>$x){//se è verticale
$cw = 0;
$ch = 0;
$cx = 0;
$cy = ($y-$x)/2;
$y = $x;
} else {//se è quadrata
$cw = 0;
$ch = 0;
$cx = 0;
$cy = 0;
$y = $x;
}
//crea la miniatura e la salva
$srcImg = imagecreatefromjpeg("$imageDirectory/$imageName");
$thumbImg = imagecreatetruecolor($thumbWidth, $thumbHeight);
magecopyresized($thumbImg, $srcImg, $cw, $ch, $cx, $cy, $w, $h, $x, $y);
imagejpeg($thumbImg, "$thumbDirectory/$thumbName", $thumbComp);
imagedestroy($thumbImg);
imagedestroy($srcImg);
$msg .= "Icona correttamente ridimensionata
";
Lo script lavora su PHP 4.3.1 e GD 2.0 or higher.
Che ne dite?