Skip to content

Instantly share code, notes, and snippets.

@MattFielding
Created February 11, 2013 14:14
Show Gist options
  • Save MattFielding/4754629 to your computer and use it in GitHub Desktop.
Save MattFielding/4754629 to your computer and use it in GitHub Desktop.
Responsive images in Drupal. The height and width attributes need removing from the <img> elements and we need to add a little CSS to allow the images to scale correctly
img {
max-width:100%;
height:auto;
}
<?php
// remove height and width attributes from images
// replace THEME with the name of your theme
function THEME_preprocess_image(&$variables) {
$attributes = &$variables['attributes'];
foreach (array('width', 'height') as $key) {
unset($attributes[$key]);
unset($variables[$key]);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment