CODE :
// Paramètre -> image_create_thumb($filename, $width, $height)
// $filename -> adresse de l'image
// $width -> largeur de la miniature voulu
// $height -> grandeur de la miniature voulu
// Exemple : image_create_thumb('http://www.pckult.net/images/image.jpg',100,100);
function image_create_thumb($filename, $width, $height)
{
list($image["Width"], $image["Height"], $image["Type"]) = getimagesize($filename);
if($image["Type"] == IMG_JPG || $image["Type"] == IMG_JPEG)
{
$im_image = ImageCreateFromJPEG($filename);
}
if($image["Type"] == IMG_GIF)
{
$im_image = ImageCreateFromGIF($filename);
}
if($image["Type"] == IMG_PNG)
{
$im_image = ImageCreateFromPNG($filename);
}
if($image["Width"] > $image["Height"])
{
$scale = $width / $image["Width"];
$thumb_width = $width;
$thumb_height = floor($image["Height"]*$scale);
}
else
{
$scale = $height / $image["Height"];
$thumb_height = $height;
$thumb_width = floor($image["Width"]*$scale);
}
$im_thumb = @ImageCreateTrueColor($thumb_width, $thumb_height) or die("Impossible de généré l'image à partir du module GD de PHP");
ImageCopyResized($im_thumb,$im_image,0,0,0,0,$thumb_width,$thumb_height,$image["Width"],$image["Height"]);
ImageDestroy($im_image);
ImagePNG($im_thumb, $filename);
ImageDestroy($im_thumb);
return true;
}
Marquer favoris
Bookmark
Email This
Hits: 969
Commentaires (0)

Ecrivez un commentaire





















