UriDependentTestImageEffect.php in Drupal 8
File
core/modules/image/tests/modules/image_module_test/src/Plugin/ImageEffect/UriDependentTestImageEffect.php
View source
<?php
namespace Drupal\image_module_test\Plugin\ImageEffect;
use Drupal\Core\Image\ImageInterface;
use Drupal\image\ImageEffectBase;
class UriDependentTestImageEffect extends ImageEffectBase {
public function transformDimensions(array &$dimensions, $uri) {
$dimensions = $this
->getUriDependentDimensions($uri);
}
public function applyEffect(ImageInterface $image) {
$dimensions = $this
->getUriDependentDimensions($image
->getSource());
return $image
->resize($dimensions['width'], $dimensions['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;
}
}