Skip to content

Instantly share code, notes, and snippets.

@googletorp
Last active September 6, 2015 12:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save googletorp/6d4dc3fb9fc20a716f58 to your computer and use it in GitHub Desktop.
Save googletorp/6d4dc3fb9fc20a716f58 to your computer and use it in GitHub Desktop.
Set height/width on responsive images
<?php
/**
* Implements hook_preprocess_responsive_image_formatter().
*/
function theme_preprocess_responsive_image_formatter(&$variables) {
$item = $variables['item'];
$height = $item->get('height')->getValue();
$width = $item->get('width')->getValue();
if (!$variables['responsive_image']['#width']) {
$variables['responsive_image']['#width'] = $width;
}
if (!$variables['responsive_image']['#height']) {
$variables['responsive_image']['#height'] = $height;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment