Titre: Vignette de très bonne qualité
Posté par: arnaudb le le 03-06-2006 a 13:13:40
Salut,
Je cherche un script qui génère des vignettes de très bonne qualité et ou on peut défénir une largeur fixe qui sera toujours respectée.
Ceci dans un but d'avoir des vignettes de bonne qualité, mais aussi pour réduire le poids de l'image.
Merci
|
Titre: Re:Vignette de très bonne qualité
Posté par: arnaudb le le 03-06-2006 a 16:32:59
Eh ben ça manque d'entrain sur ce site lol ;)
Allez cadeau pour vous, après plusieurs heures de boulot:
// créer un fichier thumbnail.php que vous inclurez ou vous en avez besoin
Code:
<?php function createthumb($name,$filename,$new_w,$new_h){ $system=explode('.',$name); if (preg_match('/jpg|jpeg|JPG|JPEG/',$system[1])){ $src_img=imagecreatefromjpeg($name); } if (preg_match('/png/',$system[1])){ $src_img=imagecreatefrompng($name); }
$old_x=imageSX($src_img); $old_y=imageSY($src_img); if ($old_x > $old_y) { $thumb_w=$new_w; $thumb_h=$old_y*($new_h/$old_x); } if ($old_x < $old_y) { $thumb_w=$old_x*($new_w/$old_y); $thumb_h=$new_h; } if ($old_x == $old_y) { $thumb_w=$new_w; $thumb_h=$new_h; }
$dst_img=ImageCreateTrueColor($thumb_w,$thumb_h); imagecopyresampled($dst_img,$src_img,0,0,0,0,$thumb_w,$thumb_h,$old_x,$old_y);
if (preg_match("/png/",$system[1])) { imagepng($dst_img,$filename); } else { imagejpeg($dst_img,$filename); } imagedestroy($dst_img); imagedestroy($src_img); }
?> |
|
// Votre fichier:
Code:
include('thumbnail.php'); if(!file_exists('thumbs/tn_ta_photo.jpg')) { createthumb('taphoto.jpg','thumbs/tn_ta_photo.jpg',100,100); }
|
|
|
Forum-webmaster | Actionné par YaBB SE
© 2001-2003, YaBB SE Dev Team. Tous droits réservés.
|