This project is not covered by Drupal’s security advisory policy.

ImageCache Defaults detects file paths in broken images (404 errors) generated by ImageCache (D6) and Image (D7). ImageCache Defaults can either remove images with broken paths from your markup completely or replace them with a configurable default image.

This module addresses a few related issues:

  1. The intended or implemented layout of a site relies heavily on images for its structure and will break where images for content are not present.
  2. A developer wants to work locally on a site by importing a copy of a production database. She wants to avoid either importing a cumbersomely large files directory full of high res images or the lorem ipsum nonsense generated by Devel.
  3. A site administrator may be concerned that 404 errors generated by images on a production site are harming SEO efforts and wants to implement a simple fallback.

ImageCache Defaults works by analysing each image path sent to Image(Cache) to see if they are invalid (could never represent an image path) or broken (could have once been a valid image path but the file is currently missing).

ImageCache Defaults will work well without any extra configuration but provides the following optional functionality:

  • A dedicated cache table to avoid hitting the filesystem wherever possible. Highly recommended for sites with an NFS setup or large theme registry.
  • Pass cached image dimensions to imagecache to be rendered as height/width html image attributes, similar to imageinfo_cache. (only in D6, this problem was solved in D7 core)
  • Apply an extra preset/style to the default image in addition to the preset/style that would be applied to the broken image
  • Log a watchdog message for each broken file path detected
  • Remove broken images from your markup completely instead of replacing them with the default.

Installation

Add an image with "imagecache_defaults" in the name to one of the scanned directories to override the provided default image.

Directories are scanned in the following order (relative to the Drupal root):

  1. sites/[site]/files
  2. sites/all/files
  3. profiles/[current_profile]/files
  4. path/to/imagecache_defaults/images

Further configuration can be found on the "Defaults" tab of the Imagecache/Image administration page - "admin/config/media/image-styles/defaults" in D7 and "admin/build/imagecache/defaults" in D6.

Alternatives

Stage File Proxy

For an alternative way to work around broken image links, have a look at Stage File Proxy (SFP) which allows you to automatically point your broken image links at a custom url but at the time of writing it has a few limitations that ImageCache Defaults doesn't:

  • SFP doesn't check if certain files exist before replacing them so you can accidentally DOS yourself with it #1545912: stage_file_proxy should check if the file already exists, even if it's not an imagecache
  • SFP can't remove broken image tags from your page completely
  • SFP isn't recommended for use on production sites so there's an extra step in downloading, enabling and configuring it every time you reimport your production site
  • SFP doesn't log the location of broken images to watchdog
  • SFP relies on server configuration but has only been tested on Apache 2 on Mac OSX and Linux
  • SFP requires the developer to have the same relative paths to system file directories on development and production sites
  • SFP requires more configuration than simply enabling it before it starts working

Dummy image

Dummy image is very, very similar to imagecache_defaults (apologies, this module is younger!). The D6 version of Dummy image uses exactly the same approach, modifying the theme registry and wrapping imagecache, the D7 version of Dummy image preprocesses theme('image') directly. Main differences (as of April 2013) are:

  • Dummy image supports third party placeholder image providers. There is currently no plan to make imagecache_defaults support external urls for placeholder images.
  • Dummy image never caches what it discovers about the file system, it checks is_file() for every image on the page on every page load OR it replaces every single image, even those that are valid on the current filesystem. This can make it less desirable for use on production as a fallback for image 404s.
  • Dummy image (for Drupal 7) works directly on theme('image') which comes *after* image styles are applied, meaning they aren't applied to the placeholder. However it does attempt to guess the correct height/width from the image meta info, I'm not entirely sure how effective this approach is in practice.
  • Dummy image doesn't seem to have any test coverage, and multiple unresolved bugs in the issue queue that are over 6 months old.
  • Dummy image (for Drupal 6) doesn't work as hard to preserve existing theme wrappers around imagecache to avoid conflicts with other modules.

Known Limitations

Image(Cache) Defaults only intercepts images that are processed by ImageCache or Image. There are a few images in core of Drupal (like user profiles) that aren't run through ImageCache by default but they can always be configured to do so (http://drupal.org/project/imagecache_profiles for example).

This is intentional (see #1696440: Integrate with core's theme('image')) and there are currently no plans to support a blanket shiv of images into every image tag generated by theme('image'). If you need placeholder images for absolutely everything try http://drupal.org/project/dummyimage.

If you're writing custom code where you call theme functions directly like theme_image_style() instead of calling theme('image_style') then you are bypassing the Drupal API and so this module won't work until you update your code.

Maintenance Status

The D6 branch is not accepting new features, bugfixes only. The current recommended version says "beta" but there are no known bugs in it.
New features will be added to the D7 branch.
There will be a D8 branch added around the time #1898420: image.module - Convert theme_ functions to Twig is resolved.

Project information

Releases