【发布时间】:2013-05-02 23:11:35
【问题描述】:
我正在尝试通过使用转换为 Alpha 过滤器(请参阅 http://erskinedesign.com/blog/fireworks-tips-convert-alpha/)来实现与 Fireworks 所做的类似的事情。这可能只使用 php gd 函数吗?
我的代码如下:
$img = imagecreatefromstring(file_get_contents('...'));
imagealphablending($img, true);
$transparentcolour = imagecolorallocate($img, 255,255,255);
imagecolortransparent($img, $transparentcolour);
imagefilter($img, IMG_FILTER_GRAYSCALE);
$w = imagesx($img);
$h = imagesy($img);
for ($x=0; $x<$w; $x++)
{
for ($y=0; $y<$h; $y++)
{
$color = imagecolorsforindex($img, imagecolorat($img, $x, $y));
if ($color['alpha'] == 0)
continue;
}
}
imagepng($img);
exit;
我的想法是转换为灰度,测量一个像素有多“暗”,然后将其转换为黑色 alpha,但我自己似乎很困惑。
【问题讨论】:
-
这是您所说功能的全部代码吗?我在这里没有看到任何 imagepng()。
-
imagepng() 就在 for 循环之后。
标签: php transparency gd