/** * {@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->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; }
/** * {@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) { $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) { 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['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) { 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; }
/** * {@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) { $dimensions = $this->getUriDependentDimensions($image->getSource()); return $image->resize($dimensions['width'], $dimensions['height']); }
/** * 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; }
/** * Applies the crop effect to an image. * * @param ImageInterface $image * The image resource to crop. * * @return bool * TRUE if the image is successfully cropped, otherwise FALSE. */ public function applyCrop(ImageInterface $image) { $crop_type = $this->focalPointConfig->get('crop_type'); /** @var \Drupal\crop\CropInterface $crop */ if ($crop = Crop::findCrop($image->getSource(), $crop_type)) { // An existing crop has been found; set the size. $crop->setSize($this->configuration['width'], $this->configuration['height']); } else { // No existing crop could be found; create a new one using the size. $crop = $this->cropStorage->create([ 'type' => $crop_type, 'x' => (int) round($image->getWidth() / 2), 'y' => (int) round($image->getHeight() / 2), 'width' => $this->configuration['width'], 'height' => $this->configuration['height'], ]); } // 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)', [ '%toolkit' => $image->getToolkitId(), '%path' => $image->getSource(), '%mimetype' => $image->getMimeType(), '%dimensions' => $image->getWidth() . 'x' . $image->getHeight(), '%anchor' => $anchor, ] ); return FALSE; } return TRUE; }