Download & Extend

Imagecache External

About

Imagecache External is a utility module to allow you to use imagecache(D6)/image derivatives (D7) with external images.

Dependencies (D6)

Image cache (obviously)
Drupal 7 version requires the core image module.

Installation

Extract the module to sites/all/modules or sites/xx/modules depending on whether or not you have a multisite installation.
Enable the module at admin/build/modules or using drush

Configuration

The module's default configuration is very restrictive.
Excluding admin user or users with the 'Bypass black/white list' permission - the default configuration of the module is to deny all requests to fetch external images.
So to get the module to work, you need to visit admin/settings/imagecache_external and either:

  • Add some domains to the whitelist -or-
  • Switch the mode of operation from whitelist to blacklist

Usage instructions

Drupal 7

Usage is simplified in Drupal 7 as follows:

<?php
 
print theme('imagecache_external', array('path' => 'http://larsjung.de/h5ai/sample/screenshots/h5ai-v0.7-icons.png', 'style_name'=> 'thumbnail'));
?>

Thanks to manu manu for the D7 port.

Drupal 6

Usage varies between version 6.x-1.x and version 6.x-2.x.
Version 2 produces less server load as previously generated imagecache derivatives are served without a full Drupal bootstrap.
Instructions for Version 6.x-1.x
Instructions for Version 6.x-2.x

Usage instructions version 6.x-1.x

Once you have either added domains to the whitelist or switched the operation mode to blacklist you may use the external images as follows:

<img src="/external/presetname/www.somedomain.com/someimage.jpg" alt="Image description" />

OR
<img src="/external/presetname/http://www.somedomain.com/someimage.jpg" alt="Image description" />

Where presetname is the imagecache preset you wish to use for the fetched image.
Note that the modules does not store the files in a folder called external, this is a menu callback. The files are physically stored inside the files folder (in a sub-folder called externals).
Url encoding

If your image url contains a query string or other url sensitive characters, you'll need to url encode it (eg instead of ? use %3F).

How it works - Version 1

The module accepts all of the elements of the path after the 'external' as an argument.
It uses the first one as the presetname and implodes the rest, adding a http:// if needed to generate the url to fetch.
It then compares the url to the whitelist/blacklist and takes the appropriate action.

Instructions for Version 6.x-2.x

Version 2 works differently to version 1 - to generate your image urls, use the utility function imagecahe_external_generate_path as follows

<?php
$image_url
= imagecache_external_generate_path($url, $preset);
?>

Where $url is the url to the actual image on the external server, $preset is the imagecache preset name. The return value is a url suitable for use in your code. If the image does not exist or the user does not have appropriate permissions, this function will call drupal_not_found (404 error) or drupal_access_denied (403 error) respectively.
Embed your return value as follows:
<img src="<?php print $image_url;?>" alt="image description" />

Note that this function handles the actual fetching of the external image when you call it so you need to ensure the user has the appropriate permissions. The advantages of this version are that it does not rely on a full Drupal bootstrap just to serve a previously generated imagecache derivative.

Permissions

The module provides various permissions - most importantly

  • View external images
  • Fetch external images

If you're not getting the expected results for anonymous users, make sure you have these set the way you need them.
For an external image to be used with imagecache, it has to be fetched and cached at least once. If the image has not been fetched and the requesting user does not have the 'fetch external images' permission, then it won't work - the image won't be fetched (in fact a 403 error will occur).

Other notes

Images are fetched using drupal_http_request so if your server is not configured properly (view the status report) this won't work.
Images are stored in the site's files folder in an external subdirectory.
You may flush the fetched external images (note that this does not flush the generated imagecache files) by visiting admin/settings/imagecache_externals/flush.

Downloads

Recommended releases

Version Downloads Date Links
7.x-2.0-beta1 tar.gz (9.45 KB) | zip (10.47 KB) 2012-Apr-01 Notes
6.x-2.0-beta2 tar.gz (7.73 KB) | zip (8.78 KB) 2011-Mar-12 Notes

Other releases

Version Downloads Date Links
6.x-1.1 tar.gz (7.84 KB) | zip (8.88 KB) 2010-Nov-23 Notes

Development releases

Version Downloads Date Links
7.x-2.x-dev tar.gz (9.46 KB) | zip (10.47 KB) 2012-Apr-02 Notes

Project Information


Maintainers for Imagecache External

  • larowlan - 4 commits
    last: 1 year ago, first: 2 years ago

Issues for Imagecache External

To avoid duplicates, please search before submitting a new issue.
All issues
Bug reports
Statistics (2 years)
New issues
Open bugs
Participants
nobody click here