Override function image_style_path doesn't work? I work with the S3FS module on Drupal 7.

In this module the function _s3fs_image_style_deliver of file s3fs.module call the function image_style_path in that line :

$derivative_uri = image_style_path($style['name'], $image_uri);


This function comes from drupal core module image.

I need a way to override this function or the function _s3fs_image_style_deliver from s3fs module.
If someone have an idea ?

Thx :)
I find a way to modify/rewrite the url for each files image style with s3fs module for amazon S3.
It's not really easy to explain, but it work, so i try :

In module s3fs :

Edit file S3fsStreamWrapper.inc line 310 in function getExternalUrl
line 331 replace :

if ($path_parts[0] == 'styles' &amp;&amp; substr($s3_key, -4) != '.css') {


by :   if (substr($s3_key, -4) != '.css') {

This will stop checking whether the first path element is the 'styles' folder.

Line 337 replace:

array_unshift($path_parts, 's3','files');

by : array_unshift($path_parts, 't','f','s');

The listening url for creating the derivatives image will be changed from s3/files/ to t/f/s in part to not signal at any time that we are working with an S3. But it's url is not show to normaly user. We can not delete these folders because Drupal expects in 4th position the name of the style like s3/files/style /your-style-name we will see later why I added a folder "s".

Edit file s3fs.module :
line 116 replace :

$items['s3/files/styles/%image_style'] = array(


by : $items['t/f/s/%image_style'] = array(

We changed the listening url in the S3fsStreamWrapper.inc file so we need to modify the listener.

In function _s3fs_image_style_deliver :
Line 206 replace :

$scheme = array_shift($args);


par : $scheme ='s3';

In the previous modification we no longer send information on the scheme. That is read normally through the s3/files url which is now t/f/s. So here we have to say manually what is the scheme.

Line 210 replace : 

if (!variable_get('image_allow_insecure_derivatives', FALSE) || strpos(ltrim($filename, '\/'), 'styles/') === 0) {


by : if (!variable_get('image_allow_insecure_derivatives', FALSE) ) {

Another line that check that in first position we have style but we change it afterwards so we change that.

Edit directly Core module image in module/image/image.module. 
Rewrite function image_style_path line 1096 :

function image_style_path($style_name, $uri) {
  $scheme = file_uri_scheme($uri);
  if ($scheme) {
    $path = file_uri_target($uri);
  }
  else {
    $path = $uri;
    $scheme = file_default_scheme();
  }
  $tabpath=explode('/', $path);
  $namefile = array_pop ($tabpath); //array_pop delete the last element of array $tabpath and put is value to $namefile
  $path=implode('/', $tabpath);

  $total= $scheme . '://' . $style_name . '/' . $path . '/' . $namefile;
  return $total;
}


The new variable $total allows to rewrite the address of the image by keeping the name of the style first so that the drupal core recognizes it. This is the final address. I did not want it to be like /styles/your-name-style/path but directly /your-name-style/path. As a result, this requires the previous changes in the derivatives creation url so that the style name is in the same location.

Save the files and create the new images for each style:
Empty the Drupal cache with command : drush cc all

And flush the old file to create the news :

Execute this dursh function and when it ask choose all :  drush image-flush

I hope it help someone !