在保留透明度的情况下在PHP中组合图像 [英] Combining images in PHP while retaining transparency

查看:67
本文介绍了在保留透明度的情况下在PHP中组合图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

我想去除蓝色部分末尾的白色东西,但是我尝试了许多不起作用的事情.

I want to remove the white-thingy at the end of the blue part, but I have tried many different things that didn't work.

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

If needed the pngs can be found in http://tyilo.jbusers.com/PNG/ folder (http://tyilo.jbusers.com/PNG/Empty.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;
}
}

推荐答案

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

try using imagecreatetruecolor() to create your image.

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

这篇关于在保留透明度的情况下在PHP中组合图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆