You are here

class ScaleAndSmartCrop in Image Effects 8.2

Same name in this branch
  1. 8.2 src/Plugin/ImageToolkit/Operation/gd/ScaleAndSmartCrop.php \Drupal\image_effects\Plugin\ImageToolkit\Operation\gd\ScaleAndSmartCrop
  2. 8.2 src/Plugin/ImageToolkit/Operation/imagemagick/ScaleAndSmartCrop.php \Drupal\image_effects\Plugin\ImageToolkit\Operation\imagemagick\ScaleAndSmartCrop
Same name and namespace in other branches
  1. 8.3 src/Plugin/ImageToolkit/Operation/imagemagick/ScaleAndSmartCrop.php \Drupal\image_effects\Plugin\ImageToolkit\Operation\imagemagick\ScaleAndSmartCrop
  2. 8 src/Plugin/ImageToolkit/Operation/imagemagick/ScaleAndSmartCrop.php \Drupal\image_effects\Plugin\ImageToolkit\Operation\imagemagick\ScaleAndSmartCrop

Defines Imagemagick Scale and Smart Crop operation.

Plugin annotation


@ImageToolkitOperation(
  id = "image_effects_imagemagick_scale_and_smart_crop",
  toolkit = "imagemagick",
  operation = "scale_and_smart_crop",
  label = @Translation("Scale and Smart Crop"),
  description = @Translation("Similar to Scale And Crop, but preserves the portion of the image with the most entropy.")
)

Hierarchy

  • class \Drupal\image_effects\Plugin\ImageToolkit\Operation\imagemagick\ScaleAndSmartCrop extends \Drupal\imagemagick\Plugin\ImageToolkit\Operation\imagemagick\ImagemagickImageToolkitOperationBase uses ScaleAndSmartCropTrait

Expanded class hierarchy of ScaleAndSmartCrop

File

src/Plugin/ImageToolkit/Operation/imagemagick/ScaleAndSmartCrop.php, line 19

Namespace

Drupal\image_effects\Plugin\ImageToolkit\Operation\imagemagick
View source
class ScaleAndSmartCrop extends ImagemagickImageToolkitOperationBase {
  use ScaleAndSmartCropTrait;

  /**
   * {@inheritdoc}
   */
  protected function execute(array $arguments = []) {

    // Don't scale if we don't change the dimensions at all.
    if ($arguments['width'] !== $this
      ->getToolkit()
      ->getWidth() || $arguments['height'] !== $this
      ->getToolkit()
      ->getHeight()) {

      // Don't upscale if the option isn't enabled.
      if ($arguments['upscale'] || $arguments['width'] <= $this
        ->getToolkit()
        ->getWidth() && $arguments['height'] <= $this
        ->getToolkit()
        ->getHeight()) {
        return $this
          ->getToolkit()
          ->apply('resize', $arguments['resize']) && $this
          ->getToolkit()
          ->apply('smart_crop', $arguments);
      }
    }
    return TRUE;
  }

}

Members