【问题标题】:Combining images in PHP while retaining transparency在 PHP 中组合图像,同时保持透明度
【发布时间】:2011-03-07 20:26:11
【问题描述】:

看看这里:http://tyilo.jbusers.com/PNG/progress.php?l=100&p=20

我想删除蓝色部分末尾的白色东西,但我尝试了许多不同的东西,但都不起作用。

如果需要,可以在 http://tyilo.jbusers.com/PNG/ 文件夹 (http://tyilo.jbusers.com/PNG/Empty.png) 中找到 png 文件

header('Content-type: image/png');
echo imagepng(progressbar($_GET['l'], $_GET['p']));
function progressbar($length, $percentage)
{
$length = round($length / 2) * 2;
$percentage = min(100, max(0, $percentage));
if($length > 0)
{
    $bar = imagecreate($length, 14);
    $empty = imagecreatefrompng('Empty.png');
    $fill = imagecreatefrompng('Fill.png');
    $lempty = imagecreatefrompng('LeftEmpty.png');
    $lfill = imagecreatefrompng('LeftFill.png');
    $rempty = imagecreatefrompng('RightEmpty.png');
    $rfill = imagecreatefrompng('RightFill.png');
    $emptycaplength = min(7, $length / 2); //5 
    imagecopy($bar, $lempty, 0, 0, 0, 0, $emptycaplength, 14);
    imagecopy($bar, $rempty, $length - $emptycaplength, 0, 7 - $emptycaplength, 0, $emptycaplength, 14);
    if($length > 14)
    {
        imagecopyresized($bar, $empty, 7, 0, 0, 0, $length - 14, 14, 1, 14);
    }
    $filllength = round(($length * ($percentage / 100)) / 2) * 2;
    $fillcaplength = min(7, $filllength / 2);
    imagecopy($bar, $lfill, 0, 0, 0, 0, $fillcaplength, 14);
    imagecopy($bar, $rfill, $filllength - $fillcaplength, 0, 7 - $fillcaplength, 0, $fillcaplength, 14);
    if($filllength > 14)
    {
        imagecopyresized($bar, $fill, 7, 0, 0, 0, $filllength - 14, 14, 1, 14);
    }
    return $bar;
}
else
{
    return false;
}
}

【问题讨论】:

  • 你的previous question有什么不同?
  • 故意询问复制粘贴重复问题是暂停帐户的好方法。请不要这样做。

标签: php png transparency gd


【解决方案1】:

尝试使用 imagecreatetruecolor() 创建图像。

http://www.php.net/manual/en/function.imagecreatetruecolor.php

【讨论】:

    【解决方案2】:

    我认为您需要设置图像的 Alpha 混合...

     imagealphablending($cropimg, false);
     imagesavealpha($cropimg, true);
    

    我还发现它有助于设置颜色分配。

    imageColorAllocate ($cropimg, 0, 0, 0);
    

    我认为您需要在所有填充图像上调用这三个函数。很抱歉回答不完整,我很着急,但我想我会扔给你一根骨头。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-01-12
      • 1970-01-01
      • 2018-12-21
      • 1970-01-01
      • 2021-10-08
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多