4
在做一個補丁的大小調整爲一大束的JPG,PNG和GIF文件,PHP下降死非常意外,出現以下錯誤信息:什麼可能導致imagecolorsforindex()的「顏色索引超出範圍」錯誤?
imagecolorsforindex()[function.imagecolorsforindex]: 色指數226出的範圍
相關的代碼片段:
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);
}
}
}
怎麼可能,如果已經通過imagecolortransparent
返回的顯色指數不存在?
或... imagecolorsforindex($ IMG,imagecolorstotal($ IMG) - 1); – Johny 2018-01-22 15:15:27