class UriDependentTestImageEffect
Same name in other branches
- 9 core/modules/image/tests/modules/image_module_test/src/Plugin/ImageEffect/UriDependentTestImageEffect.php \Drupal\image_module_test\Plugin\ImageEffect\UriDependentTestImageEffect
- 8.9.x core/modules/image/tests/modules/image_module_test/src/Plugin/ImageEffect/UriDependentTestImageEffect.php \Drupal\image_module_test\Plugin\ImageEffect\UriDependentTestImageEffect
- 11.x core/modules/image/tests/modules/image_module_test/src/Plugin/ImageEffect/UriDependentTestImageEffect.php \Drupal\image_module_test\Plugin\ImageEffect\UriDependentTestImageEffect
Performs an image operation that depends on the URI of the original image.
Hierarchy
- class \Drupal\Component\Plugin\PluginBase implements \Drupal\Component\Plugin\PluginInspectionInterface, \Drupal\Component\Plugin\DerivativeInspectionInterface
- class \Drupal\Core\Plugin\PluginBase extends \Drupal\Component\Plugin\PluginBase uses \Drupal\Core\StringTranslation\StringTranslationTrait, \Drupal\Core\DependencyInjection\DependencySerializationTrait, \Drupal\Core\Messenger\MessengerTrait
- class \Drupal\image\ImageEffectBase extends \Drupal\Core\Plugin\PluginBase implements \Drupal\image\ImageEffectInterface, \Drupal\Core\Plugin\ContainerFactoryPluginInterface
- class \Drupal\image_module_test\Plugin\ImageEffect\UriDependentTestImageEffect extends \Drupal\image\ImageEffectBase
- class \Drupal\image\ImageEffectBase extends \Drupal\Core\Plugin\PluginBase implements \Drupal\image\ImageEffectInterface, \Drupal\Core\Plugin\ContainerFactoryPluginInterface
- class \Drupal\Core\Plugin\PluginBase extends \Drupal\Component\Plugin\PluginBase uses \Drupal\Core\StringTranslation\StringTranslationTrait, \Drupal\Core\DependencyInjection\DependencySerializationTrait, \Drupal\Core\Messenger\MessengerTrait
Expanded class hierarchy of UriDependentTestImageEffect
File
-
core/
modules/ image/ tests/ modules/ image_module_test/ src/ Plugin/ ImageEffect/ UriDependentTestImageEffect.php, line 13
Namespace
Drupal\image_module_test\Plugin\ImageEffectView source
class UriDependentTestImageEffect extends ImageEffectBase {
/**
* {@inheritdoc}
*/
public function transformDimensions(array &$dimensions, $uri) {
$dimensions = $this->getUriDependentDimensions($uri);
}
/**
* {@inheritdoc}
*/
public function applyEffect(ImageInterface $image) {
$dimensions = $this->getUriDependentDimensions($image->getSource());
return $image->resize($dimensions['width'], $dimensions['height']);
}
/**
* Make the image dimensions dependent on the image file extension.
*
* @param string $uri
* Original image file URI.
*
* @return array
* Associative array.
* - width: Integer with the derivative image width.
* - height: Integer with the derivative image height.
*/
protected function getUriDependentDimensions($uri) {
$dimensions = [];
$extension = pathinfo($uri, PATHINFO_EXTENSION);
switch (strtolower($extension)) {
case 'png':
$dimensions['width'] = $dimensions['height'] = 100;
break;
case 'gif':
$dimensions['width'] = $dimensions['height'] = 50;
break;
default:
$dimensions['width'] = $dimensions['height'] = 20;
break;
}
return $dimensions;
}
}
Members
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.