Use Apache mod_rewrite to redirect image requests through ImageCache
Imagecache is an extremely useful Drupal module. It is especially useful when you want to ensure that images on your site do not wreak havoc on your customized themes and layouts. Fortunately, Apache's mod_rewrite module comes to the rescue.
- The first step is to create a new present in the ImageCache UI that will scale and crop your images as needed. Simply visit admin/build/imagecache and add a new preset.
- Give your new preset a name in the Preset namespace. Something such as "full" or "default" should be appropriate.
- In the Edit Preset dialog, add new actions as appropriate. For a simple solution, add a scale preset.
- Enter an appropriate value in the width field of the next dialog. If necessary, add a height value as well. Make sure that you do not enable Upscale unless you want user pictures in comments and the such to be blown way out of proportion.
- Once you have added the scale action, choose Update Preset to save your new preset.
Now that we have a proper preset, we can continue to the mod_rewrite configuration to put this preset to use. Edit your .htaccess fill and add the following lines just before the final series of RewriteCond and RewrtieRule entries:
RewriteCond %{REQUEST_URI} \.(jpg|png|gif)$
RewriteCond %{REQUEST_URI} !imagecache
RewriteRule ^system/files/(.*)$ index.php?q=system/files/imagecache/<name of preset>/$1 [L]
When adding these lines, make sure you replace the <name of preset> with the name of your imagecache preset. Save the .htaccess file and you are all set.
Comments
Post new comment