/**
  * {@inheritdoc}
  */
 public function applyEffect(ImageInterface $image)
 {
     if (!$image->convert($this->configuration['extension'])) {
         $this->logger->error('Image convert failed using the %toolkit toolkit on %path (%mimetype)', array('%toolkit' => $image->getToolkitId(), '%path' => $image->getSource(), '%mimetype' => $image->getMimeType()));
         return FALSE;
     }
     return TRUE;
 }
 /**
  * Function for finding a pixel's RGBa values.
  */
 function getPixelColor(ImageInterface $image, $x, $y)
 {
     $toolkit = $image->getToolkit();
     $color_index = imagecolorat($toolkit->getResource(), $x, $y);
     $transparent_index = imagecolortransparent($toolkit->getResource());
     if ($color_index == $transparent_index) {
         return array(0, 0, 0, 127);
     }
     return array_values(imagecolorsforindex($toolkit->getResource(), $color_index));
 }
 /**
  * {@inheritdoc}
  */
 public function applyEffect(ImageInterface $image)
 {
     // Next, attempt to crop the image.
     $focal_point = FocalPoint::getFromURI($image->getSource());
     $crop_data = self::calculateCropData($focal_point, $image->getWidth(), $image->getHeight(), $this->configuration['width'], $this->configuration['height']);
     if (!$image->crop($crop_data['x'], $crop_data['y'], $crop_data['width'], $crop_data['height'])) {
         $this->logger->error('Focal point scale and crop failed while scaling and cropping using the %toolkit toolkit on %path (%mimetype, %dimensions)', array('%toolkit' => $image->getToolkitId(), '%path' => $image->getSource(), '%mimetype' => $image->getMimeType(), '%dimensions' => $image->getWidth() . 'x' . $image->getHeight()));
         return FALSE;
     }
     return TRUE;
 }
예제 #4
0
 /**
  * {@inheritdoc}
  */
 public function applyEffect(ImageInterface $image)
 {
     list($x, $y) = explode('-', $this->configuration['anchor']);
     $x = image_filter_keyword($x, $image->getWidth(), $this->configuration['width']);
     $y = image_filter_keyword($y, $image->getHeight(), $this->configuration['height']);
     if (!$image->crop($x, $y, $this->configuration['width'], $this->configuration['height'])) {
         $this->logger->error('Image crop failed using the %toolkit toolkit on %path (%mimetype, %dimensions)', array('%toolkit' => $image->getToolkitId(), '%path' => $image->getSource(), '%mimetype' => $image->getMimeType(), '%dimensions' => $image->getWidth() . 'x' . $image->getHeight()));
         return FALSE;
     }
     return TRUE;
 }
 /**
  * {@inheritdoc}
  */
 public function applyEffect(ImageInterface $image)
 {
     if (empty($this->configuration['crop_type']) || !$this->typeStorage->load($this->configuration['crop_type'])) {
         $this->logger->error('Manual image crop failed due to misconfigured crop type on %path.', ['%path' => $image->getSource()]);
         return FALSE;
     }
     if ($crop = $this->getCrop($image)) {
         // Use position instead of anchor(),
         // ImageWidgetCrop already set coordinates by center
         $anchor = $crop->position();
         $size = $crop->size();
         if (!$image->crop($anchor['x'], $anchor['y'], $size['width'], $size['height'])) {
             $this->logger->error('Manual image crop failed using the %toolkit toolkit on %path (%mimetype, %width x %height)', ['%toolkit' => $image->getToolkitId(), '%path' => $image->getSource(), '%mimetype' => $image->getMimeType(), '%width' => $image->getWidth(), '%height' => $image->getHeight()]);
             return FALSE;
         }
     }
     return TRUE;
 }
예제 #6
0
 /**
  * {@inheritdoc}
  */
 public function applyEffect(ImageInterface $image)
 {
     if (!$image->desaturate()) {
         watchdog('image', 'Image desaturate failed using the %toolkit toolkit on %path (%mimetype, %dimensions)', array('%toolkit' => $image->getToolkitId(), '%path' => $image->getSource(), '%mimetype' => $image->getMimeType(), '%dimensions' => $image->getWidth() . 'x' . $image->getHeight()), WATCHDOG_ERROR);
         return FALSE;
     }
     return TRUE;
 }
예제 #7
0
 /**
  * {@inheritdoc}
  */
 public function applyEffect(ImageInterface $image)
 {
     if (!$image->scaleAndCrop($this->configuration['width'], $this->configuration['height'])) {
         watchdog('image', 'Image scale and crop failed using the %toolkit toolkit on %path (%mimetype, %dimensions)', array('%toolkit' => $image->getToolkitId(), '%path' => $image->getSource(), '%mimetype' => $image->getMimeType(), '%dimensions' => $image->getWidth() . 'x' . $image->getHeight()), WATCHDOG_ERROR);
         return FALSE;
     }
     return TRUE;
 }
예제 #8
0
 /**
  * {@inheritdoc}
  */
 public function applyEffect(ImageInterface $image)
 {
     if (!$image->resize($this->configuration['width'], $this->configuration['height'])) {
         $this->logger->error('Image resize failed using the %toolkit toolkit on %path (%mimetype, %dimensions)', array('%toolkit' => $image->getToolkitId(), '%path' => $image->getSource(), '%mimetype' => $image->getMimeType(), '%dimensions' => $image->getWidth() . 'x' . $image->getHeight()));
         return FALSE;
     }
     return TRUE;
 }
예제 #9
0
 /**
  * {@inheritdoc}
  */
 public function applyEffect(ImageInterface $image)
 {
     if (!empty($this->configuration['random'])) {
         $degrees = abs((double) $this->configuration['degrees']);
         $this->configuration['degrees'] = rand(-$degrees, $degrees);
     }
     if (!$image->rotate($this->configuration['degrees'], $this->configuration['bgcolor'])) {
         $this->logger->error('Image rotate failed using the %toolkit toolkit on %path (%mimetype, %dimensions)', array('%toolkit' => $image->getToolkitId(), '%path' => $image->getSource(), '%mimetype' => $image->getMimeType(), '%dimensions' => $image->getWidth() . 'x' . $image->getHeight()));
         return FALSE;
     }
     return TRUE;
 }
 /**
  * {@inheritdoc}
  */
 public function applyEffect(ImageInterface $image)
 {
     $ratio_adjustment = isset($this->configuration['ratio_adjustment']) ? floatval($this->configuration['ratio_adjustment']) : 1;
     $aspect = $image->getWidth() / $image->getHeight();
     // Calculate orientation: width / height * adjustment. If > 1, it's wide.
     $style_name = $aspect * $ratio_adjustment > 1 ? $this->configuration['landscape'] : $this->configuration['portrait'];
     if (empty($style_name)) {
         // Do nothing. just return what we've got.
         return TRUE;
     }
     /* @var ImageStyle $style */
     $style = ImageStyle::load($style_name);
     if (empty($style)) {
         // Required preset has gone missing?
         return FALSE;
     }
     // Run the preset actions ourself.
     foreach ($style->getEffects() as $sub_effect) {
         /* @var ImageEffectInterface $sub_effect */
         $sub_effect->applyEffect($image);
     }
     return TRUE;
 }
 /**
  * {@inheritdoc}
  */
 public function applyEffect(ImageInterface $image)
 {
     $path = $image->getSource();
     $entity_manager = \Drupal::entityManager();
     $files = $entity_manager->getStorage('file')->loadByProperties(array('uri' => $path));
     $file = NULL;
     if (count($files)) {
         $file = reset($files);
         $info = imagefield_crop_get_file_info($file->id());
         if (!$info) {
             return TRUE;
         }
         if (!$image->crop($info['x'], $info['y'], $info['width'], $info['height'])) {
             $this->logger->error('Image crop failed using the %toolkit toolkit on %path (%mimetype, %dimensions)', array('%toolkit' => $image->getToolkitId(), '%path' => $image->getSource(), '%mimetype' => $image->getMimeType(), '%dimensions' => $image->getWidth() . 'x' . $image->getHeight()));
             return FALSE;
         }
     }
     return TRUE;
 }
예제 #12
0
 /**
  * {@inheritdoc}
  */
 public function applyEffect(ImageInterface $image)
 {
     $data = [];
     $data['canvas_color'] = $this->configuration['canvas_color'];
     // Get resulting dimensions.
     $dimensions = $this->getDimensions($image->getWidth(), $image->getHeight());
     $data['width'] = $dimensions['width'];
     $data['height'] = $dimensions['height'];
     // Get offset of original image.
     if ($this->configuration['canvas_size'] === 'exact') {
         list($x_pos, $y_pos) = explode('-', $this->configuration['exact']['placement']);
         $data['x_pos'] = image_filter_keyword($x_pos, $data['width'], $image->getWidth()) + $this->configuration['exact']['x_offset'];
         $data['y_pos'] = image_filter_keyword($y_pos, $data['height'], $image->getHeight()) + $this->configuration['exact']['y_offset'];
     } else {
         $data['x_pos'] = $this->configuration['relative']['left'];
         $data['y_pos'] = $this->configuration['relative']['top'];
     }
     // All the math is done, now defer to the toolkit in use.
     return $image->apply('set_canvas', $data);
 }
예제 #13
0
 /**
  * {@inheritdoc}
  */
 public function applyEffect(ImageInterface $image)
 {
     // Convert short #FFF syntax to full #FFFFFF syntax.
     if (strlen($this->configuration['bgcolor']) == 4) {
         $c = $this->configuration['bgcolor'];
         $this->configuration['bgcolor'] = $c[0] . $c[1] . $c[1] . $c[2] . $c[2] . $c[3] . $c[3];
     }
     // Convert #FFFFFF syntax to hexadecimal colors.
     if ($this->configuration['bgcolor'] != '') {
         $this->configuration['bgcolor'] = hexdec(str_replace('#', '0x', $this->configuration['bgcolor']));
     } else {
         $this->configuration['bgcolor'] = NULL;
     }
     if (!empty($this->configuration['random'])) {
         $degrees = abs((double) $this->configuration['degrees']);
         $this->configuration['degrees'] = rand(-1 * $degrees, $degrees);
     }
     if (!$image->rotate($this->configuration['degrees'], $this->configuration['bgcolor'])) {
         watchdog('image', 'Image rotate failed using the %toolkit toolkit on %path (%mimetype, %dimensions)', array('%toolkit' => $image->getToolkitId(), '%path' => $image->getSource(), '%mimetype' => $image->getMimeType(), '%dimensions' => $image->getWidth() . 'x' . $image->getHeight()), WATCHDOG_ERROR);
         return FALSE;
     }
     return TRUE;
 }
예제 #14
0
  /**
   * Returns the focal point value (in pixels) relative to the provided image.
   *
   * @param 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 array
   *   An array with the keys 'x' and 'y'. Values are in pixels.
   */
  protected function transformFocalPoint(ImageInterface $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;
  }
예제 #15
0
 /**
  * {@inheritdoc}
  */
 public function applyEffect(ImageInterface $image)
 {
     // Test to see if EXIF is supported by the image format.
     if (in_array($image->getMimeType(), ['image/jpeg', 'image/tiff'])) {
         // Hand over to toolkit.
         return $image->apply('auto_orient');
     }
     return TRUE;
 }
 /**
  * {@inheritdoc}
  */
 public function applyEffect(ImageInterface $image)
 {
     $dimensions = $this->getUriDependentDimensions($image->getSource());
     return $image->resize($dimensions['width'], $dimensions['height']);
 }
 /**
  * {@inheritdoc}
  */
 public function applyEffect(ImageInterface $image)
 {
     return $image->apply('strip');
 }
예제 #18
0
 /**
  * {@inheritdoc}
  */
 public function applyEffect(ImageInterface $image)
 {
     return $image->apply('contrast', ['level' => $this->configuration['level']]);
 }
예제 #19
0
 /**
  * {@inheritdoc}
  */
 public function applyEffect(ImageInterface $image)
 {
     return $image->apply('colorshift', ['RGB' => $this->configuration['RGB']]);
 }
예제 #20
0
  /**
   * Gets crop entity for the image.
   *
   * @param ImageInterface $image
   *   Image object.
   *
   * @return \Drupal\Core\Entity\EntityInterface|\Drupal\crop\CropInterface|FALSE
   *   Crop entity or FALSE if crop doesn't exist.
   */
  protected function getCrop(ImageInterface $image) {
    if (!isset($this->crop)) {
      $this->crop = FALSE;
      if ($crop = Crop::findCrop($image->getSource(), $this->configuration['crop_type'])) {
        $this->crop = $crop;
      }
    }

    return $this->crop;
  }
예제 #21
0
 /**
  * {@inheritdoc}
  */
 public function applyEffect(ImageInterface $image)
 {
     $watermark_image = $this->imageFactory->get($this->configuration['watermark_image']);
     if (!$watermark_image->isValid()) {
         return FALSE;
     }
     list($x, $y) = explode('-', $this->configuration['placement']);
     $x_pos = image_filter_keyword($x, $image->getWidth(), $watermark_image->getWidth());
     $y_pos = image_filter_keyword($y, $image->getHeight(), $watermark_image->getHeight());
     return $image->apply('watermark', ['x_offset' => $x_pos + $this->configuration['x_offset'], 'y_offset' => $y_pos + $this->configuration['y_offset'], 'opacity' => $this->configuration['opacity'], 'watermark_image' => $watermark_image]);
 }