diff --git a/core/modules/system/lib/Drupal/system/Plugin/ImageToolkit/GDToolkit.php b/core/modules/system/lib/Drupal/system/Plugin/ImageToolkit/GDToolkit.php index 4aeef32..1a234a4 100644 --- a/core/modules/system/lib/Drupal/system/Plugin/ImageToolkit/GDToolkit.php +++ b/core/modules/system/lib/Drupal/system/Plugin/ImageToolkit/GDToolkit.php @@ -341,7 +341,7 @@ public function createNew(ImageInterface $image, $type, $width, $height, $transp * Converts a hex color into an RGB triplet. * * @param string $hex - * A hexadecimal string representing a color in the '#rrggbbaa' format. + * A hexadecimal string representing a color in the '#rrggbb' notation. * * @return array * An RGB triplet. @@ -377,8 +377,9 @@ public function createTmp($type, $width, $height) { if ($type == IMAGETYPE_GIF) { // Grab transparent color index from image resource. $transparent = imagecolortransparent($this->getResource()); + $palletsize = imagecolorstotal($this->getResource()); - if ($transparent >= 0) { + if ($transparent >= 0 && $transparent < $palletsize) { // 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']); diff --git a/core/modules/system/lib/Drupal/system/Tests/Image/ToolkitGdTest.php b/core/modules/system/lib/Drupal/system/Tests/Image/ToolkitGdTest.php index 387f998..ec97c68 100644 --- a/core/modules/system/lib/Drupal/system/Tests/Image/ToolkitGdTest.php +++ b/core/modules/system/lib/Drupal/system/Tests/Image/ToolkitGdTest.php @@ -15,6 +15,14 @@ * Test the core GD image manipulation functions. */ class ToolkitGdTest extends DrupalUnitTestBase { + + /** + * The image factory service. + * + * @var \Drupal\Core\Image\ImageFactory + */ + protected $imageFactory; + // Colors that are used in testing. protected $black = array(0, 0, 0, 0); protected $red = array(255, 0, 0, 0); @@ -43,6 +51,16 @@ public static function getInfo() { ); } + /** + * {@inheritdoc} + */ + public function setUp() { + parent::setUp(); + + // Set the image factory service. + $this->imageFactory = $this->container->get('image.factory'); + } + protected function checkRequirements() { // GD2 support is available. if (!function_exists('imagegd2')) { @@ -211,11 +229,10 @@ function testManipulations() { ); } - $image_factory = $this->container->get('image.factory')->setToolkitId('gd'); foreach ($files as $file) { foreach ($operations as $op => $values) { // Load up a fresh image. - $image = $image_factory->get(drupal_get_path('module', 'simpletest') . '/files/' . $file); + $image = $this->imageFactory->get(drupal_get_path('module', 'simpletest') . '/files/' . $file); $toolkit = $image->getToolkit(); if (!$image) { $this->fail(String::format('Could not load image %file.', array('%file' => $file))); diff --git a/core/modules/system/lib/Drupal/system/Tests/Image/ToolkitTestBase.php b/core/modules/system/lib/Drupal/system/Tests/Image/ToolkitTestBase.php index f9a4bc3..74caafd 100644 --- a/core/modules/system/lib/Drupal/system/Tests/Image/ToolkitTestBase.php +++ b/core/modules/system/lib/Drupal/system/Tests/Image/ToolkitTestBase.php @@ -30,6 +30,13 @@ protected $file; /** + * The image factory service. + * + * @var \Drupal\Core\Image\ImageFactory + */ + protected $imageFactory; + + /** * The image object for the test file. * * @var \Drupal\Core\Image\ImageInterface @@ -39,6 +46,9 @@ function setUp() { parent::setUp(); + // Set the image factory service. + $this->imageFactory = $this->container->get('image.factory'); + // Pick a file for testing. $file = current($this->drupalGetTestFiles('image')); $this->file = $file->uri; @@ -57,9 +67,7 @@ function setUp() { * The image object. */ protected function getImage() { - $image = $this->container->get('image.factory') - ->setToolkitId('test') - ->get($this->file); + $image = $this->imageFactory->get($this->file, 'test'); $this->assertTrue($image->isExisting(), 'Image was loaded.'); return $image; }