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 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66
| <?php
function createThumbWithOver($img_src,$w_thumb,$h_thumb,$border=10,$radial=24,$alpha=0){
$pic['destNormal']['name'] = $img_src; // nom du fichier normal
$makePic = false; // variable pour vérifcation is on cré les images ou non
// Routine pour vérifier si le fichier cache existe et si il est plus vieux que l'image d'origine
if(file_exists('./temp/'.$pic['destNormal']['name'].'.png') === true ){ // si le fihcier existe ?
if(intval(filemtime($img_src)) > intval(filemtime('./temp/'.$pic['destNormal']['name'].'.png'))) $makePic = true;
}else $makePic = true; // si le fihcier cache n'existe pas il faut le créer
// Vérification de la variable , piour savoIr si on cré les images
if($makePic === true){
// Récupération des infos de l'image source
list($pic['src']['info']['width'], $pic['src']['info']['height'], $pic['src']['info']['type'], $pic['src']['info']['attr']) = getimagesize($img_src);
//On vérifie si le parametre de la hauteur est plsu grand que 0
if($h_thumb == 0){ // si egal a zaro on affecte la hauteur proportionnellement
$h_thumb = floor($pic['src']['info']['height'] * $w_thumb / $pic['src']['info']['width']);
}
switch($pic['src']['info']['type']){
case"1": $pic['src']['ress'] = imagecreatefromgif($img_src); break; // Création de l'image pour une source gif
case"2": $pic['src']['ress'] = imagecreatefromjpeg($img_src); break; // Création de l'image pour une source jpg
case"3": $pic['src']['ress'] = imagecreatefrompng($img_src); break; // Création de l'image pour une source png
}
$pic['destNormal']['ress'] = imagecreatetruecolor($w_thumb, $h_thumb); // On crée la miniature vide pour l'image Etat Normal
// On crée la miniature Normal
imagecopyresampled($pic['destNormal']['ress'], $pic['src']['ress'], 0, 0, 0, 0, $w_thumb, $h_thumb, $pic['src']['info']['width'], $pic['src']['info']['height']);
// On commence à créer le masque pour le contour coin rond
$pic['maskBorder']['ress'] = imagecreate($w_thumb, $h_thumb); // On crée le mask vide
$pic['maskBorder']['green'] = imagecolorallocate($pic['maskBorder']['ress'], 0, 255, 0); // affectation de la couleur verte
$pic['maskBorder']['pink'] = imagecolorallocate($pic['maskBorder']['ress'], 255, 0, 255); // affectation de la couleur rose
// Ici on trace la zone à mettre en transparence avant le merge entre les 2 images
// PRINCIPE : 4 cercle situé dans chauque coin avec un rayon de 2 fois la bordure
// PRINCIPE : 1 forme polygonale de 8 coter pour peindre de rose la zone restante
imagefilledellipse($pic['maskBorder']['ress'], $radial, $radial, $radial*2, $radial*2, $pic['maskBorder']['pink']); // cercle gauche supérieur
imagefilledellipse($pic['maskBorder']['ress'], $w_thumb-$radial, $radial, $radial*2, $radial*2, $pic['maskBorder']['pink']); // cercle droite supérieur
imagefilledellipse($pic['maskBorder']['ress'], $radial, $h_thumb-$radial, $radial*2, $radial*2, $pic['maskBorder']['pink']); // cercle gauche inférieur
imagefilledellipse($pic['maskBorder']['ress'], $w_thumb-$radial, $h_thumb-$radial, $radial*2, $radial*2, $pic['maskBorder']['pink']); // cercle droit inférieur
imagefilledpolygon ($pic['maskBorder']['ress'], array($radial,0,0,$radial,0,$h_thumb-$radial,$radial,$h_thumb,$w_thumb-$radial,$h_thumb,$w_thumb,$h_thumb-$radial,$w_thumb,$radial,$w_thumb-$radial,0), 8, $pic['maskBorder']['pink']); // forme géométrique à 8 coter
imagecolortransparent($pic['maskBorder']['ress'], $pic['maskBorder']['pink']); // Applique la transparence à la couleur rose
// TRAITEMENT SUR L'IMAGE NORMAL
imagecopymerge($pic['destNormal']['ress'], $pic['maskBorder']['ress'], 0, 0, 0, 0, $w_thumb, $h_thumb, 100); // copie du masque au dessus de la miniature avec une transparence (0%)
// il faut enlever le vert pour que le fond soit transparent
if($radial > 0){ // si le radial est de 0 alors ne pas appliquer la transparence parce que le pixel 0,0 n'est pas vert ce qui entraine une transparence sur les zones qui on la meme couleur que le pixel 0,0
imagetruecolortopalette($pic['destNormal']['ress'], FALSE, 256); // conversion en palette 256 couleur
$pic['destNormal']['green'] = imagecolorat($pic['destNormal']['ress'], 0, 0); // affectation de la couleur verte (récupérer au pixel 0,0)
imagecolortransparent($pic['destNormal']['ress'], $pic['destNormal']['green']); // Applique la transparence à la couleur verte
}
// On enregistre la miniature avec bordure coin rond
imagepng($pic['destNormal']['ress'],'./temp/'.$pic['destNormal']['name'].'.png');
imagedestroy($pic['destNormal']['ress']);
}
// Retourne les le code html / javascript pour afficher l'image et effectuer le rollOver / rollOut
return 'src="./temp/'.$pic['destNormal']['name'].'.png"';
//unlink(
}
?>
<img <?php echo createThumbWithOver('1.jpg',1024,260); ?> style="cursor:pointer;"> |
Partager