Get Alpha from PNG created with imagepng()
Frank,
Here is your solution with code
<!DOCTYPE html>
<html lang="en">
<head>
<title>Test</title>
</head>
<body>
<a href="index.php" class="navbar-brand">
<?php
$x = 1;
$y = 1;
$gd = imagecreatetruecolor($x, $y);
imageAlphaBlending($gd, false);
imageSaveAlpha($gd, true);
imagesetpixel($gd, 0, 0, imagecolorallocatealpha($gd, 200, 200, 200, 1));
imagepng($gd, 'img/logo.png" ');
imagedestroy($gd);
$im = imagecreatefrompng('img/logo.png');
$rgb = imagecolorat($im, 0, 0);
$colors = imagecolorsforindex($im, $rgb);
$red = (int) $colors["red"];
$blue = (int) $colors["blue"];
$green = (int) $colors["green"];
echo $alpha = (int) $colors["alpha"]; // return only 0
?>
</a>
</body>
</html>
You should call imageAlphaBlending
and imageSaveAlpha
before calling imagesetpixel
:
imageAlphaBlending($gd, false);
imageSaveAlpha($gd, true);
imagesetpixel($gd, 0,0, imagecolorallocatealpha($gd, 200,200,200,1));