Quand vous faites un patch redimensionne à un grand groupe de JPG, PNG et fichiers GIF, PHP tombe mort à l'improviste avec le message d'erreur suivant:Qu'est-ce qui pourrait causer une erreur "indice de couleur hors plage" pour imagecolorsforindex()?
imagecolorsforindex() [function.imagecolorsforindex]: index couleur 226 sur de la gamme
Le fragment de code correspondant est:
protected function preserveTransparency($img, $resized, $ftype) {
if (($ftype == IMAGETYPE_PNG) || ($ftype == IMAGETYPE_GIF)) {
$tidx = imagecolortransparent($img);
if ($tidx >= 0) {
$transColor = imagecolorsforindex($img, $tidx);
$tidx = imagecolorallocate($resized, $transColor['red'], $transColor['green'], $transColor['blue']);
imagefill($resized, 0, 0, $tidx);
imagecolortransparent($resized, $tidx);
} elseif ($ftype == IMAGETYPE_PNG) {
imagealphablending($resized, false);
imagesavealpha($resized, true);
$transparent = imagecolorallocatealpha($resized, 255, 255, 255, 127);
imagefill($resized, 0, 0, $transparent);
}
}
}
Comment un indice de couleur n'existerait pas si déjà retourné par imagecolortransparent
?
ou ... imagecolorsforindex (img $, imagecolorstotal (img $) - 1); – Johny