php function setAlphaFon src imagealphablending src false imagesavealp

 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
<?php
function setAlphaFon(&$src)
{
imagealphablending($src, false);
imagesavealpha($src, true);
$srcW = imagesx($src);
$srcH = imagesy($src);
for($x = 0; $x < $srcW; $x++)
{
for($y = 0; $y < $srcH; $y++)
{
$srcColor = imagecolorsforindex($src, imagecolorat($src, $x, $y));
if($srcColor['alpha'] == 60) {
$srcColor = imagecolorallocatealpha(
$src, $srcColor['red'], $srcColor['green'], $srcColor['blue'], 127
);
imagesetpixel($src, $x, $y, $srcColor);
}
}
}
}
$image = imagecreatefrompng('logo.png');
setAlphaFon($image, array(255, 0, 0));
header('Content-type: image/png');
imagepng($image);