Tuesday, August 3, 2010

allows of exchange the size of an image in php

allows of exchange the size of an image in php veiled Ca can be very useful for the site wap/i-mode since it changes as the weight of the file doncs Ca allows as the page would not be too heavy
size.php :
/// < img src="size.php?pic=(url of your image)&w_max=(largor maximum)&h_max=(hautor)">

PHP Code:
$taille getimagesize("$pic");  $h_i $taille[1];  $w_i $taille[0]; 
if(
$h_i >$h_max
{  
$convert=$h_max/$h_i;  $h_i=$h_max;  $w_i=ceil($w_i*$convert); 

if(
$w_i >$w_max
{  
$convert=$w_max/$w_i;  $w_i=$w_max;  $h_i=ceil($h_i*$convert); 
}; 
$largeur "$w_i"$hauteur ="$h_i";
header("Content-Type: image/jpeg");
list(
$width$height$type$attr) = getimagesize("$pic");

if(
$type == "1")
$img_in imagecreatefromgif($pic);
}

if(
$type == "2")
$img_in imagecreatefromjpeg($pic);
}

if(
$type == "3")
$img_in imagecreatefrompng($pic);
}
$img_out imagecreatetruecolor($largeur$hauteur); imagecopyresampled($img_out$img_in0000imagesx($img_out), imagesy($img_out), imagesx($img_in), imagesy($img_in)); $t imagejpeg($img_out);
echo 
$t?>

No comments:

Post a Comment