unendo il mio script per ridimensionare l'img e l'esempio del manuale, ho ricavato questo.
Codice PHP:
<?php
// Original image$filename = 'test.jpg';
// Get dimensions of the original imagelist($current_width, $current_height) = getimagesize($filename);
$w = $current_width;
$h = $current_height;
$x = 170; //DIMENSIONI DEL DIV
if($current_height>$current_width)//RIDIMENSIONO IN BASE ALL'ALTEZZA
{ $setX = $current_width = $x;
$current_height = (int)($x/$w*$h);
//echo "se h > w<br />w = 170 mentre h = ".$height;
}else
{//RIDIMENSIONO IN BASE ALLA LARGHEZZA
$setY = $current_height = $x;
$current_width = (int)($x/$h*$w);
//echo "se W > H<br />H = 170 mentre W = ".$width; }
// COORDINATE DA CUI PARTE IL RITAGLIO
$left = $setX;
$top = $setY;
// GRANDEZZA DEL RITAGLIO
$crop_width = 170;
$crop_height = 170;
// Resample the image
$canvas = imagecreatetruecolor($crop_width, $crop_height);
$current_image = imagecreatefromjpeg($filename);
imagecopy($canvas, $current_image, 0, 0,$left, $top, $current_width, $current_height);
imagejpeg($canvas, $filename, 100);?>
<img src="test.jpg" />
ho 2 problemi:
1- nonostante il ridimensionamento funzioni, l'img viene tagliata dall'img originale (ovviamente il resize è solamente un'equazione quindi non modifica le dimensioni dell'originale)
2- tenendo conto di utilizzare l'img a runtime, non riesco a evitare di far modificare l'img originale sul server (quindi la taglia fisicamente)