Commit 12db22c4 authored by alexpott's avatar alexpott
Browse files

Issue #2485761 by mondrake, c470ip, jhedstrom: Support for transparent GIFs broken

parent 7b4baac5
......@@ -346,6 +346,7 @@ function testImageFieldDefaultImage() {
$alt = $this->randomString(512);
$title = $this->randomString(1024);
$edit = array(
// Get the path of the 'image-test.png' file.
'files[settings_default_image_uuid]' => drupal_realpath($images[0]->uri),
'settings[default_image][alt]' => $alt,
'settings[default_image][title]' => $title,
......@@ -378,7 +379,8 @@ function testImageFieldDefaultImage() {
// Create alt text for the image.
$alt = $this->randomMachineName();
$nid = $this->uploadNodeImage($images[1], $field_name, 'article', $alt);
// Upload the 'image-test.gif' file.
$nid = $this->uploadNodeImage($images[2], $field_name, 'article', $alt);
$node_storage->resetCache(array($nid));
$node = $node_storage->load($nid);
$file = $node->{$field_name}->entity;
......@@ -413,7 +415,8 @@ function testImageFieldDefaultImage() {
$this->createImageField($private_field_name, 'article', array('uri_scheme' => 'private'));
// Add a default image to the new field.
$edit = array(
'files[settings_default_image_uuid]' => drupal_realpath($images[1]->uri),
// Get the path of the 'image-test.gif' file.
'files[settings_default_image_uuid]' => drupal_realpath($images[2]->uri),
'settings[default_image][alt]' => $alt,
'settings[default_image][title]' => $title,
);
......
......@@ -107,12 +107,12 @@ protected function execute(array $arguments) {
case IMAGETYPE_GIF:
if (empty($arguments['transparent_color'])) {
// No transparency color specified, fill white.
$fill_color = imagecolorallocate($res, 255, 255, 255);
// No transparency color specified, fill white transparent.
$fill_color = imagecolorallocatealpha($res, 255, 255, 255, 127);
}
else {
$fill_rgb = Color::hexToRgb($arguments['transparent_color']);
$fill_color = imagecolorallocate($res, $fill_rgb['red'], $fill_rgb['green'], $fill_rgb['blue']);
$fill_color = imagecolorallocatealpha($res, $fill_rgb['red'], $fill_rgb['green'], $fill_rgb['blue'], 127);
imagecolortransparent($res, $fill_color);
}
imagefill($res, 0, 0, $fill_color);
......
......@@ -271,13 +271,6 @@ function testManipulations() {
$image_truecolor = imageistruecolor($toolkit->getResource());
$this->assertTrue($image_truecolor, SafeMarkup::format('Image %file after load is a truecolor image.', array('%file' => $file)));
if ($image->getToolkit()->getType() == IMAGETYPE_GIF) {
if ($op == 'desaturate') {
// Transparent GIFs and the imagefilter function don't work together.
$values['corners'][3][3] = 0;
}
}
// Store the original GD resource.
$old_res = $toolkit->getResource();
......@@ -330,11 +323,21 @@ function testManipulations() {
if ($image->getToolkit()->getType() != IMAGETYPE_JPEG && $image_original_type != IMAGETYPE_JPEG) {
// Now check each of the corners to ensure color correctness.
foreach ($values['corners'] as $key => $corner) {
// The test gif that does not have transparency has yellow where the
// others have transparent.
if ($file === 'image-test-no-transparency.gif' && $corner === $this->transparent) {
// The test gif that does not have transparency color set is a
// special case.
if ($file === 'image-test-no-transparency.gif') {
if ($op == 'desaturate') {
// For desaturating, keep the expected color from the test
// data, but set alpha channel to fully opaque.
$corner[3] = 0;
}
elseif ($corner === $this->transparent) {
// Set expected pixel to yellow where the others have
// transparent.
$corner = $this->yellow;
}
}
// Get the location of the corner.
switch ($key) {
case 0:
......@@ -436,9 +439,46 @@ public function testResourceDestruction() {
}
/**
* Tests loading an image whose transparent color index is out of range.
* Tests for GIF images with transparency.
*/
function testTransparentColorOutOfRange() {
function testGifTransparentImages() {
// Prepare a directory for test file results.
$directory = $this->publicFilesDirectory .'/imagetest';
file_prepare_directory($directory, FILE_CREATE_DIRECTORY);
// Test loading an indexed GIF image with transparent color set.
// Color at top-right pixel should be fully transparent.
$file = 'image-test-transparent-indexed.gif';
$image = $this->imageFactory->get(drupal_get_path('module', 'simpletest') . '/files/' . $file);
$resource = $image->getToolkit()->getResource();
$color_index = imagecolorat($resource, $image->getWidth() - 1, 0);
$color = array_values(imagecolorsforindex($resource, $color_index));
$this->assertEqual($this->rotateTransparent, $color, "Image {$file} after load has full transparent color at corner 1.");
// Test deliberately creating a GIF image with no transparent color set.
// Color at top-right pixel should be fully transparent while in memory,
// fully opaque after flushing image to file.
$file = 'image-test-no-transparent-color-set.gif';
$file_path = $directory . '/' . $file ;
// Create image.
$image = $this->imageFactory->get();
$image->createNew(50, 20, 'gif', NULL);
$resource = $image->getToolkit()->getResource();
$color_index = imagecolorat($resource, $image->getWidth() - 1, 0);
$color = array_values(imagecolorsforindex($resource, $color_index));
$this->assertEqual($this->rotateTransparent, $color, "New GIF image with no transparent color set after creation has full transparent color at corner 1.");
// Save image.
$this->assertTrue($image->save($file_path), "New GIF image {$file} was saved.");
// Reload image.
$image_reloaded = $this->imageFactory->get($file_path);
$resource = $image_reloaded->getToolkit()->getResource();
$color_index = imagecolorat($resource, $image_reloaded->getWidth() - 1, 0);
$color = array_values(imagecolorsforindex($resource, $color_index));
// Check explicitly for alpha == 0 as the rest of the color has been
// compressed and may have slight difference from full white.
$this->assertEqual(0, $color[3], "New GIF image {$file} after reload has no transparent color at corner 1.");
// Test loading an image whose transparent color index is out of range.
// This image was generated by taking an initial image with a palette size
// of 6 colors, and setting the transparent color index to 6 (one higher
// than the largest allowed index), as follows:
......
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