The function:
/**
* Copy of image_style_path() for use with remote images.
*
* When image_style_path() is give a file like 'http://example.com/image.png'
* it is converted into 'http://styles/stylename/http/example.com/image.png'
* which will fail image_style_deliver().
*/
function remote_stream_wrapper_image_style_path($style_name, $uri) {
// Force the image style to be returned with the default file scheme, but
// with the file's original scheme in the path.
return file_default_scheme() . '://styles/' . $style_name . '/' . file_uri_scheme($uri) . '/' . file_uri_target($uri);
}
Builds too many subdirectories, and they hare hard to manage and maintain.
I would prefer to use only the file_default_scheme() . '://styles/' . $style_name and then prepend file_uri_scheme($uri) converting slashes into something else to preserve the file name unity.
If you are not considering this an option, can i modify the code here for my site and it will work?
Comments
Comment #1
egarias commentedPlease, any help?
the paths created by the images are:
imagepath/http/site.com/xxxx/xxxx/xxxx ...
wouldn't it be better to reduce such paths??
Comment #2
egarias commentedI have no feedback but I will put an example:
This is one of my images paths:
<img typeof="foaf:Image" src="http://mysite.com/sites/default/files/styles/large/http/www.vilaweb.cat//media/continguts/000/034/282/thumbnails/thumb_474__4.jpg" width="474" height="320" alt="">Wouldn't it be better to have:
http/www.vilaweb.cat//media/continguts/000/034/282/thumbnails/thumb_474__4.jpg
replaced by something like
Thanks, and waiting for some feedback, I am trying to make some patches but can find the solution
Comment #3
helmo commentedI got bitten by this, a remote site with dirty( not clean :)) url's. e.g.
This caused the creation of a directory for every file. Calling the image 'maxwidth_288' in every directory :)
The resulting watchdog errors were a bit misleading...but acurate.
A test on the shell gave me more info:
Explanation: http://superuser.com/questions/298420/cannot-mkdir-too-many-links)
I've attached a (hackish) patch that rewrites the path to avoid this issue.
The side effect is though, that my html still contains links to the dirty derivative path on my own server. So the check in .htaccess to see if the literal file exists no longer works.
I hope that this inspires someone to come up with a better solution.
Ideas:
* Could we just sha sum the path
* Could we just use the fid
Comment #4
clemens.tolboomThe report of @egarias is about the tree too deep.
While @helmo reports about to many directories on the same level.
Changing the Drupal path for a remote image does not help as the manage file table (must) contain the remote URI and is used by ie media module to generate an image url. Setting a display style uses the remote URI to generate the path to the derived image.
So the question to be answered too is can we adjust
to generate a better path for remote images.
Is this a chicken and egg problem?