You are here

public function EventSubscriberTest::testGifCoalesce in ImageMagick 8.3

Test coalescence of Animated GIFs.

@dataProvider providerToolkitConfiguration

Parameters

string $toolkit_id: The id of the toolkit to set up.

string $toolkit_config: The config object of the toolkit to set up.

array $toolkit_settings: The settings of the toolkit to set up.

File

tests/src/Functional/EventSubscriberTest.php, line 132

Class

EventSubscriberTest
Tests for ImagemagickEventSubscriber.

Namespace

Drupal\Tests\imagemagick\Functional

Code

public function testGifCoalesce(string $toolkit_id, string $toolkit_config, array $toolkit_settings) : void {
  $this
    ->setUpToolkit($toolkit_id, $toolkit_config, $toolkit_settings);
  $this
    ->prepareImageFileHandling();
  $image_uri = drupal_get_path('module', 'imagemagick') . '/misc/test-multi-frame.gif';

  // By default, no coalesce of animated GIFs.
  $image = $this->imageFactory
    ->get($image_uri);
  $image
    ->getToolkit()
    ->arguments()
    ->add("-resize 100x75!");
  $image
    ->save("public://imagetest/coalesced.gif");
  $expected = "-resize 100x75! -quality 100";
  $this
    ->assertSame($expected, $image
    ->getToolkit()
    ->arguments()
    ->toString(ImagemagickExecArguments::POST_SOURCE));

  // Change the Advanced Coalesce setting, '-coalesce' must now be included
  // in the command line.
  \Drupal::configFactory()
    ->getEditable('imagemagick.settings')
    ->set('advanced.coalesce', TRUE)
    ->save();
  $image = $this->imageFactory
    ->get($image_uri);
  $image
    ->getToolkit()
    ->arguments()
    ->add("-resize 100x75!");
  $image
    ->save("public://imagetest/coalesced.gif");
  $expected = "-coalesce -resize 100x75! -quality 100";
  $this
    ->assertSame($expected, $image
    ->getToolkit()
    ->arguments()
    ->toString(ImagemagickExecArguments::POST_SOURCE));

  // Single frame GIF should not be coalesceable.
  $image = $this->imageFactory
    ->get("public://image-test.gif");
  $image
    ->getToolkit()
    ->arguments()
    ->add("-resize 100x75!");
  $image
    ->save("public://imagetest/coalesced.gif");
  $expected = "-resize 100x75! -quality 100";
  $this
    ->assertSame($expected, $image
    ->getToolkit()
    ->arguments()
    ->toString(ImagemagickExecArguments::POST_SOURCE));

  // PNG should not be coalesceable.
  $image = $this->imageFactory
    ->get("public://image-test.png");
  $image
    ->getToolkit()
    ->arguments()
    ->add("-resize 100x75!");
  $image
    ->save("public://imagetest/coalesced.png");
  $expected = "-resize 100x75! -quality 100";
  $this
    ->assertSame($expected, $image
    ->getToolkit()
    ->arguments()
    ->toString(ImagemagickExecArguments::POST_SOURCE));
}