Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
We noticed that we were having a massive performance hit when our external images used an uppercase file extension (.JPG, .pNg ...) or used the .jpeg extension. As it turns out, these images were failing an extension test in imagecache_external_generate_path() function and were causing extra hits on the imagecache_external_fetch() function rather than serving the cached image.
<?php
if ($extension = pathinfo($url_parameters['path'], PATHINFO_EXTENSION)) {
if (in_array($extension, array('jpg', 'png', 'gif'))) {
$filename .= '.' . $extension;
}
}
?>
The solution was to modify this extension test to permit these variants on the file extension:
<?php
if ($extension = strtolower(pathinfo($url_parameters['path'], PATHINFO_EXTENSION))) {
if (in_array($extension, array('jpg', 'jpeg', 'png', 'gif'))) {
$filename .= '.' . $extension;
}
}
?>
Patch attached.
Comment | File | Size | Author |
---|---|---|---|
#1 | imagecache_external-uppercase-file-extensions-2502379.patch | 670 bytes | Paul_Gregory |
Comments
Comment #1
Paul_Gregory CreditAttribution: Paul_Gregory commentedComment #2
swentel CreditAttribution: swentel commentedWe should also default to an extension as well IMO.
Sometimes external uri's don't have the extension and you basically will download the images every single request.
Comment #3
Paul_Gregory CreditAttribution: Paul_Gregory commented@swentel That sounds fair but don't forget the strtolower() I put in my patch in the first place.
Comment #4
swentel CreditAttribution: swentel commentedYeah sorry about that, that was actually code directly from a patch that I'm running local :)
Comment #6
BarisW CreditAttribution: BarisW as a volunteer commentedLooks good to me. Thanks, both!