【发布时间】:2011-05-27 15:23:22
【问题描述】:
我阅读了一些关于此的内容,但我不知道如何将其放入我的代码中。
这里是:
function go($image) {
// Open the image
$getimage=imagecreatefrompng($image);
//Get the width/height
$w = imagesx($getimage);
$h = imagesy($getimage);
//init Count variable, when it reach the width, skip a line
$count = 0;
// For each line
for($y=0;$y<$h;$y++) {
// For each column
for($x=0;$x<$w;$x++) {
$rgba = imagecolorat($getimage, $x, $y);
$r = ($rgba >> 16) & 0xFF;
$g = ($rgba >> 8) & 0xFF;
$b = $rgba & 0xFF;
$a = ($rgba & 0x7F000000) >> 24;
echo '<div class="pix" style="background-color: rgba('.$r.', '.$g.', '.$b.', '.$a.');"></div>';
$count++;
if($count==$w) {echo '<br>'; $count = 0; }
}
}
echo $pixel_gen;
}
如果oyu想看看它的样子,请点击这里:http://narks.xtreemhost.com/
然后双击任何图标,将出现弹出窗口。 (注意:dbl-clinking 任何图标都会显示相同的图像(我还没有解决这个问题)
知道如何使黑色像素看起来像带有 alpha 的真实像素吗?
感谢您的帮助!
已编辑 (新代码,我只放了第一行,因为我想节省空间)
function go($image) {
// Open the image
$getimage=imagecreatefrompng($image);
imagealphablending($getimage, false);
imagesavealpha($getimage, true);
//Get the width/height
$w = imagesx($getimage);
$h = imagesy($getimage);
[...]
要查看它现在的样子,请访问上面的网站并双击一个图标。
编辑 2 我刚刚尝试(进行测试):
$getimage=imagecreatefrompng('iconDB/lib/chat_fav_48.png');
imagealphablending($getimage, false);
imagesavealpha($getimage, true);
header("Content-type: image/png");
imagepng($getimage);
imagedestroy($getimage);
然后用
$getimage=imagecreatefrompng('iconDB/lib/chat_fav_48.png');
header("Content-type: image/png");
imagepng($getimage);
imagedestroy($getimage);
第一个没问题,第二个使像素变黑。所以当我得到每个像素的 RGB 颜色并显示它时。有人看到那里有错误吗?
【问题讨论】: