8

Today I uploaded my site to the server, and I get errors like the following:

Unable to generate the derived image located at public://styles/sponsor_image/public/TerraThermaSponsorLogo.png.

Image styles cannot generate images. I have tried to set permissions on styles/* folders with chmod -R 775 styles/, and even tried chmod -R 777 styles/. The folder's owner is OK. I don't get what can be wrong.

The directory associated with public:// is sites/default/files, and it is OK.

5

Briefly, this is what I do whenever I have this problem:

Change user to the one running your web server (apache, httpd, www-data, nginx etc)

sudo -u [user] -s /bin/bash

and cd directly to the files directory, and try to write random data to a new file.

echo "Random text" > some_file_name

Usually this will fail and you'll get an error message from the OS, moving the problem out from Drupal at least. If this fails to work, you have file permissions issue. This question may be helpful: What are the recommended directory permissions?

  • yep you are right, i cannot write anything :/ – Petro Popelyshko Dec 18 '12 at 15:16
  • 1
    Then you still have a file-system level permissions problem. A guess is that you have directories closer to the root that the web server is not allowed to write to. That's the topic for some non-drupal forum however, as we now have all kinds of filesystem and operating system specific issues to deal with. You at least know the issue is not in Drupal now. :) – Letharion Dec 18 '12 at 15:27
  • I can write something as www-data, but I still get the error. What else do I do? ImageMagick is configured correctly, I'm running this on a server that has many Drupal installations. – nnyby Aug 28 '14 at 17:07
  • @nnyby At that point, I'm not actually sure what do to next. The only thing left I can think of then is to start digging in the source code where the error occurs. – Letharion Aug 29 '14 at 13:37
  • I solved the issue -- it was that the image files Drupal was looking for didn't actually exist, and the error message was misleading. – nnyby Aug 30 '14 at 15:05
9

You should also make sure you do have a graphical library (like php-gd) installed on your server: check /admin/config/media/image-toolkit (D7).

  • 1
    After migrating to another server I got this error, Of course I forgot to apt-get php5-gd ;-) – TheSquad Jan 7 '14 at 0:01
5

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.

  1. 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.

  2. 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.

3

This can also be caused by PHP being compiled without libjpeg (if the images that won't generate have jpeg sources). Check the output of gd_info() to see if there is PHP support.

  • 2
    to quickly print from command line: php -r 'print_r(gd_info());' – latvian Mar 27 '14 at 23:56
  • This was definitely my issue. (And thanks @latvian for the quick cmd ref.) – trimbletodd Aug 18 '14 at 23:57

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.