Commit 7fd3e0f9 authored by catch's avatar catch

Issue #375062 by cs_shadow, juampy, theunraveler, mondrake, hswong3i, smk-ka:...

Issue #375062 by cs_shadow, juampy, theunraveler, mondrake, hswong3i, smk-ka: Imagecolorsforindex() Color index nnn out of range in GDToolkit.
parent abb88f9f
......@@ -320,17 +320,26 @@ public function createTmp($type, $width, $height) {
$res = imagecreatetruecolor($width, $height);
if ($type == IMAGETYPE_GIF) {
// Grab transparent color index from image resource.
// Find out if a transparent color is set, will return -1 if no
// transparent color has been defined in the image.
$transparent = imagecolortransparent($this->getResource());
if ($transparent >= 0) {
// The original must have a transparent color, allocate to the new image.
$transparent_color = imagecolorsforindex($this->getResource(), $transparent);
$transparent = imagecolorallocate($res, $transparent_color['red'], $transparent_color['green'], $transparent_color['blue']);
// Flood with our new transparent color.
imagefill($res, 0, 0, $transparent);
imagecolortransparent($res, $transparent);
// Find out the number of colors in the image palette. It will be 0 for
// truecolor images.
$palette_size = imagecolorstotal($this->getResource());
if ($palette_size == 0 || $transparent < $palette_size) {
// Set the transparent color in the new resource, either if it is a
// truecolor image or if the transparent color is part of the palette.
// Since the index of the transparency color is a property of the
// image rather than of the palette, it is possible that an image
// could be created with this index set outside the palette size.
$transparent_color = imagecolorsforindex($this->getResource(), $transparent);
$transparent = imagecolorallocate($res, $transparent_color['red'], $transparent_color['green'], $transparent_color['blue']);
// Flood with our new transparent color.
imagefill($res, 0, 0, $transparent);
imagecolortransparent($res, $transparent);
}
}
}
elseif ($type == IMAGETYPE_PNG) {
......
......@@ -274,7 +274,8 @@ function testManipulations() {
$directory = $this->public_files_directory .'/imagetest';
file_prepare_directory($directory, FILE_CREATE_DIRECTORY);
$image->save($directory . '/' . $op . image_type_to_extension($image->getType()));
$file_path = $directory . '/' . $op . image_type_to_extension($image->getType());
$image->save($file_path);
$this->assertTrue($correct_dimensions_real, String::format('Image %file after %action action has proper dimensions.', array('%file' => $file, '%action' => $op)));
$this->assertTrue($correct_dimensions_object, String::format('Image %file object after %action action is reporting the proper height and width values.', array('%file' => $file, '%action' => $op)));
......@@ -307,6 +308,9 @@ function testManipulations() {
$this->assertTrue($correct_colors, String::format('Image %file object after %action action has the correct color placement at corner %corner.', array('%file' => $file, '%action' => $op, '%corner' => $key)));
}
}
// Check that saved image reloads without raising PHP errors.
$image_reloaded = $this->imageFactory->get($file_path);
}
}
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment