2011-09-11 30 views
0

私はここにイメージを持っている(透過PNG画像)PHPの変更透明勾配のpng画像の色

enter image description here私は青いものに変更したい

は、私の画像を変更するには、任意の関数(複数可)またはライブラリのクラスがあります?私は多くのウェブサイトが色を使って透明なGIFを生成する機能を使用していることを知っています。

私を助けてください。

+0

。 – oknoorap

答えて

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

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

参考:http://www.php.net/manual/en/ref.image.php私はちょうど感謝「PHPの変更透明グラデーション画像の色をPNG形式」への質問のタイトル編集し

関連する問題