View source
<?php
namespace Drupal\Tests\image_effects\Functional\Effect;
use Drupal\Tests\image_effects\Functional\ImageEffectsTestBase;
class ImagemagickArgumentsTest extends ImageEffectsTestBase {
public function providerToolkits() {
$toolkits = parent::providerToolkits();
unset($toolkits['GD']);
return $toolkits;
}
public function testImagemagickArgumentsEffect($toolkit_id, $toolkit_config, array $toolkit_settings) {
$this
->changeToolkit($toolkit_id, $toolkit_config, $toolkit_settings);
$original_uri = $this
->getTestImageCopyUri('/tests/images/portrait-painting.jpg', 'image_effects');
$derivative_uri = $this->testImageStyle
->buildUri($original_uri);
$exif = @exif_read_data(\Drupal::service('file_system')
->realpath($original_uri));
$this
->assertEquals(8, isset($exif['Orientation']) ? $exif['Orientation'] : NULL);
$effect = [
'id' => 'image_effects_imagemagick_arguments',
'data' => [
'command_line' => '-strip',
'dimensions_method' => 'keep',
],
];
$uuid = $this
->addEffectToTestStyle($effect);
$image = $this->imageFactory
->get($original_uri);
$derivative_url = file_url_transform_relative($this->testImageStyle
->buildUrl($original_uri));
$variables = [
'#theme' => 'image_style',
'#style_name' => 'image_effects_test',
'#uri' => $original_uri,
'#width' => $image
->getWidth(),
'#height' => $image
->getHeight(),
];
$this
->assertRegExp("/\\<img src=\"" . preg_quote($derivative_url, '/') . "\" width=\"640\" height=\"480\" alt=\"\" .*class=\"image\\-style\\-image\\-effects\\-test\" \\/\\>/", $this
->getImageTag($variables));
$this->testImageStyle
->createDerivative($original_uri, $derivative_uri);
$image = $this->imageFactory
->get($derivative_uri);
$this
->assertEquals(640, $image
->getWidth());
$this
->assertEquals(480, $image
->getHeight());
$exif = @exif_read_data(\Drupal::service('file_system')
->realpath($derivative_uri));
$this
->assertEquals(NULL, isset($exif['Orientation']) ? $exif['Orientation'] : NULL);
$this
->removeEffectFromTestStyle($uuid);
$effect = [
'id' => 'image_effects_imagemagick_arguments',
'data' => [
'command_line' => '-strip',
'dimensions_method' => 'strip',
],
];
$uuid = $this
->addEffectToTestStyle($effect);
$image = $this->imageFactory
->get($original_uri);
$derivative_url = file_url_transform_relative($this->testImageStyle
->buildUrl($original_uri));
$variables = [
'#theme' => 'image_style',
'#style_name' => 'image_effects_test',
'#uri' => $original_uri,
'#width' => $image
->getWidth(),
'#height' => $image
->getHeight(),
];
$this
->assertRegExp("/\\<img src=\"" . preg_quote($derivative_url, '/') . "\" alt=\"\" .*class=\"image\\-style\\-image\\-effects\\-test\" \\/\\>/", $this
->getImageTag($variables));
$this->testImageStyle
->createDerivative($original_uri, $derivative_uri);
$image = $this->imageFactory
->get($derivative_uri);
$this
->assertEquals(640, $image
->getWidth());
$this
->assertEquals(480, $image
->getHeight());
$this
->removeEffectFromTestStyle($uuid);
$effect = [
'id' => 'image_effects_imagemagick_arguments',
'data' => [
'command_line' => '-strip',
'dimensions_method' => 'value',
'dimensions][width][c0][c1][value' => 50,
'dimensions][width][c0][c1][uom' => 'perc',
'dimensions][height][c0][c1][value' => 25,
'dimensions][height][c0][c1][uom' => 'perc',
],
];
$uuid = $this
->addEffectToTestStyle($effect);
$image = $this->imageFactory
->get($original_uri);
$derivative_url = file_url_transform_relative($this->testImageStyle
->buildUrl($original_uri));
$variables = [
'#theme' => 'image_style',
'#style_name' => 'image_effects_test',
'#uri' => $original_uri,
'#width' => $image
->getWidth(),
'#height' => $image
->getHeight(),
];
$this
->assertRegExp("/\\<img src=\"" . preg_quote($derivative_url, '/') . "\" width=\"320\" height=\"120\" alt=\"\" .*class=\"image\\-style\\-image\\-effects\\-test\" \\/\\>/", $this
->getImageTag($variables));
$this
->removeEffectFromTestStyle($uuid);
$effect = [
'id' => 'image_effects_imagemagick_arguments',
'data' => [
'command_line' => '-strip',
'dimensions_method' => 'value',
'dimensions][width][c0][c1][value' => 64,
'dimensions][width][c0][c1][uom' => 'px',
'dimensions][height][c0][c1][value' => 48,
'dimensions][height][c0][c1][uom' => 'px',
],
];
$uuid = $this
->addEffectToTestStyle($effect);
$image = $this->imageFactory
->get($original_uri);
$derivative_url = file_url_transform_relative($this->testImageStyle
->buildUrl($original_uri));
$variables = [
'#theme' => 'image_style',
'#style_name' => 'image_effects_test',
'#uri' => $original_uri,
'#width' => $image
->getWidth(),
'#height' => $image
->getHeight(),
];
$this
->assertRegExp("/\\<img src=\"" . preg_quote($derivative_url, '/') . "\" width=\"64\" height=\"48\" alt=\"\" .*class=\"image\\-style\\-image\\-effects\\-test\" \\/\\>/", $this
->getImageTag($variables));
$this
->removeEffectFromTestStyle($uuid);
}
}