diff --git a/src/FocalPointEffectBase.php b/src/FocalPointEffectBase.php index 4184a3b..de66d28 100644 --- a/src/FocalPointEffectBase.php +++ b/src/FocalPointEffectBase.php @@ -33,11 +33,11 @@ abstract class FocalPointEffectBase extends ResizeImageEffect implements Contain protected $focalPointConfig; /** - * The original image before any effects are applied. + * The original image dimensions before any effects are applied. * - * @var \Drupal\Core\Image\ImageInterface + * @var array */ - protected $originalImage; + protected $originalImageSize; /** * Focal point manager object. @@ -104,7 +104,7 @@ abstract class FocalPointEffectBase extends ResizeImageEffect implements Contain */ public function applyEffect(ImageInterface $image) { // @todo: Get the original image in case there are multiple scale/crop effects? - $this->originalImage = clone $image; + $this->setOriginalImageSize(clone $image); return TRUE; } @@ -182,7 +182,9 @@ abstract class FocalPointEffectBase extends ResizeImageEffect implements Contain ]); } - $anchor = $this->calculateAnchor($image, $crop); + // Get the top-left anchor position of the crop area. + $anchor = $this->getAnchor($image, $crop); + if (!$image->crop($anchor['x'], $anchor['y'], $this->configuration['width'], $this->configuration['height'])) { $this->logger->error( 'Focal point scale and crop failed while scaling and cropping using the %toolkit toolkit on %path (%mimetype, %dimensions, anchor: %anchor)', @@ -201,12 +203,7 @@ abstract class FocalPointEffectBase extends ResizeImageEffect implements Contain } /** - * Calculate the top left coordinates of crop rectangle. - * - * This is based on Crop's anchor function with additional logic to ensure - * that crop area doesn't fall outside of the original image. Note that the - * image modules crop effect expects the top left coordinate of the crop - * rectangle. + * Get the top-left anchor position of the crop area. * * @param \Drupal\Core\Image\ImageInterface $image * Image object representing original image. @@ -215,28 +212,57 @@ abstract class FocalPointEffectBase extends ResizeImageEffect implements Contain * * @return array * Array with two keys (x, y) and anchor coordinates as values. + * + * @codeCoverageIgnore */ - protected function calculateAnchor(ImageInterface $image, CropInterface $crop) { - $crop_size = $crop->size(); - $image_size = [ + public function getAnchor(ImageInterface $image, CropInterface $crop) { + $original_focal_point = $this->getOriginalFocalPoint($crop, $this->focalPointManager); + $focal_point = $this->transformFocalPoint($image, $original_focal_point); + + return $this->calculateAnchor($focal_point, $image, $crop); + } + + /** + * Set original image size. + * + * @param \Drupal\Core\Image\ImageInterface $image + * + * @todo: change args to $width & $height + */ + public function setOriginalImageSize(ImageInterface $image) { + $this->originalImageSize = [ 'width' => $image->getWidth(), - 'height' => $image->getHeight(), + 'height' => $image->getHeight() ]; + } - // Check if we are generating a preview image. If so get the focal point - // from the query parameter, otherwise use the crop position. - $preview_value = $this->getPreviewValue(); - if (is_null($preview_value)) { - $focal_point = $crop->position(); - } - else { - // @todo: should we check that preview_value is valid here? If its invalid it gets converted to 0,0. - list($x, $y) = explode('x', $preview_value); - $focal_point = $this->focalPointManager->relativeToAbsolute($x, $y, $this->originalImage->getWidth(), $this->originalImage->getHeight()); - } + /** + * Get original image. + * + * @return array + */ + public function getOriginalImageSize() { + // @todo: check if originalImageSize exists and if not throw an exception. + return $this->originalImageSize; + } - $focal_point['x'] = (int) round($focal_point['x'] / $this->originalImage->getWidth() * $image_size['width']); - $focal_point['y'] = (int) round($focal_point['y'] / $this->originalImage->getHeight() * $image_size['height']); + /** + * Calculate the top left coordinates of crop rectangle. + * + * This is based on Crop's anchor function with additional logic to ensure + * that crop area doesn't fall outside of the original image. Note that the + * image modules crop effect expects the top left coordinate of the crop + * rectangle + * + * @param $focal_point + * @param \Drupal\Core\Image\ImageInterface $image + * @param \Drupal\crop\CropInterface $crop + * + * @return array + * An array with the keys 'x' and 'y'. + */ + protected function calculateAnchor($focal_point, ImageInterface $image, CropInterface $crop) { + $crop_size = $crop->size(); // The anchor must be the top-left coordinate of the crop area but the focal // point is expressed as the center coordinates of the crop area. @@ -245,33 +271,99 @@ abstract class FocalPointEffectBase extends ResizeImageEffect implements Contain 'y' => (int) ($focal_point['y'] - ($crop_size['height'] / 2)), ]; + $anchor = $this->constrainCropArea($anchor, $image, $crop); + + return $anchor; + } + + /** + * Given the top-left anchor (in pixels), the crop size and the image size, + * reposition the anchor to ensure the crop area does not exceed the bounds of + * the image. + * + * @param array $anchor + * An array with the keys 'x' and 'y'. Values are in pixels representing the + * top left corner of the of the crop area relative to the image. + * @param \Drupal\Core\Image\ImageInterface $image + * The image to which the crop area must be constrained. + * @param \Drupal\crop\CropInterface $crop + * + * + * @return array + * An array with the keys 'x' and 'y'. + */ + protected function constrainCropArea($anchor, ImageInterface $image, CropInterface $crop) { + $image_size = [ + 'width' => $image->getWidth(), + 'height' => $image->getHeight(), + ]; + $crop_size = $crop->size(); + // Ensure that the crop area doesn't fall off the bottom right of the image. - $anchor['x'] = $anchor['x'] + $crop_size['width'] <= $image_size['width'] ? $anchor['x'] : $image_size['width'] - $crop_size['width']; - $anchor['y'] = $anchor['y'] + $crop_size['height'] <= $image_size['height'] ? $anchor['y'] : $image_size['height'] - $crop_size['height']; + $anchor = [ + 'x' => $anchor['x'] + $crop_size['width'] <= $image_size['width'] ? $anchor['x'] : $image_size['width'] - $crop_size['width'], + 'y' => $anchor['y'] = $anchor['y'] + $crop_size['height'] <= $image_size['height'] ? $anchor['y'] : $image_size['height'] - $crop_size['height'], + ]; // Ensure that the crop area doesn't fall off the top left of the image. - $anchor['x'] = max(0, $anchor['x']); - $anchor['y'] = max(0, $anchor['y']); + $anchor = [ + 'x' => max(0, $anchor['x']), + 'y' => max(0, $anchor['y']), + ]; return $anchor; } /** - * Set original image. + * Returns the focal point value (in pixels) relative to the original image. * - * @param \Drupal\Core\Image\ImageInterface $image + * @param \Drupal\crop\CropInterface $crop + * @param \Drupal\focal_point\FocalPointManager $focal_point_manager + * + * @return array + * An array with the keys 'x' and 'y'. Values are in pixels. */ - public function setOriginalImage(ImageInterface $image) { - $this->originalImage = $image; + protected function getOriginalFocalPoint(CropInterface $crop, FocalPointManager $focal_point_manager) { + $focal_point = $crop->position(); + + // Check if we are generating a preview image. If so get the focal point + // from the query parameter, otherwise use the crop position. + $preview_value = $this->getPreviewValue(); + if (!is_null($preview_value)) { + // @todo: should we check that preview_value is valid here? If it's invalid it gets converted to 0,0. + $original_image_size = $this->getOriginalImageSize(); + list($x, $y) = explode('x', $preview_value); + $focal_point = $focal_point_manager->relativeToAbsolute($x, $y, $original_image_size['width'], $original_image_size['height']); + } + + return $focal_point; } /** - * Get original image. + * Returns the focal point value (in pixels) relative to the provided image. + * + * @param \Drupal\Core\Image\ImageInterface $image + * Image object that the focal point must be applied to. + * @param array $original_focal_point + * An array with keys 'x' and 'y' which represent the focal point in pixels + * relative to the original image. * - * @return \Drupal\Core\Image\ImageInterface + * @return array + * An array with the keys 'x' and 'y'. Values are in pixels. */ - public function getOriginalImage() { - return $this->originalImage; + protected function transformFocalPoint($image, $original_focal_point) { + $image_size = [ + 'width' => $image->getWidth(), + 'height' => $image->getHeight(), + ]; + $original_image_size = $this->getOriginalImageSize(); + + $relative_focal_point = [ + 'x' => (int) round($original_focal_point['x'] / $original_image_size['width'] * $image_size['width']), + 'y' => (int) round($original_focal_point['y'] / $original_image_size['height'] * $image_size['height']) + ]; + + return $relative_focal_point; } /** diff --git a/src/Plugin/ImageEffect/FocalPointScaleAndCropImageEffect.php b/src/Plugin/ImageEffect/FocalPointScaleAndCropImageEffect.php index 0d93815..0de1220 100644 --- a/src/Plugin/ImageEffect/FocalPointScaleAndCropImageEffect.php +++ b/src/Plugin/ImageEffect/FocalPointScaleAndCropImageEffect.php @@ -24,7 +24,8 @@ class FocalPointScaleAndCropImageEffect extends FocalPointEffectBase { parent::applyEffect($image); // First, attempt to resize the image. - $resize_data = self::calculateResizeData($this->originalImage->getWidth(), $this->originalImage->getHeight(), $this->configuration['width'], $this->configuration['height']); + $originalDimensions = $this->getOriginalImageSize(); + $resize_data = self::calculateResizeData($originalDimensions['width'], $originalDimensions['height'], $this->configuration['width'], $this->configuration['height']); if (!$image->resize($resize_data['width'], $resize_data['height'])) { $this->logger->error( 'Focal point scale and crop failed while resizing using the %toolkit toolkit on %path (%mimetype, %dimensions)', diff --git a/tests/src/Unit/Effects/FocalPointEffectsTest.php b/tests/src/Unit/Effects/FocalPointEffectsTest.php index 4c2e498..b62738b 100644 --- a/tests/src/Unit/Effects/FocalPointEffectsTest.php +++ b/tests/src/Unit/Effects/FocalPointEffectsTest.php @@ -3,7 +3,6 @@ namespace Drupal\Tests\focal_point\Unit\Effects; use Drupal\Core\Config\ImmutableConfig; -use Drupal\Core\Image\ImageInterface; use Drupal\crop\CropInterface; use Drupal\crop\CropStorageInterface; use Drupal\focal_point\Plugin\ImageEffect\FocalPointCropImageEffect; @@ -32,6 +31,8 @@ class FocalPointEffectsTest extends FocalPointUnitTestCase { * @covers ::__construct */ public function testEffectConstructor() { + // We can't use $this->getTestEffect here because the attributes tested + // below won't match. $logger = $this->prophesize(LoggerInterface::class); $crop_storage = $this->prophesize(CropStorageInterface::class); $focal_point_config = $this->prophesize(ImmutableConfig::class); @@ -69,65 +70,144 @@ class FocalPointEffectsTest extends FocalPointUnitTestCase { } /** - * @covers ::setOriginalImage - * @covers ::getOriginalImage + * @covers ::setOriginalImageSize + * @covers ::getOriginalImageSize */ - public function testSetGetOriginalImage() { - $logger = $this->prophesize(LoggerInterface::class); - $crop_storage = $this->prophesize(CropStorageInterface::class); - $immutable_config = $this->prophesize(ImmutableConfig::class); - $request = $this->prophesize(Request::class); + public function testSetGetOriginalImageSize() { + $original_image_dimensions = ['width' => 131, 'height' => 313]; + $original_image = $this->getTestImage($original_image_dimensions['width'], $original_image_dimensions['height']); - $original_image = $this->prophesize(ImageInterface::class); - $original_image = $original_image->reveal(); + $effect = $this->getTestEffect($original_image); + + $this->assertArrayEquals($original_image_dimensions, $effect->getOriginalImageSize()); + } + + /** + * @covers ::transformFocalPoint + * + * @dataProvider transformFocalPointProvider + */ + public function testTransformFocalPoint($image_dimensions, $original_image_dimensions, $original_focal_point, $expected_focal_point) { + $image = $this->getTestImage($image_dimensions['width'], $image_dimensions['height']); + $original_image = $this->getTestImage($original_image_dimensions['width'], $original_image_dimensions['height']); - $effect = new FocalPointCropImageEffect([], 'plugin_id', [], $logger->reveal(), $this->focalPointManager, $crop_storage->reveal(), $immutable_config->reveal(), $request->reveal()); - $effect->setOriginalImage($original_image); + // Use reflection to test a private/protected method. + $effect = $this->getTestEffect($original_image); + $effect_reflection = new \ReflectionClass(TestFocalPointEffectBase::class); + $method = $effect_reflection->getMethod('transformFocalPoint'); + $method->setAccessible(TRUE); - $this->assertEquals($original_image, $effect->getOriginalImage()); + $this->assertSame($expected_focal_point, $method->invokeArgs($effect, [$image, $original_focal_point])); } /** - * @covers ::calculateAnchor + * Data provider for testTransformFocalPoint(). * - * @dataProvider calculateAnchorProvider + * @see FocalPointEffectsTest::testTransformFocalPoint() */ - public function testCalculateAnchor($original_image_size, $resized_image_size, $cropped_image_size, $position, $expected_anchor) { + public function transformFocalPointProvider() { + $data = []; + + $data['no_scale'] = [['width' => 800, 'height' => 600], ['width' => 800, 'height' => 600], ['x' => 300, 'y' => 400], ['x' => 300, 'y' => 400]]; + $data['scaled_down'] = [['width' => 800, 'height' => 600], ['width' => 2500, 'height' => 4000], ['x' => 100, 'y' => 100], ['x' => 32, 'y' => 15]]; + $data['scaled_up'] = [['width' => 800, 'height' => 600], ['width' => 460, 'height' => 313], ['x' => 500, 'y' => 900], ['x' => 870, 'y' => 1725]]; + $data['different_orientation'] = [['width' => 350, 'height' => 200], ['width' => 5000, 'height' => 4000], ['x' => 2100, 'y' => 313], ['x' => 147, 'y' => 16]]; + + return $data; + } + + /** + * @covers ::getOriginalFocalPoint + */ + public function testGetOriginalFocalPoint() { + $original_image = $this->getTestImage(50, 50); + + // Create a instance of TestFocalPointEffectBase since we need to override + // the getPreviewValue method. $logger = $this->prophesize(LoggerInterface::class); $crop_storage = $this->prophesize(CropStorageInterface::class); $immutable_config = $this->prophesize(ImmutableConfig::class); $request = $this->prophesize(Request::class); - $original_image = $this->prophesize(ImageInterface::class); - $original_image->getWidth()->willReturn($original_image_size['width']); - $original_image->getHeight()->willReturn($original_image_size['height']); + $effect = new TestFocalPointEffectBase([], 'plugin_id', [], $logger->reveal(), $this->focalPointManager, $crop_storage->reveal(), $immutable_config->reveal(), $request->reveal()); + $effect->setOriginalImageSize($original_image); - $image = $this->prophesize(ImageInterface::class); - $image->getWidth()->willReturn($resized_image_size['width']); - $image->getHeight()->willReturn($resized_image_size['height']); + // Use reflection to test a private/protected method. + $effect_reflection = new \ReflectionClass(TestFocalPointEffectBase::class); + $method = $effect_reflection->getMethod('getOriginalFocalPoint'); + $method->setAccessible(TRUE); + // Mock crop object + $expected = ['x' => 313, 'y' => 404]; $crop = $this->prophesize(CropInterface::class); - $crop->position()->willReturn([ - 'x' => $position['x'], - 'y' => $position['y'], - ]); - $crop->size()->willReturn([ - 'width' => $cropped_image_size['width'], - 'height' => $cropped_image_size['height'], - ]); + $crop->position()->willReturn($expected); + + // Non-preview + $this->assertSame($expected, $method->invokeArgs($effect, [$crop->reveal(), $this->focalPointManager])); + + // Preview test. + $query_string = '500x250'; + $expected = ['x' => 250, 'y' => 125]; + $effect->setTestingPreview($query_string); + $this->assertSame($expected, $method->invokeArgs($effect, [$crop->reveal(), $this->focalPointManager])); + } + + /** + * @covers ::constrainCropArea + * + * @dataProvider constrainCropAreaProvider + */ + public function testConstrainCropArea($anchor, $image_size, $crop_size, $expected) { + $image = $this->getTestImage($image_size['width'], $image_size['height']); + $crop = $this->prophesize(CropInterface::class); + $crop->size()->willReturn($crop_size); // Use reflection to test a private/protected method. - $effect = new TestFocalPointEffectBase([], 'plugin_id', [], $logger->reveal(), $this->focalPointManager, $crop_storage->reveal(), $immutable_config->reveal(), $request->reveal()); - $effect->setOriginalImage($original_image->reveal()); + $effect = $this->getTestEffect(); $effect_reflection = new \ReflectionClass(TestFocalPointEffectBase::class); - $method = $effect_reflection->getMethod('calculateAnchor'); + $method = $effect_reflection->getMethod('constrainCropArea'); $method->setAccessible(TRUE); - $this->assertSame($expected_anchor, $method->invokeArgs($effect, [$image->reveal(), $crop->reveal(), $original_image_size])); + $this->assertSame($expected, $method->invokeArgs($effect, [$anchor, $image, $crop->reveal()])); + } + + /** + * Data provider for testConstrainCropArea(). + * + * @see FocalPointEffectsTest::testConstrainCropArea() + */ + public function constrainCropAreaProvider() { + $data = []; + + $data['constrained-top-left'] = [['x' => -10, 'y' => -10], ['width' => 1000, 'height' => 1000], ['width' => 100, 'height' => 100], ['x' => 0, 'y' => 0]]; + $data['constrained-top-center'] = [['x' => 10, 'y' => -10], ['width' => 1000, 'height' => 1000], ['width' => 100, 'height' => 100], ['x' => 10, 'y' => 0]]; + $data['constrained-top-right'] = [['x' => 2000, 'y' => -10], ['width' => 1000, 'height' => 1000], ['width' => 100, 'height' => 100], ['x' => 900, 'y' => 0]]; + $data['constrained-center-left'] = [['x' => -10, 'y' => 313], ['width' => 1000, 'height' => 1000], ['width' => 100, 'height' => 100], ['x' => 0, 'y' => 313]]; + $data['unconstrained'] = [['x' => 500, 'y' => 500], ['width' => 1000, 'height' => 1000], ['width' => 100, 'height' => 100], ['x' => 500, 'y' => 500]]; + $data['constrained-center-right'] = [['x' => 3000, 'y' => 313], ['width' => 1000, 'height' => 1000], ['width' => 100, 'height' => 100], ['x' => 900, 'y' => 313]]; + $data['constrained-bottom-left'] = [['x' => -10, 'y' => 2000], ['width' => 1000, 'height' => 1000], ['width' => 100, 'height' => 100], ['x' => 0, 'y' => 900]]; + $data['constrained-bottom-center'] = [['x' => 313, 'y' => 2000], ['width' => 1000, 'height' => 1000], ['width' => 100, 'height' => 100], ['x' => 313, 'y' => 900]]; + $data['constrained-bottom-right'] = [['x' => 3000, 'y' => 2000], ['width' => 1000, 'height' => 1000], ['width' => 100, 'height' => 100], ['x' => 900, 'y' => 900]]; + + return $data; + } - $effect->setTestingPreview(TRUE); - $expected_anchor = ['x' => 0, 'y' => 0]; - $this->assertSame($expected_anchor, $method->invokeArgs($effect, [$image->reveal(), $crop->reveal(), $original_image_size])); + /** + * @covers ::calculateAnchor + * + * @dataProvider calculateAnchorProvider + */ + public function testCalculateAnchor($focal_point, $image_size, $crop_size, $expected) { + $image = $this->getTestImage($image_size['width'], $image_size['height']); + $crop = $this->prophesize(CropInterface::class); + $crop->size()->willReturn($crop_size); + + // Use reflection to test a private/protected method. + $effect = $this->getTestEffect(); + $effect_reflection = new \ReflectionClass(TestFocalPointEffectBase::class); + $method = $effect_reflection->getMethod('calculateAnchor'); + $method->setAccessible(TRUE); + $this->assertSame($expected, $method->invokeArgs($effect, [$focal_point, $image, $crop->reveal()])); } /** @@ -140,138 +220,129 @@ class FocalPointEffectsTest extends FocalPointUnitTestCase { // Square image with square crop. $original_image_size = ['width' => 2000, 'height' => 2000]; - $resized_image_size = ['width' => 1000, 'height' => 1000]; $cropped_image_size = ['width' => 1000, 'height' => 1000]; list($top, $left, $center, $bottom, $right) = [100, 100, 1000, 1900, 1900]; - $data['square_image_with_square_crop__top_left'] = [$original_image_size, $resized_image_size, $cropped_image_size, ['x' => $left, 'y' => $top], ['x' => 0, 'y' => 0]]; - $data['square_image_with_square_crop__top_center'] = [$original_image_size, $resized_image_size, $cropped_image_size, ['x' => $center, 'y' => $top], ['x' => 0, 'y' => 0]]; - $data['square_image_with_square_crop__top_right'] = [$original_image_size, $resized_image_size, $cropped_image_size, ['x' => $right, 'y' => $top], ['x' => 0, 'y' => 0]]; - $data['square_image_with_square_crop__center_left'] = [$original_image_size, $resized_image_size, $cropped_image_size, ['x' => $left, 'y' => $center], ['x' => 0, 'y' => 0]]; - $data['square_image_with_square_crop__center_center'] = [$original_image_size, $resized_image_size, $cropped_image_size, ['x' => $center, 'y' => $center], ['x' => 0, 'y' => 0]]; - $data['square_image_with_square_crop__center_right'] = [$original_image_size, $resized_image_size, $cropped_image_size, ['x' => $right, 'y' => $center], ['x' => 0, 'y' => 0]]; - $data['square_image_with_square_crop__bottom_left'] = [$original_image_size, $resized_image_size, $cropped_image_size, ['x' => $left, 'y' => $bottom], ['x' => 0, 'y' => 0]]; - $data['square_image_with_square_crop__bottom_center'] = [$original_image_size, $resized_image_size, $cropped_image_size, ['x' => $center, 'y' => $bottom], ['x' => 0, 'y' => 0]]; - $data['square_image_with_square_crop__bottom_right'] = [$original_image_size, $resized_image_size, $cropped_image_size, ['x' => $right, 'y' => $bottom], ['x' => 0, 'y' => 0]]; + $data['square_image_with_square_crop__top_left'] = [['x' => $left, 'y' => $top], $original_image_size, $cropped_image_size, ['x' => 0, 'y' => 0]]; + $data['square_image_with_square_crop__top_center'] = [['x' => $center, 'y' => $top], $original_image_size, $cropped_image_size, ['x' => 500, 'y' => 0]]; + $data['square_image_with_square_crop__top_right'] = [['x' => $right, 'y' => $top], $original_image_size, $cropped_image_size, ['x' => 1000, 'y' => 0]]; + $data['square_image_with_square_crop__center_left'] = [['x' => $left, 'y' => $center], $original_image_size, $cropped_image_size, ['x' => 0, 'y' => 500]]; + $data['square_image_with_square_crop__center_center'] = [['x' => $center, 'y' => $center], $original_image_size, $cropped_image_size, ['x' => 500, 'y' => 500]]; + $data['square_image_with_square_crop__center_right'] = [['x' => $right, 'y' => $center], $original_image_size, $cropped_image_size, ['x' => 1000, 'y' => 500]]; + $data['square_image_with_square_crop__bottom_left'] = [['x' => $left, 'y' => $bottom], $original_image_size, $cropped_image_size, ['x' => 0, 'y' => 1000]]; + $data['square_image_with_square_crop__bottom_center'] = [['x' => $center, 'y' => $bottom], $original_image_size, $cropped_image_size, ['x' => 500, 'y' => 1000]]; + $data['square_image_with_square_crop__bottom_right'] = [['x' => $right, 'y' => $bottom], $original_image_size, $cropped_image_size, ['x' => 1000, 'y' => 1000]]; // Square image with horizontal crop. $original_image_size = ['width' => 2000, 'height' => 2000]; - $resized_image_size = ['width' => 1000, 'height' => 1000]; $cropped_image_size = ['width' => 1000, 'height' => 250]; list($top, $left, $center, $bottom, $right) = [100, 100, 1000, 1900, 1900]; - $data['square_image_with_horizontal_crop__top_left'] = [$original_image_size, $resized_image_size, $cropped_image_size, ['x' => $left, 'y' => $top], ['x' => 0, 'y' => 0]]; - $data['square_image_with_horizontal_crop__top_center'] = [$original_image_size, $resized_image_size, $cropped_image_size, ['x' => $center, 'y' => $top], ['x' => 0, 'y' => 0]]; - $data['square_image_with_horizontal_crop__top_right'] = [$original_image_size, $resized_image_size, $cropped_image_size, ['x' => $right, 'y' => $top], ['x' => 0, 'y' => 0]]; - $data['square_image_with_horizontal_crop__center_left'] = [$original_image_size, $resized_image_size, $cropped_image_size, ['x' => $left, 'y' => $center], ['x' => 0, 'y' => 375]]; - $data['square_image_with_horizontal_crop__center_center'] = [$original_image_size, $resized_image_size, $cropped_image_size, ['x' => $center, 'y' => $center], ['x' => 0, 'y' => 375]]; - $data['square_image_with_horizontal_crop__center_right'] = [$original_image_size, $resized_image_size, $cropped_image_size, ['x' => $right, 'y' => $center], ['x' => 0, 'y' => 375]]; - $data['square_image_with_horizontal_crop__bottom_left'] = [$original_image_size, $resized_image_size, $cropped_image_size, ['x' => $left, 'y' => $bottom], ['x' => 0, 'y' => 750]]; - $data['square_image_with_horizontal_crop__bottom_center'] = [$original_image_size, $resized_image_size, $cropped_image_size, ['x' => $center, 'y' => $bottom], ['x' => 0, 'y' => 750]]; - $data['square_image_with_horizontal_crop__bottom_right'] = [$original_image_size, $resized_image_size, $cropped_image_size, ['x' => $right, 'y' => $bottom], ['x' => 0, 'y' => 750]]; + $data['square_image_with_horizontal_crop__top_left'] = [['x' => $left, 'y' => $top], $original_image_size, $cropped_image_size, ['x' => 0, 'y' => 0]]; + $data['square_image_with_horizontal_crop__top_center'] = [['x' => $center, 'y' => $top], $original_image_size, $cropped_image_size, ['x' => 500, 'y' => 0]]; + $data['square_image_with_horizontal_crop__top_right'] = [['x' => $right, 'y' => $top], $original_image_size, $cropped_image_size, ['x' => 1000, 'y' => 0]]; + $data['square_image_with_horizontal_crop__center_left'] = [['x' => $left, 'y' => $center], $original_image_size, $cropped_image_size, ['x' => 0, 'y' => 875]]; + $data['square_image_with_horizontal_crop__center_center'] = [['x' => $center, 'y' => $center], $original_image_size, $cropped_image_size, ['x' => 500, 'y' => 875]]; + $data['square_image_with_horizontal_crop__center_right'] = [['x' => $right, 'y' => $center], $original_image_size, $cropped_image_size, ['x' => 1000, 'y' => 875]]; + $data['square_image_with_horizontal_crop__bottom_left'] = [['x' => $left, 'y' => $bottom], $original_image_size, $cropped_image_size, ['x' => 0, 'y' => 1750]]; + $data['square_image_with_horizontal_crop__bottom_center'] = [['x' => $center, 'y' => $bottom], $original_image_size, $cropped_image_size, ['x' => 500, 'y' => 1750]]; + $data['square_image_with_horizontal_crop__bottom_right'] = [['x' => $right, 'y' => $bottom], $original_image_size, $cropped_image_size, ['x' => 1000, 'y' => 1750]]; // Square image with vertical crop. $original_image_size = ['width' => 2000, 'height' => 2000]; - $resized_image_size = ['width' => 500, 'height' => 500]; $cropped_image_size = ['width' => 100, 'height' => 500]; list($top, $left, $center, $bottom, $right) = [100, 100, 1000, 1900, 1900]; - $data['square_image_with_vertical_crop__top_left'] = [$original_image_size, $resized_image_size, $cropped_image_size, ['x' => $left, 'y' => $top], ['x' => 0, 'y' => 0]]; - $data['square_image_with_vertical_crop__top_center'] = [$original_image_size, $resized_image_size, $cropped_image_size, ['x' => $center, 'y' => $top], ['x' => 200, 'y' => 0]]; - $data['square_image_with_vertical_crop__top_right'] = [$original_image_size, $resized_image_size, $cropped_image_size, ['x' => $right, 'y' => $top], ['x' => 400, 'y' => 0]]; - $data['square_image_with_vertical_crop__center_left'] = [$original_image_size, $resized_image_size, $cropped_image_size, ['x' => $left, 'y' => $center], ['x' => 0, 'y' => 0]]; - $data['square_image_with_vertical_crop__center_center'] = [$original_image_size, $resized_image_size, $cropped_image_size, ['x' => $center, 'y' => $center], ['x' => 200, 'y' => 0]]; - $data['square_image_with_vertical_crop__center_right'] = [$original_image_size, $resized_image_size, $cropped_image_size, ['x' => $right, 'y' => $center], ['x' => 400, 'y' => 0]]; - $data['square_image_with_vertical_crop__bottom_left'] = [$original_image_size, $resized_image_size, $cropped_image_size, ['x' => $left, 'y' => $bottom], ['x' => 0, 'y' => 0]]; - $data['square_image_with_vertical_crop__bottom_center'] = [$original_image_size, $resized_image_size, $cropped_image_size, ['x' => $center, 'y' => $bottom], ['x' => 200, 'y' => 0]]; - $data['square_image_with_vertical_crop__bottom_right'] = [$original_image_size, $resized_image_size, $cropped_image_size, ['x' => $right, 'y' => $bottom], ['x' => 400, 'y' => 0]]; + $data['square_image_with_vertical_crop__top_left'] = [['x' => $left, 'y' => $top], $original_image_size, $cropped_image_size, ['x' => 50, 'y' => 0]]; + $data['square_image_with_vertical_crop__top_center'] = [['x' => $center, 'y' => $top], $original_image_size, $cropped_image_size, ['x' => 950, 'y' => 0]]; + $data['square_image_with_vertical_crop__top_right'] = [['x' => $right, 'y' => $top], $original_image_size, $cropped_image_size, ['x' => 1850, 'y' => 0]]; + $data['square_image_with_vertical_crop__center_left'] = [['x' => $left, 'y' => $center], $original_image_size, $cropped_image_size, ['x' => 50, 'y' => 750]]; + $data['square_image_with_vertical_crop__center_center'] = [['x' => $center, 'y' => $center], $original_image_size, $cropped_image_size, ['x' => 950, 'y' => 750]]; + $data['square_image_with_vertical_crop__center_right'] = [['x' => $right, 'y' => $center], $original_image_size, $cropped_image_size, ['x' => 1850, 'y' => 750]]; + $data['square_image_with_vertical_crop__bottom_left'] = [['x' => $left, 'y' => $bottom], $original_image_size, $cropped_image_size, ['x' => 50, 'y' => 1500]]; + $data['square_image_with_vertical_crop__bottom_center'] = [['x' => $center, 'y' => $bottom], $original_image_size, $cropped_image_size, ['x' => 950, 'y' => 1500]]; + $data['square_image_with_vertical_crop__bottom_right'] = [['x' => $right, 'y' => $bottom], $original_image_size, $cropped_image_size, ['x' => 1850, 'y' => 1500]]; // Horizontal image with square crop. $original_image_size = ['width' => 1500, 'height' => 500]; - $resized_image_size = ['width' => 600, 'height' => 200]; $cropped_image_size = ['width' => 200, 'height' => 200]; list($top, $left, $vcenter, $hcenter, $bottom, $right) = [10, 10, 250, 750, 490, 1490]; - $data['horizontal_image_with_square_crop__top_left'] = [$original_image_size, $resized_image_size, $cropped_image_size, ['x' => $left, 'y' => $top], ['x' => 0, 'y' => 0]]; - $data['horizontal_image_with_square_crop__top_center'] = [$original_image_size, $resized_image_size, $cropped_image_size, ['x' => $hcenter, 'y' => $top], ['x' => 200, 'y' => 0]]; - $data['horizontal_image_with_square_crop__top_right'] = [$original_image_size, $resized_image_size, $cropped_image_size, ['x' => $right, 'y' => $top], ['x' => 400, 'y' => 0]]; - $data['horizontal_image_with_square_crop__center_left'] = [$original_image_size, $resized_image_size, $cropped_image_size, ['x' => $left, 'y' => $vcenter], ['x' => 0, 'y' => 0]]; - $data['horizontal_image_with_square_crop__center_center'] = [$original_image_size, $resized_image_size, $cropped_image_size, ['x' => $hcenter, 'y' => $vcenter], ['x' => 200, 'y' => 0]]; - $data['horizontal_image_with_square_crop__center_right'] = [$original_image_size, $resized_image_size, $cropped_image_size, ['x' => $right, 'y' => $vcenter], ['x' => 400, 'y' => 0]]; - $data['horizontal_image_with_square_crop__bottom_left'] = [$original_image_size, $resized_image_size, $cropped_image_size, ['x' => $left, 'y' => $bottom], ['x' => 0, 'y' => 0]]; - $data['horizontal_image_with_square_crop__bottom_center'] = [$original_image_size, $resized_image_size, $cropped_image_size, ['x' => $hcenter, 'y' => $bottom], ['x' => 200, 'y' => 0]]; - $data['horizontal_image_with_square_crop__bottom_right'] = [$original_image_size, $resized_image_size, $cropped_image_size, ['x' => $right, 'y' => $bottom], ['x' => 400, 'y' => 0]]; + $data['horizontal_image_with_square_crop__top_left'] = [['x' => $left, 'y' => $top], $original_image_size, $cropped_image_size, ['x' => 0, 'y' => 0]]; + $data['horizontal_image_with_square_crop__top_center'] = [['x' => $hcenter, 'y' => $top], $original_image_size, $cropped_image_size, ['x' => 650, 'y' => 0]]; + $data['horizontal_image_with_square_crop__top_right'] = [['x' => $right, 'y' => $top], $original_image_size, $cropped_image_size, ['x' => 1300, 'y' => 0]]; + $data['horizontal_image_with_square_crop__center_left'] = [['x' => $left, 'y' => $vcenter], $original_image_size, $cropped_image_size, ['x' => 0, 'y' => 150]]; + $data['horizontal_image_with_square_crop__center_center'] = [['x' => $hcenter, 'y' => $vcenter], $original_image_size, $cropped_image_size, ['x' => 650, 'y' => 150]]; + $data['horizontal_image_with_square_crop__center_right'] = [['x' => $right, 'y' => $vcenter], $original_image_size, $cropped_image_size, ['x' => 1300, 'y' => 150]]; + $data['horizontal_image_with_square_crop__bottom_left'] = [['x' => $left, 'y' => $bottom], $original_image_size, $cropped_image_size, ['x' => 0, 'y' => 300]]; + $data['horizontal_image_with_square_crop__bottom_center'] = [['x' => $hcenter, 'y' => $bottom], $original_image_size, $cropped_image_size, ['x' => 650, 'y' =>300]]; + $data['horizontal_image_with_square_crop__bottom_right'] = [['x' => $right, 'y' => $bottom], $original_image_size, $cropped_image_size, ['x' => 1300, 'y' => 300]]; // Horizontal image with horizontal crop. $original_image_size = ['width' => 1024, 'height' => 768]; - $resized_image_size = ['width' => 1000, 'height' => 750]; $cropped_image_size = ['width' => 800, 'height' => 50]; list($top, $left, $vcenter, $hcenter, $bottom, $right) = [10, 10, 384, 512, 750, 1000]; - $data['horizontal_image_with_horizontal_crop__top_left'] = [$original_image_size, $resized_image_size, $cropped_image_size, ['x' => $left, 'y' => $top], ['x' => 0, 'y' => 0]]; - $data['horizontal_image_with_horizontal_crop__top_center'] = [$original_image_size, $resized_image_size, $cropped_image_size, ['x' => $hcenter, 'y' => $top], ['x' => 100, 'y' => 0]]; - $data['horizontal_image_with_horizontal_crop__top_right'] = [$original_image_size, $resized_image_size, $cropped_image_size, ['x' => $right, 'y' => $top], ['x' => 200, 'y' => 0]]; - $data['horizontal_image_with_horizontal_crop__center_left'] = [$original_image_size, $resized_image_size, $cropped_image_size, ['x' => $left, 'y' => $vcenter], ['x' => 0, 'y' => 350]]; - $data['horizontal_image_with_horizontal_crop__center_center'] = [$original_image_size, $resized_image_size, $cropped_image_size, ['x' => $hcenter, 'y' => $vcenter], ['x' => 100, 'y' => 350]]; - $data['horizontal_image_with_horizontal_crop__center_right'] = [$original_image_size, $resized_image_size, $cropped_image_size, ['x' => $right, 'y' => $vcenter], ['x' => 200, 'y' => 350]]; - $data['horizontal_image_with_horizontal_crop__bottom_left'] = [$original_image_size, $resized_image_size, $cropped_image_size, ['x' => $left, 'y' => $bottom], ['x' => 0, 'y' => 700]]; - $data['horizontal_image_with_horizontal_crop__bottom_center'] = [$original_image_size, $resized_image_size, $cropped_image_size, ['x' => $hcenter, 'y' => $bottom], ['x' => 100, 'y' => 700]]; - $data['horizontal_image_with_horizontal_crop__bottom_right'] = [$original_image_size, $resized_image_size, $cropped_image_size, ['x' => $right, 'y' => $bottom], ['x' => 200, 'y' => 700]]; + $data['horizontal_image_with_horizontal_crop__top_left'] = [['x' => $left, 'y' => $top], $original_image_size, $cropped_image_size, ['x' => 0, 'y' => 0]]; + $data['horizontal_image_with_horizontal_crop__top_center'] = [['x' => $hcenter, 'y' => $top], $original_image_size, $cropped_image_size, ['x' => 112, 'y' => 0]]; + $data['horizontal_image_with_horizontal_crop__top_right'] = [['x' => $right, 'y' => $top], $original_image_size, $cropped_image_size, ['x' => 224, 'y' => 0]]; + $data['horizontal_image_with_horizontal_crop__center_left'] = [['x' => $left, 'y' => $vcenter], $original_image_size, $cropped_image_size, ['x' => 0, 'y' => 359]]; + $data['horizontal_image_with_horizontal_crop__center_center'] = [['x' => $hcenter, 'y' => $vcenter], $original_image_size, $cropped_image_size, ['x' => 112, 'y' => 359]]; + $data['horizontal_image_with_horizontal_crop__center_right'] = [['x' => $right, 'y' => $vcenter], $original_image_size, $cropped_image_size, ['x' => 224, 'y' => 359]]; + $data['horizontal_image_with_horizontal_crop__bottom_left'] = [['x' => $left, 'y' => $bottom], $original_image_size, $cropped_image_size, ['x' => 0, 'y' => 718]]; + $data['horizontal_image_with_horizontal_crop__bottom_center'] = [['x' => $hcenter, 'y' => $bottom], $original_image_size, $cropped_image_size, ['x' => 112, 'y' => 718]]; + $data['horizontal_image_with_horizontal_crop__bottom_right'] = [['x' => $right, 'y' => $bottom], $original_image_size, $cropped_image_size, ['x' => 224, 'y' => 718]]; // Horizontal image with vertical crop. $original_image_size = ['width' => 1024, 'height' => 768]; - $resized_image_size = ['width' => 800, 'height' => 600]; $cropped_image_size = ['width' => 313, 'height' => 600]; list($top, $left, $vcenter, $hcenter, $bottom, $right) = [10, 10, 384, 512, 750, 1000]; - $data['horizontal_image_with_vertical_crop__top_left'] = [$original_image_size, $resized_image_size, $cropped_image_size, ['x' => $left, 'y' => $top], ['x' => 0, 'y' => 0]]; - $data['horizontal_image_with_vertical_crop__top_center'] = [$original_image_size, $resized_image_size, $cropped_image_size, ['x' => $hcenter, 'y' => $top], ['x' => 243, 'y' => 0]]; - $data['horizontal_image_with_vertical_crop__top_right'] = [$original_image_size, $resized_image_size, $cropped_image_size, ['x' => $right, 'y' => $top], ['x' => 487, 'y' => 0]]; - $data['horizontal_image_with_vertical_crop__center_left'] = [$original_image_size, $resized_image_size, $cropped_image_size, ['x' => $left, 'y' => $vcenter], ['x' => 0, 'y' => 0]]; - $data['horizontal_image_with_vertical_crop__center_center'] = [$original_image_size, $resized_image_size, $cropped_image_size, ['x' => $hcenter, 'y' => $vcenter], ['x' => 243, 'y' => 0]]; - $data['horizontal_image_with_vertical_crop__center_right'] = [$original_image_size, $resized_image_size, $cropped_image_size, ['x' => $right, 'y' => $vcenter], ['x' => 487, 'y' => 0]]; - $data['horizontal_image_with_vertical_crop__bottom_left'] = [$original_image_size, $resized_image_size, $cropped_image_size, ['x' => $left, 'y' => $bottom], ['x' => 0, 'y' => 0]]; - $data['horizontal_image_with_vertical_crop__bottom_center'] = [$original_image_size, $resized_image_size, $cropped_image_size, ['x' => $hcenter, 'y' => $bottom], ['x' => 243, 'y' => 0]]; - $data['horizontal_image_with_vertical_crop__bottom_right'] = [$original_image_size, $resized_image_size, $cropped_image_size, ['x' => $right, 'y' => $bottom], ['x' => 487, 'y' => 0]]; + $data['horizontal_image_with_vertical_crop__top_left'] = [['x' => $left, 'y' => $top], $original_image_size, $cropped_image_size, ['x' => 0, 'y' => 0]]; + $data['horizontal_image_with_vertical_crop__top_center'] = [['x' => $hcenter, 'y' => $top], $original_image_size, $cropped_image_size, ['x' => 355, 'y' => 0]]; + $data['horizontal_image_with_vertical_crop__top_right'] = [['x' => $right, 'y' => $top], $original_image_size, $cropped_image_size, ['x' => 711, 'y' => 0]]; + $data['horizontal_image_with_vertical_crop__center_left'] = [['x' => $left, 'y' => $vcenter], $original_image_size, $cropped_image_size, ['x' => 0, 'y' => 84]]; + $data['horizontal_image_with_vertical_crop__center_center'] = [['x' => $hcenter, 'y' => $vcenter], $original_image_size, $cropped_image_size, ['x' => 355, 'y' => 84]]; + $data['horizontal_image_with_vertical_crop__center_right'] = [['x' => $right, 'y' => $vcenter], $original_image_size, $cropped_image_size, ['x' => 711, 'y' => 84]]; + $data['horizontal_image_with_vertical_crop__bottom_left'] = [['x' => $left, 'y' => $bottom], $original_image_size, $cropped_image_size, ['x' => 0, 'y' => 168]]; + $data['horizontal_image_with_vertical_crop__bottom_center'] = [['x' => $hcenter, 'y' => $bottom], $original_image_size, $cropped_image_size, ['x' => 355, 'y' => 168]]; + $data['horizontal_image_with_vertical_crop__bottom_right'] = [['x' => $right, 'y' => $bottom], $original_image_size, $cropped_image_size, ['x' => 711, 'y' => 168]]; // Vertical image with square crop. $original_image_size = ['width' => 500, 'height' => 2500]; - $resized_image_size = ['width' => 500, 'height' => 2500]; $cropped_image_size = ['width' => 100, 'height' => 100]; list($top, $left, $vcenter, $hcenter, $bottom, $right) = [50, 50, 1250, 250, 2450, 450]; - $data['vertical_image_with_square_crop__top_left'] = [$original_image_size, $resized_image_size, $cropped_image_size, ['x' => $left, 'y' => $top], ['x' => 0, 'y' => 0]]; - $data['vertical_image_with_square_crop__top_center'] = [$original_image_size, $resized_image_size, $cropped_image_size, ['x' => $hcenter, 'y' => $top], ['x' => 200, 'y' => 0]]; - $data['vertical_image_with_square_crop__top_right'] = [$original_image_size, $resized_image_size, $cropped_image_size, ['x' => $right, 'y' => $top], ['x' => 400, 'y' => 0]]; - $data['vertical_image_with_square_crop__center_left'] = [$original_image_size, $resized_image_size, $cropped_image_size, ['x' => $left, 'y' => $vcenter], ['x' => 0, 'y' => 1200]]; - $data['vertical_image_with_square_crop__center_center'] = [$original_image_size, $resized_image_size, $cropped_image_size, ['x' => $hcenter, 'y' => $vcenter], ['x' => 200, 'y' => 1200]]; - $data['vertical_image_with_square_crop__center_right'] = [$original_image_size, $resized_image_size, $cropped_image_size, ['x' => $right, 'y' => $vcenter], ['x' => 400, 'y' => 1200]]; - $data['vertical_image_with_square_crop__bottom_left'] = [$original_image_size, $resized_image_size, $cropped_image_size, ['x' => $left, 'y' => $bottom], ['x' => 0, 'y' => 2400]]; - $data['vertical_image_with_square_crop__bottom_center'] = [$original_image_size, $resized_image_size, $cropped_image_size, ['x' => $hcenter, 'y' => $bottom], ['x' => 200, 'y' => 2400]]; - $data['vertical_image_with_square_crop__bottom_right'] = [$original_image_size, $resized_image_size, $cropped_image_size, ['x' => $right, 'y' => $bottom], ['x' => 400, 'y' => 2400]]; + $data['vertical_image_with_square_crop__top_left'] = [['x' => $left, 'y' => $top], $original_image_size, $cropped_image_size, ['x' => 0, 'y' => 0]]; + $data['vertical_image_with_square_crop__top_center'] = [['x' => $hcenter, 'y' => $top], $original_image_size, $cropped_image_size, ['x' => 200, 'y' => 0]]; + $data['vertical_image_with_square_crop__top_right'] = [['x' => $right, 'y' => $top], $original_image_size, $cropped_image_size, ['x' => 400, 'y' => 0]]; + $data['vertical_image_with_square_crop__center_left'] = [['x' => $left, 'y' => $vcenter], $original_image_size, $cropped_image_size, ['x' => 0, 'y' => 1200]]; + $data['vertical_image_with_square_crop__center_center'] = [['x' => $hcenter, 'y' => $vcenter], $original_image_size, $cropped_image_size, ['x' => 200, 'y' => 1200]]; + $data['vertical_image_with_square_crop__center_right'] = [['x' => $right, 'y' => $vcenter], $original_image_size, $cropped_image_size, ['x' => 400, 'y' => 1200]]; + $data['vertical_image_with_square_crop__bottom_left'] = [['x' => $left, 'y' => $bottom], $original_image_size, $cropped_image_size, ['x' => 0, 'y' => 2400]]; + $data['vertical_image_with_square_crop__bottom_center'] = [['x' => $hcenter, 'y' => $bottom], $original_image_size, $cropped_image_size, ['x' => 200, 'y' => 2400]]; + $data['vertical_image_with_square_crop__bottom_right'] = [['x' => $right, 'y' => $bottom], $original_image_size, $cropped_image_size, ['x' => 400, 'y' => 2400]]; // Vertical image with horizontal crop. $original_image_size = ['width' => 1111, 'height' => 313]; - $resized_image_size = ['width' => 1111, 'height' => 313]; $cropped_image_size = ['width' => 400, 'height' => 73]; list($top, $left, $vcenter, $hcenter, $bottom, $right) = [10, 10, 384, 512, 750, 1000]; - $data['vertical_image_with_horizontal_crop__top_left'] = [$original_image_size, $resized_image_size, $cropped_image_size, ['x' => $left, 'y' => $top], ['x' => 0, 'y' => 0]]; - $data['vertical_image_with_horizontal_crop__top_center'] = [$original_image_size, $resized_image_size, $cropped_image_size, ['x' => $hcenter, 'y' => $top], ['x' => 312, 'y' => 0]]; - $data['vertical_image_with_horizontal_crop__top_right'] = [$original_image_size, $resized_image_size, $cropped_image_size, ['x' => $right, 'y' => $top], ['x' => 711, 'y' => 0]]; - $data['vertical_image_with_horizontal_crop__center_left'] = [$original_image_size, $resized_image_size, $cropped_image_size, ['x' => $left, 'y' => $vcenter], ['x' => 0, 'y' => 240]]; - $data['vertical_image_with_horizontal_crop__center_center'] = [$original_image_size, $resized_image_size, $cropped_image_size, ['x' => $hcenter, 'y' => $vcenter], ['x' => 312, 'y' => 240]]; - $data['vertical_image_with_horizontal_crop__center_right'] = [$original_image_size, $resized_image_size, $cropped_image_size, ['x' => $right, 'y' => $vcenter], ['x' => 711, 'y' => 240]]; - $data['vertical_image_with_horizontal_crop__bottom_left'] = [$original_image_size, $resized_image_size, $cropped_image_size, ['x' => $left, 'y' => $bottom], ['x' => 0, 'y' => 240]]; - $data['vertical_image_with_horizontal_crop__bottom_center'] = [$original_image_size, $resized_image_size, $cropped_image_size, ['x' => $hcenter, 'y' => $bottom], ['x' => 312, 'y' => 240]]; - $data['vertical_image_with_horizontal_crop__bottom_right'] = [$original_image_size, $resized_image_size, $cropped_image_size, ['x' => $right, 'y' => $bottom], ['x' => 711, 'y' => 240]]; + $data['vertical_image_with_horizontal_crop__top_left'] = [['x' => $left, 'y' => $top], $original_image_size, $cropped_image_size, ['x' => 0, 'y' => 0]]; + $data['vertical_image_with_horizontal_crop__top_center'] = [['x' => $hcenter, 'y' => $top], $original_image_size, $cropped_image_size, ['x' => 312, 'y' => 0]]; + $data['vertical_image_with_horizontal_crop__top_right'] = [['x' => $right, 'y' => $top], $original_image_size, $cropped_image_size, ['x' => 711, 'y' => 0]]; + $data['vertical_image_with_horizontal_crop__center_left'] = [['x' => $left, 'y' => $vcenter], $original_image_size, $cropped_image_size, ['x' => 0, 'y' => 240]]; + $data['vertical_image_with_horizontal_crop__center_center'] = [['x' => $hcenter, 'y' => $vcenter], $original_image_size, $cropped_image_size, ['x' => 312, 'y' => 240]]; + $data['vertical_image_with_horizontal_crop__center_right'] = [['x' => $right, 'y' => $vcenter], $original_image_size, $cropped_image_size, ['x' => 711, 'y' => 240]]; + $data['vertical_image_with_horizontal_crop__bottom_left'] = [['x' => $left, 'y' => $bottom], $original_image_size, $cropped_image_size, ['x' => 0, 'y' => 240]]; + $data['vertical_image_with_horizontal_crop__bottom_center'] = [['x' => $hcenter, 'y' => $bottom], $original_image_size, $cropped_image_size, ['x' => 312, 'y' => 240]]; + $data['vertical_image_with_horizontal_crop__bottom_right'] = [['x' => $right, 'y' => $bottom], $original_image_size, $cropped_image_size, ['x' => 711, 'y' => 240]]; // Vertical image with vertical crop. $original_image_size = ['width' => 200, 'height' => 2000]; - $resized_image_size = ['width' => 112, 'height' => 1111]; $cropped_image_size = ['width' => 100, 'height' => 1111]; list($top, $left, $vcenter, $hcenter, $bottom, $right) = [10, 10, 384, 512, 750, 1000]; - $data['vertical_image_with_vertical_crop__top_left'] = [$original_image_size, $resized_image_size, $cropped_image_size, ['x' => $left, 'y' => $top], ['x' => 0, 'y' => 0]]; - $data['vertical_image_with_vertical_crop__top_center'] = [$original_image_size, $resized_image_size, $cropped_image_size, ['x' => $hcenter, 'y' => $top], ['x' => 12, 'y' => 0]]; - $data['vertical_image_with_vertical_crop__top_right'] = [$original_image_size, $resized_image_size, $cropped_image_size, ['x' => $right, 'y' => $top], ['x' => 12, 'y' => 0]]; - $data['vertical_image_with_vertical_crop__center_left'] = [$original_image_size, $resized_image_size, $cropped_image_size, ['x' => $left, 'y' => $vcenter], ['x' => 0, 'y' => 0]]; - $data['vertical_image_with_vertical_crop__center_center'] = [$original_image_size, $resized_image_size, $cropped_image_size, ['x' => $hcenter, 'y' => $vcenter], ['x' => 12, 'y' => 0]]; - $data['vertical_image_with_vertical_crop__center_right'] = [$original_image_size, $resized_image_size, $cropped_image_size, ['x' => $right, 'y' => $vcenter], ['x' => 12, 'y' => 0]]; - $data['vertical_image_with_vertical_crop__bottom_left'] = [$original_image_size, $resized_image_size, $cropped_image_size, ['x' => $left, 'y' => $bottom], ['x' => 0, 'y' => 0]]; - $data['vertical_image_with_vertical_crop__bottom_center'] = [$original_image_size, $resized_image_size, $cropped_image_size, ['x' => $hcenter, 'y' => $bottom], ['x' => 12, 'y' => 0]]; - $data['vertical_image_with_vertical_crop__bottom_right'] = [$original_image_size, $resized_image_size, $cropped_image_size, ['x' => $right, 'y' => $bottom], ['x' => 12, 'y' => 0]]; + $data['vertical_image_with_vertical_crop__top_left'] = [['x' => $left, 'y' => $top], $original_image_size, $cropped_image_size, ['x' => 0, 'y' => 0]]; + $data['vertical_image_with_vertical_crop__top_center'] = [['x' => $hcenter, 'y' => $top], $original_image_size, $cropped_image_size, ['x' => 100, 'y' => 0]]; + $data['vertical_image_with_vertical_crop__top_right'] = [['x' => $right, 'y' => $top], $original_image_size, $cropped_image_size, ['x' => 100, 'y' => 0]]; + $data['vertical_image_with_vertical_crop__center_left'] = [['x' => $left, 'y' => $vcenter], $original_image_size, $cropped_image_size, ['x' => 0, 'y' => 0]]; + $data['vertical_image_with_vertical_crop__center_center'] = [['x' => $hcenter, 'y' => $vcenter], $original_image_size, $cropped_image_size, ['x' => 100, 'y' => 0]]; + $data['vertical_image_with_vertical_crop__center_right'] = [['x' => $right, 'y' => $vcenter], $original_image_size, $cropped_image_size, ['x' => 100, 'y' => 0]]; + $data['vertical_image_with_vertical_crop__bottom_left'] = [['x' => $left, 'y' => $bottom], $original_image_size, $cropped_image_size, ['x' => 0, 'y' => 194]]; + $data['vertical_image_with_vertical_crop__bottom_center'] = [['x' => $hcenter, 'y' => $bottom], $original_image_size, $cropped_image_size, ['x' => 100, 'y' => 194]]; + $data['vertical_image_with_vertical_crop__bottom_right'] = [['x' => $right, 'y' => $bottom], $original_image_size, $cropped_image_size, ['x' => 100, 'y' => 194]]; return $data; } @@ -283,19 +354,20 @@ class TestFocalPointEffectBase extends FocalPointEffectBase { /** * @var bool */ - protected $testingPreview = FALSE; + protected $testingPreview = NULL; + /** * @return null|string */ protected function getPreviewValue() { - return $this->testingPreview ? '0x0' : NULL; + return $this->testingPreview; } /** - * @param bool $testing_preview + * @param $value */ - public function setTestingPreview($testing_preview) { - $this->testingPreview = $testing_preview; + public function setTestingPreview($value) { + $this->testingPreview = $value; } -} +} \ No newline at end of file diff --git a/tests/src/Unit/FocalPointUnitTestCase.php b/tests/src/Unit/FocalPointUnitTestCase.php index 98d4dd8..ae9b176 100644 --- a/tests/src/Unit/FocalPointUnitTestCase.php +++ b/tests/src/Unit/FocalPointUnitTestCase.php @@ -4,10 +4,15 @@ namespace Drupal\Tests\focal_point\Unit; use Drupal\crop\CropStorageInterface; use Drupal\Core\Entity\EntityTypeManager; +use Drupal\Core\Image\ImageInterface; use Symfony\Component\DependencyInjection\ContainerInterface; use Drupal\focal_point\FocalPointManager; use Drupal\Tests\UnitTestCase; use Symfony\Component\HttpFoundation\Request; +use Drupal\focal_point\Plugin\ImageEffect\FocalPointCropImageEffect; +use Psr\Log\LoggerInterface; +use Drupal\Core\Config\ImmutableConfig; +use Drupal\focal_point\FocalPointEffectBase; /** * @group Focal Point @@ -50,4 +55,37 @@ abstract class FocalPointUnitTestCase extends UnitTestCase { \Drupal::setContainer($this->container->reveal()); } + /** + * @param \Drupal\Core\Image\ImageInterface|NULL $original_image + * @return \Drupal\focal_point\Plugin\ImageEffect\FocalPointCropImageEffect + */ + protected function getTestEffect(ImageInterface $original_image = NULL) { + if (is_null($original_image)) { + $original_image = $this->getTestImage(0,0); + } + + $logger = $this->prophesize(LoggerInterface::class); + $crop_storage = $this->prophesize(CropStorageInterface::class); + $immutable_config = $this->prophesize(ImmutableConfig::class); + $request = $this->prophesize(Request::class); + + $effect = new FocalPointCropImageEffect([], 'plugin_id', [], $logger->reveal(), $this->focalPointManager, $crop_storage->reveal(), $immutable_config->reveal(), $request->reveal()); + $effect->setOriginalImageSize($original_image); + + return $effect; + } + + /** + * @param int $width + * @param int $height + * @return object + */ + protected function getTestImage($width, $height) { + $image = $this->prophesize(ImageInterface::class); + $image->getWidth()->willReturn($width); + $image->getHeight()->willReturn($height); + + return $image->reveal(); + } + }