开发者

PHP change transparent gradient png image color

I have image here (transparent PNG image)

PHP change transparent gradient png image color

I want to change with blue one, is there any function(s) or library class to change my image开发者_Python百科? I know there are many website use their function to generate transparent gif with color.

Please help me.


$img = imagecreatefromgif("put here your image path");

// Grab all color indeces for the given image.
$indeces = array();
for ($y = 0; $y < $imgHeight; ++$y) {
    for ($x = 0; $x < $imgWidth; ++$x) {
        $index = imagecolorat($img, $x, $y);
        if (!in_array($index, $indeces)) {
            $indeces[] = $index;
        }
    }
}   

foreach ($indeces as $index) {
    // Grab the color info for the index.
    $colors = imagecolorsforindex($img, $index);

    // Here, you would make your color transformation.
    $red    = $colors['red'];
    $green  = $colors['green'];
    $blue   = $colors['blue'];
    $alpha  = $colors['alpha'];

    // Update the old color to the new one.
    imagecolorset($img, $index, $red, $green, $blue, $alpha);
}

This is untested code. The actual color transformation is left up to you, but as long as you use the same transformation across all indeces and don't muck with the alpha, the resulting image should retain the gradient.

Reference: http://www.php.net/manual/en/ref.image.php

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜