final class AutomatedCropDefault in Automated Crop 8
Class Generic routing entity mapper.
Plugin annotation
@AutomatedCrop(
id = "automated_crop_default",
label = @Translation("Automated crop"),
description = @Translation("The default strategy for automatic crop."),
)
Hierarchy
- class \Drupal\Component\Plugin\PluginBase implements DerivativeInspectionInterface, PluginInspectionInterface
- class \Drupal\automated_crop\AbstractAutomatedCrop implements AutomatedCropInterface, ContainerFactoryPluginInterface uses StringTranslationTrait
- class \Drupal\automated_crop\Plugin\AutomatedCrop\AutomatedCropDefault
- class \Drupal\automated_crop\AbstractAutomatedCrop implements AutomatedCropInterface, ContainerFactoryPluginInterface uses StringTranslationTrait
Expanded class hierarchy of AutomatedCropDefault
File
- src/
Plugin/ AutomatedCrop/ AutomatedCropDefault.php, line 16
Namespace
Drupal\automated_crop\Plugin\AutomatedCropView source
final class AutomatedCropDefault extends AbstractAutomatedCrop {
/**
* {@inheritdoc}
*/
public function calculateCropBoxCoordinates() {
$this->cropBox['x'] = $this->originalImageSizes['width'] / 2 - $this->cropBox['width'] / 2;
$this->cropBox['y'] = $this->originalImageSizes['height'] / 2 - $this->cropBox['height'] / 2;
return $this;
}
/**
* {@inheritdoc}
*/
public function calculateCropBoxSize() {
if (!$this
->hasSizes() && !$this
->hasHardSizes()) {
$this
->automatedCropBoxCalculation();
}
if ('width' === $this
->findUnknownValue()) {
$value = !empty($this->cropBox['width']) ? $this->cropBox['width'] : $this->cropBox['max_width'];
$this
->setCropBoxSize($this
->calculateUnknownValue($value), $this->cropBox['height']);
}
if ('height' === $this
->findUnknownValue()) {
$value = !empty($this->cropBox['height']) ? $this->cropBox['height'] : $this->cropBox['max_height'];
$this
->setCropBoxSize($this->cropBox['width'], $this
->calculateUnknownValue($value));
}
// Initialize auto crop area & unsure we can't exceed original image sizes.
$width = min(max($this->cropBox['width'], $this->cropBox['min_width']), $this->cropBox['max_width']);
$height = min(max($this->cropBox['height'], $this->cropBox['min_height']), $this->cropBox['max_height']);
$this
->setCropBoxSize($width, $height);
return $this;
}
/**
* Calculate size automatically based on origin image width.
*
* This method admit you want to crop the height of your image in another,
* ratio with respect of original image homothety. If you not define any,
* ratio in plugin configuration, nothing happen. If you define a new ratio,
* your image will conserve his original width but the height will,
* calculated to respect plugin ratio given.
*
* This method contains a system that avoids exceeding,
* the maximum sizes of the cropBox. Pay attention with the,
* configurations of max width/height.
*/
protected function automatedCropBoxCalculation() {
$delta = $this
->getDelta();
$width = $this->originalImageSizes['width'];
$height = round($this->cropBox['max_height'] * $delta);
if (!empty($this->cropBox['max_height']) && $height > $this->cropBox['max_height']) {
$height = $this->cropBox['max_height'];
$width = round($height * $delta);
}
if (!empty($this->cropBox['max_width']) && $width > $this->cropBox['max_width']) {
$width = $this->cropBox['max_width'];
$height = round($width * $delta);
}
$this->cropBox['width'] = $width;
$this->cropBox['height'] = $height;
}
/**
* Evaluate if with or height need to be calculated.
*
* If we have already ALL cropBox sizes we just need to apply,
* it don't need to evaluate missing values.
*
* @return bool|string
* The value to find or False if cropBox have any sizes found.
*/
protected function findUnknownValue() {
if (!$this
->hasSizes()) {
return FALSE;
}
$valueToSearch = 'width';
if (!empty($this->cropBox['width']) && empty($this->cropBox['height'])) {
$valueToSearch = 'height';
}
return $valueToSearch;
}
/**
* Calculate the new value of given width or height respecting homothety.
*
* @param int $value
* Value to convert with image delta to found compatible new sizes.
*
* @return int
* The new height or width respect the homothety of image.
*/
protected function calculateUnknownValue($value) {
return round($value * $this->delta);
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
AbstractAutomatedCrop:: |
protected | property | The machine name of this crop type. | |
AbstractAutomatedCrop:: |
protected | property | The percentage of automatic cropping area when initializes. | |
AbstractAutomatedCrop:: |
protected | property | All available value expected to calculate crop box area. | |
AbstractAutomatedCrop:: |
protected | property | The delta obtained by dividing the height by width. | |
AbstractAutomatedCrop:: |
protected | property | The entity type manager service. | |
AbstractAutomatedCrop:: |
protected | property | The image object to crop. | |
AbstractAutomatedCrop:: |
protected | property | Plugin label. | |
AbstractAutomatedCrop:: |
protected | property | The machine name of this crop type. | |
AbstractAutomatedCrop:: |
public | function |
Gets crop anchor (top-left corner of crop area). Overrides AutomatedCropInterface:: |
|
AbstractAutomatedCrop:: |
constant | Aspect ratio validation regexp. | ||
AbstractAutomatedCrop:: |
public | function |
Calculates dependencies for the configured plugin. Overrides DependentPluginInterface:: |
|
AbstractAutomatedCrop:: |
protected static | function | Calculate the greatest common denominator of two numbers. | |
AbstractAutomatedCrop:: |
public static | function |
Creates an instance of the plugin. Overrides ContainerFactoryPluginInterface:: |
|
AbstractAutomatedCrop:: |
public | function |
Gets default configuration for this plugin. Overrides ConfigurablePluginInterface:: |
|
AbstractAutomatedCrop:: |
public | function |
Get the aspect ratio. Overrides AutomatedCropInterface:: |
|
AbstractAutomatedCrop:: |
public | function |
Gets this plugin's configuration. Overrides ConfigurablePluginInterface:: |
|
AbstractAutomatedCrop:: |
public | function |
Gets the delta of image. Overrides AutomatedCropInterface:: |
|
AbstractAutomatedCrop:: |
public | function |
Gets the plugin image object to crop. Overrides AutomatedCropInterface:: |
|
AbstractAutomatedCrop:: |
public | function |
Get the original image sizes of image to be cropped. Overrides AutomatedCropInterface:: |
|
AbstractAutomatedCrop:: |
public | function | Evaluate if crop box has Hard sizes defined. | |
AbstractAutomatedCrop:: |
public | function | Evaluate if user have set one of crop box area sizes. | |
AbstractAutomatedCrop:: |
public | function | Initializes the properties of the plugins according to the configurations. | |
AbstractAutomatedCrop:: |
public | function |
Returns the display label. Overrides AutomatedCropInterface:: |
|
AbstractAutomatedCrop:: |
public | function |
Set crop anchor (top-left corner of crop area). Overrides AutomatedCropInterface:: |
|
AbstractAutomatedCrop:: |
public | function |
Set the aspect ratio from plugin object. Overrides AutomatedCropInterface:: |
|
AbstractAutomatedCrop:: |
public | function |
Define the percentage of automatic cropping area when initializes. Overrides AutomatedCropInterface:: |
|
AbstractAutomatedCrop:: |
public | function |
Sets the configuration for this plugin instance. Overrides ConfigurablePluginInterface:: |
|
AbstractAutomatedCrop:: |
protected | function | Set all crop box properties from plugin configuration. | |
AbstractAutomatedCrop:: |
public | function |
Set crop box sizes. Overrides AutomatedCropInterface:: |
|
AbstractAutomatedCrop:: |
public | function |
Calculate and set the delta to apply of each size calculation of cropBox. Overrides AutomatedCropInterface:: |
|
AbstractAutomatedCrop:: |
public | function |
Set the image resource from plugin configuration to be cropped. Overrides AutomatedCropInterface:: |
|
AbstractAutomatedCrop:: |
public | function |
Gets crop box size. Overrides AutomatedCropInterface:: |
|
AbstractAutomatedCrop:: |
public | function |
Set the original sizes of image. Overrides AutomatedCropInterface:: |
|
AbstractAutomatedCrop:: |
public | function |
Gets crop box size. Overrides AutomatedCropInterface:: |
|
AbstractAutomatedCrop:: |
public | function |
Constructs AutomatedCrop plugin. Overrides PluginBase:: |
|
AutomatedCropDefault:: |
protected | function | Calculate size automatically based on origin image width. | |
AutomatedCropDefault:: |
public | function |
Calculation of the coordinates of the crop area. Overrides AbstractAutomatedCrop:: |
|
AutomatedCropDefault:: |
public | function |
Calculation of the dimensions of the crop area. Overrides AbstractAutomatedCrop:: |
|
AutomatedCropDefault:: |
protected | function | Calculate the new value of given width or height respecting homothety. | |
AutomatedCropDefault:: |
protected | function | Evaluate if with or height need to be calculated. | |
PluginBase:: |
protected | property | Configuration information passed into the plugin. | 1 |
PluginBase:: |
protected | property | The plugin implementation definition. | 1 |
PluginBase:: |
protected | property | The plugin_id. | |
PluginBase:: |
constant | A string which is used to separate base plugin IDs from the derivative ID. | ||
PluginBase:: |
public | function |
Gets the base_plugin_id of the plugin instance. Overrides DerivativeInspectionInterface:: |
|
PluginBase:: |
public | function |
Gets the derivative_id of the plugin instance. Overrides DerivativeInspectionInterface:: |
|
PluginBase:: |
public | function |
Gets the definition of the plugin implementation. Overrides PluginInspectionInterface:: |
3 |
PluginBase:: |
public | function |
Gets the plugin_id of the plugin instance. Overrides PluginInspectionInterface:: |
|
PluginBase:: |
public | function | Determines if the plugin is configurable. | |
StringTranslationTrait:: |
protected | property | The string translation service. | 1 |
StringTranslationTrait:: |
protected | function | Formats a string containing a count of items. | |
StringTranslationTrait:: |
protected | function | Returns the number of plurals supported by a given language. | |
StringTranslationTrait:: |
protected | function | Gets the string translation service. | |
StringTranslationTrait:: |
public | function | Sets the string translation service to use. | 2 |
StringTranslationTrait:: |
protected | function | Translates a string to the current language or to a given language. |