/** * {@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) { // 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; }
/** * {@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; }
/** * {@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; }
/** * {@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; }
/** * {@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) { $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; }
/** * {@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) { // 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; }
/** * {@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); }
/** * {@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]); }
/** * 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; }