0

ここに画像があります(透明なPNG画像)

ここに画像の説明を入力

青いものに変更したいのですが、画像を変更する関数やライブラリ クラスはありますか? 多くのWebサイトがその機能を使用して、色付きの透明なgifを生成していることを知っています。

私を助けてください。

4

1 に答える 1

1
$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);
}

これはテストされていないコードです。実際の色変換はあなた次第ですが、すべてのインデックスで同じ変換を使用し、アルファをいじらない限り、結果の画像はグラデーションを保持するはずです。

参照: http://www.php.net/manual/en/ref.image.php

于 2011-09-11T13:55:42.297 に答える