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
| <?php
function modif_alpha($src , $dest , $alpha){
/*
* webmaster@creatixnet.com - licence bananière
* ("faites de ce code ce que vous voulez...")
*
* Paramètres : $src : fichier source
* $dest : fichier de destination
* $alpha : transparence (entre 0 (opaque) et 127 (transparent))
*
* EX : modif_alpha('image.jpg', 'image.png', 70)
* rend l'image à moitié transparente.
*/
if (file_exists($src)) $size = getimagesize($src);
else return FALSE;
switch($size[2])
{
case 1 :
if (imagetypes() & IMG_GIF)
$pic = imagecreatefromgif($src);
break;
case 2 :
if (imagetypes() & IMG_JPG)
$pic = imagecreatefromjpeg($src);
break;
case 3 :
if (imagetypes() & IMG_PNG)
$pic = imagecreatefrompng($src);
break;
default :
if (preg_match("/\.wbmp$/i", $src) && (imagetypes() & IMG_WBMP))
$pic = imagecreatefromwbmp($src);
}
if (!$pic) return FALSE;
$new=imagecreatetruecolor($size[0], $size[1]);
imagealphablending($new, FALSE);
imagesavealpha ($new, true);
$colors_num = imagecolorstotal($pic);
for($x=0;$x<$size[0];$x++) {
for($y=0;$y<$size[1];$y++) {
$colorat=imagecolorat($pic,$x,$y);
$color = imagecolorsforindex($pic, $colorat);
$r = $color["red"];
$g = $color["green"];
$b = $color["blue"];
$idx=imagecolorallocatealpha($new,$r,$g,$b,$alpha);
imagesetpixel($new,$x,$y,$idx);
}
}
imagepng($new, $dest);
return TRUE;
}
?> |
Partager