On Drupal 7, I have added a drupal_alter on the image_style_url file in order to be able to remove itoks. My idea was to offer a hook that allow to alter the image styled url without modifying the original behavior of the image module.

As a file_url_alter hook (thrown by the file_create_url function) exists and, on the image_style_url function, the unique action made after the file_create_url call is the add of the itok, the main aim of my new hook is to offer the ablility of itok's removal.

With that call of Drupal alter, just create a module that catch my new hook and remove the itok :

function itok_fix_image_style_url_alter(&$file_url){
  if(strstr($file_url, '?itok=') != FALSE){
    $exploded_itok = explode('?itok=', $file_url);
    $file_url = $exploded_itok[0];
  }
}
CommentFileSizeAuthor
image-alter-image-url_1.patch629 bytesjulien_g
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

tstoeckler’s picture

Title: New hook for styled image url - itok removal » Introduce an alter hook for image_style_url()
Version: 7.23 » 7.x-dev
Issue tags: +Performance, +Needs benchmarks
Related issues: +#1934498: Allow the image style 'itok' token to be suppressed in image derivative URLs

This needs benchmarks to measure the performance hit this would cause.

Also re-titling, as the itok removal is being handled in #1934498: Allow the image style 'itok' token to be suppressed in image derivative URLs and it seems that has good chance of hitting core.

julien_g’s picture

Status: Active » Closed (outdated)