se vuoi questa è una classe che uso per il ridimensionamento con php delle immagini
Codice PHP:
class Thumbnail
{
// Set destination filename
function setImgSource( $source )
{
$this->source = $source;
}
// Set maximum size of thumbnail
function setMaxSize ( $max_width = 100, $max_height = 100 )
{
$this->max_width = $max_width;
$this->max_height = $max_height;
}
// Get info about original image
function getImageData( $data )
{
$size = GetImageSize( $this->source );
switch ( $data )
{
case 'width':
return $size[0];
break;
case 'height':
return $size[1];
break;
case 'type':
switch ( $size[2] )
{
case 1:
return 'gif';
break;
case 2:
return 'jpg';
break;
case 3:
return 'png';
break;
}
break;
}
}
// Get info about thumbnail
function getThumbData( $data )
{
$w_ratio = $this->max_width / $this->GetImageData('width');
$h_ratio = $this->max_height / $this->GetImageData('height');
if ( $h_ratio < $w_ratio )
{
$height = $this->max_height;
$width = round( $this->GetImageData('width') * $h_ratio, 0);
}
else
{
$width = $this->max_width;
$height = round( $this->GetImageData('height') * $w_ratio, 0);
}
switch ( $data )
{
case 'width':
return $width;
break;
case 'height':
return $height;
break;
}
}
// Creating a thumbnail
function Create( $dest )
{
$img_des = ImageCreateTrueColor ( $this->GetThumbData('width'), $this->GetThumbData('height') );
switch ( $this->GetImageData('type') )
{
case 'gif':
$img_src = ImageCreateFromGIF ( $this->source );
break;
case 'jpg':
$img_src = ImageCreateFromJPEG ( $this->source );
break;
case 'png':
$img_src = ImageCreateFromPNG ( $this->source );
break;
}
@ImageCopyResized( $img_des, $img_src, 0, 0, 0, 0, $this->GetThumbData('width'), $this->GetThumbData('height'), $this->GetImageData('width'), $this->GetImageData('height') );
switch ( $this->GetImageData('type') )
{
case 'gif':
if ( empty( $dest ) )
{
header( "Content-type: image/gif" );
return ImageGIF( $img_des );
}
else
{
return ImageGIF( $img_des, $dest );
}
break;
case 'jpg':
if ( empty( $dest ) )
{
header ( "Content-type: image/jpeg" );
return ImageJPEG($img_des,'',100);
}
else
{
return ImageJPEG( $img_des, $dest, 100 );
}
break;
case 'png':
if ( empty( $dest ) )
{
header ( "Content-type: image/png" );
return ImagePNG( $img_des );
}
else
{
return ImagePNG( $img_des, $dest );
}
break;
}
}
}
e la utilizzi in questo modo (dopo aver incluso il file in cui hai messo la classe nel file in cui la utilizzi)
Codice PHP:
$ImgResize = new Thumbnail; // Start using a class $ImgResize->setMaxSize(80,80); // Specify maximum size (width, height) $ImgResize->setImgSource($immagine); // Specify original image filename $ImgResize->Create(""); //vuoto per output diretto, indirizzo sul server nel caso si volesse salvare l'immagine