Last active
October 10, 2016 19:31
-
-
Save xpersonas/1cf12cef71607c84ce5f5416f0e052cd to your computer and use it in GitHub Desktop.
Drupal 8 Images Rendered with Style
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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