1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31
|
function reduire_photo($ad,$larg,$rep,$ext){
list($width, $height) = getimagesize($ad);
$newwidth = $larg;
$newheight =(int)($height*$larg/$width);
$a=explode("/",$ad);
$l=count($a)-1;
$adresse_photo_r=$rep.$a[$l];
$thumb = imagecreatetruecolor($newwidth, $newheight);
if($ext=="gif") $source = imagecreatefromgif($ad);
if($ext=="jpg") $source = imagecreatefromjpeg($ad);
$originaltransparentcolor = imagecolortransparent( $source );
if($originaltransparentcolor >= 0 // -1 pour opaque
&& $originaltransparentcolor < imagecolorstotal( $source ))
{
$transparentcolor = imagecolorsforindex( $source, $originaltransparentcolor );
$newtransparentcolor = imagecolorallocate(
$thumb,
$transparentcolor['red'],
$transparentcolor['green'],
$transparentcolor['blue']
);
imagefill( $thumb, 0, 0, $newtransparentcolor );
imagecolortransparent( $thumb, $newtransparentcolor );
}
imagecopyresized($thumb, $source, 0, 0, 0, 0, $newwidth, $newheight, $width, $height);
if($ext=="gif") imagegif($thumb,$adresse_photo_r);
elseif($ext=="jpg") imagejpeg($thumb,$adresse_photo_r);
imagedestroy($thumb);
return $adresse_photo_r;
} |
Partager