Что могло вызвать ошибку «цветовой индекс вне допустимого диапазона» для imagecolorsforindex ()?

При изменении размера патча для большого количества файлов JPG, PNG и GIF PHP неожиданно падает мертвым со следующим сообщением об ошибке:

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 ?

5
задан Saul 8 October 2010 в 22:28
поделиться