xpersonas
10/10/2016 - 6:47 PM

Drupal 8 Images Rendered with Style

Drupal 8 Images Rendered with Style

// https://kindrakevich.com/notes/drupal-8-render-images-image-style
// Find a derivative URI and URL:
$original_image = 'public://images/image.jpg';
use Drupal\image\Entity\ImageStyle;
$style = ImageStyle::load('thumbnail');  // Load the image style configuration entity.
$uri = $style->buildUri($original_image);
$url = $style->buildUrl($original_image);

// Create a derivative image programmatically:
$original_image = 'public://images/image.jpg';
$style = ImageStyle::load('thumbnail');  // Load the image style configuration entity.
$destination = $style->buildUri($original_image);
$style->createDerivative($original_image, $destination);