3

I wish to theme the error pages generated by the image module in drupal 7, I'm not sure it can be done as this is the code that runs when imagecache fails to generate a style:

else {
    watchdog('image', 'Unable to generate the derived image located at %path.', array('%path' => $derivative_uri));
    drupal_add_http_header('Status', '500 Internal Server Error');
    print t('Error generating image.');
    drupal_exit();
}

I'm not intending on having a whole themed page, but something that isn't quite as ghastly as white screen with just "Error generating image." on it. Rather at least some way for a visiting to navigate away from it and remain on the site if they wish. It would be even better if I could return a 404 instead.

This is of course, without hacking core. So anyone have any ideas or have I missed something?

2
  • Have you tried to fix the error first ? Do you know what is causing this in the first place ?
    – tostinni
    Nov 13, 2011 at 0:25
  • The error is beyond my control. It happens when someone comes to the site from google image search, the image is still indexed by google, but has been removed from the site. So clicking "Full-size image" from the right sidebar in the overlay results in "Error generating image" and what should appear as the image in the image overlay when you arrive at the site from image search is also sometimes "Error generating image" though it is unpredictable. It also bothers me that google is being fed error 500's when the image no longer exists so it should be a 404.
    – Phizes
    Nov 13, 2011 at 10:50

1 Answer 1

3

You can't.

This is hardcoded in http://api.drupal.org/api/drupal/modules--image--image.module/function/image_style_deliver/7.

You would need to completely override this page callback to change what it does. You could do this with hook_menu_alter() but that means that you would need to make sure that you also apply any upstream changes to that function to your own copy.

Can't you just leave the images there instead of deleting them? And if they are just a temporary resource, maybe exclude them from search with robots.txt?

2
  • I had realised it was hardcoded but I thought I had missed something as this is one limitation I have run into with Drupal. I think I will go with hook_menu_alter() then.
    – Phizes
    Nov 15, 2011 at 7:47
  • Missed the 5 minute comment edit mark, robots.txt is out as the images should be indexed and blocking 3 styles per 4 - 8 images on a daily basis would be a huge robots.txt, the particular site is a proving ground for methods I am interested in using but which lack personal production environment experience, so it already consumes more than it's "fair" share of time. Not removing them is also out as the site owner uses it as a catalogue of the best images they wish to keep organised.
    – Phizes
    Nov 15, 2011 at 8:09

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.