$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);
}
Ceci est du code non testé. La transformation de couleur réelle est laissée à vous, mais tant que vous utilisez la même transformation à travers tous les indeces et ne pas débloquer avec l'alpha, l'image résultante devrait conserver le gradient.
Référence: http://www.php.net/manual/en/ref.image.php
Je viens titre de la question edited à merci "changement PHP gradient transparent couleur de l'image .png". – oknoorap