Updated Drupal to 8.6. This goes with the following updates because it's possible...
[yaffs-website] / web / core / modules / system / src / Plugin / ImageToolkit / Operation / gd / ScaleAndCrop.php
index 510020f8d8c85b4edc70dd1f25e68ee3bcddaea7..ad53ec3fa156ce3944cd0032c886f706e8a4ad11 100644 (file)
@@ -20,6 +20,16 @@ class ScaleAndCrop extends GDImageToolkitOperationBase {
    */
   protected function arguments() {
     return [
+      'x' => [
+        'description' => 'The horizontal offset for the start of the crop, in pixels',
+        'required' => FALSE,
+        'default' => NULL,
+      ],
+      'y' => [
+        'description' => 'The vertical offset for the start the crop, in pixels',
+        'required' => FALSE,
+        'default' => NULL,
+      ],
       'width' => [
         'description' => 'The target width, in pixels',
       ],
@@ -38,8 +48,12 @@ class ScaleAndCrop extends GDImageToolkitOperationBase {
 
     $scaleFactor = max($arguments['width'] / $actualWidth, $arguments['height'] / $actualHeight);
 
-    $arguments['x'] = (int) round(($actualWidth * $scaleFactor - $arguments['width']) / 2);
-    $arguments['y'] = (int) round(($actualHeight * $scaleFactor - $arguments['height']) / 2);
+    $arguments['x'] = isset($arguments['x']) ?
+      (int) round($arguments['x']) :
+      (int) round(($actualWidth * $scaleFactor - $arguments['width']) / 2);
+    $arguments['y'] = isset($arguments['y']) ?
+      (int) round($arguments['y']) :
+      (int) round(($actualHeight * $scaleFactor - $arguments['height']) / 2);
     $arguments['resize'] = [
       'width' => (int) round($actualWidth * $scaleFactor),
       'height' => (int) round($actualHeight * $scaleFactor),