Search code examples
phpdrupaldrupal-7image-resizingdrupal-theming

How to Remove Image Resizing in HTML


I'm not sure if this website is re-sizing images via HTML, or if the image size is automatically added to the code.

If the images are being re-sized, this would need to be fixed, because it slows page load times.

Here is an example page.


Solution

  • You will need to override default theme_image and remove width and height properties, or set their values to auto.

    Example:

    // In your theme's template.php file
    function [YOUR_THEME]_image($variables) {
      $attributes = $variables['attributes'];
      $attributes['src'] = file_create_url($variables['path']);
    
      foreach (array('alt', 'title') as $key) {
        if (isset($variables[$key])) {
          $attributes[$key] = $variables[$key];
        }
      }
    
      return '<img' . drupal_attributes($attributes) . ' />';
    }