$oldY) { $thumb_w = $width; $thumb_h = $oldY*($height/$oldX); } if($oldX < $oldY) { $thumb_w = $oldX*($width/$oldY); $thumb_h = $height; } if($oldX == $oldY) { $thumb_w = $width; $thumb_h = $height; } if(!$keepRatio){ $thumb_w = $width; $thumb_h = $height; } $dst_resource = ImageCreateTrueColor($thumb_w,$thumb_h); switch (mb_strtolower($infos['extension'])) { case 'png': $resource = ImageCreateFromPNG($path); imagealphablending($dst_resource, false); imagecopyresampled($dst_resource,$resource,0,0,0,0,$thumb_w,$thumb_h,$oldX,$oldY); imagesavealpha($dst_resource, true); $result = imagepng($dst_resource, $path, 4); break; case 'jpg': case 'jpeg': imagecopyresampled($dst_resource,$resource,0,0,0,0,$thumb_w,$thumb_h,$oldX,$oldY); $result = imagejpeg($dst_resource,$path,80); break; default: //On ne peut pas resize les GIF (sans faire une usine à gaz) //On ne peut resize les BMP que depuis la v7.0 de PHP break; } imagedestroy($dst_resource); imagedestroy($resource); } public static function resource($path){ $infos = pathinfo($path); switch (mb_strtolower($infos['extension'])){ case 'jpg': case 'jpeg': return imagecreatefromjpeg($path); break; case 'png': return imagecreatefrompng($path); break; case 'gif': return imagecreatefromgif($path); break; default: return 0; break; } } } ?>