Skip to content

Instantly share code, notes, and snippets.

@xpersonas
Last active October 10, 2016 19:31
Show Gist options
  • Save xpersonas/1cf12cef71607c84ce5f5416f0e052cd to your computer and use it in GitHub Desktop.
Save xpersonas/1cf12cef71607c84ce5f5416f0e052cd to your computer and use it in GitHub Desktop.
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);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment