The error is coming from Image module (core) and the logic looks like:
$success = file_exists($derivative_uri) || image_style_create_derivative($style, $image_uri, $derivative_uri);
if ($success) {
$image = image_load($derivative_uri);
file_transfer($image->source, array('Content-Type' => $image->info['mime_type'], 'Content-Length' => $image->info['file_size']));
} else {
watchdog('image', 'Unable to generate the derived image located at %path.', array('%path' => $derivative_uri));
...
}
Therefore error happens when Drupal has problem with generating an image derivative by applying all image effects and saving a cached version of the resulting image.
The easiest way reproduce the problem (for diagnosting purposes) is by drush.
Invoke image_style_create_derivative() directly from drush:
drush -v eval 'image_style_create_derivative(reset(@image_styles()), "public://pictures/picture-123.png", "public://styles/test/test-success.png");
Replace picture-123.png
with the existing picture from the log:
Unable to generate the derived image located at public://styles/foo/public/pictures/picture-x.png
Or use any other existing one, e.g. drush sqlq "SELECT * FROM file_managed"
.
If you don't have access to shell, use Devel module, go to /devel/php
and paste the PHP code there.
Note: If the files
folder is owned by Apache user, you should log-in as this user for testing purposes. Otherwise prefix your drush command with sudo -u www-data
.
There are the following possibilities.
- Above test has been successful (file has been generated successfully in your files dir), if so, check if your failing picture from the log actually exists, maybe it was removed from the server.
- If you have the same error message or the file wasn't created, then it's problem with your permission or missing libraries (check:
drush eval "print_r(gd_info());"
).
- If you don't have any error and the file wasn't created, then check if you used the right existing files.
Debugging permission problems can be easily achieved by strace
. Install it and just prefix any command that you're testing with strace -f
(you don't have to be root).
In example:
$ strace -f drush -v eval 'image_style_create_derivative(reset(@image_styles()), "public://existing-image.png", "public://styles/test/test-success.png");' 2>&1 | grep "default/files"
mkdir(".../sites/default/files/styles/test", 0775) = -1 EACCES (Permission denied)
chmod(".../sites/default/files/styles/test", 0775) = -1 EPERM (Operation not permitted)
If you're logged in with different account which owns files
, then don't forget to prefix your drush command with sudo -u www-data
to run the whole command as Apache user.