I have created an Image style which I am applying in my Blog view. But the Images are not generated in the Blog View Image folder and hence it is not showing up because of the path issue.

sites/default/files/blog/images/testing.jpg - This is the path where my images are getting stored.

sites/default/files/styles/test/public/blog/images/testing.jpg - This is the path generated from my view.

Adding "$config['image.settings']['allow_insecure_derivatives'] = TRUE;" in settings.php solves my issue. But I prefer not to use this because of security risks.

Also, there are no PHP errors that I can notice.

Please suggest to me how the issue can be resolved.

  • Welcome to Drupal Answers! 👋🏿 How did you upload/store the original images? How did you configure the image style? And how did you configure the view to display it? Please update your question and add the exact steps that need to be done to reproduce this issue. Many thanks
    – leymannx
    Nov 18, 2020 at 8:28
  • Verify that your folder sites/default/files/styles have the good owner and group (www-data) see cyberciti.biz/faq/…. If it's not the case cd sites/default/files/ and sudo chown -R www-data:www-data styles and check that the folder is writable for the group. If it's not the case sudo chmod -R g+w styles
    – MacSim
    Nov 18, 2020 at 14:11

1 Answer 1


Maybe you're trying to create the URL to the image style by string manipulation? There is a security check in place to ensure that image derivatives can't be used to DDoS (distributed denial of service) your site - basically spamming your server with image style requests.

Drupal core's Image module allows for the on-demand generation of image derivatives. This capability can be abused by requesting a large number of new derivatives which can fill up the server disk space, and which can cause a very high CPU load. Either of these effects may lead to the site becoming unavailable or unresponsive.

For this all image style URL's now require a token in the query string in the form of sites/default/files/styles/test/public/blog/images/testing.jpg?itok={token} (note it's the itok querystring in the end).

You need to create the image style URL through various formatters or class methods provided in order to get a URL with the security token, otherwise you will get access denied on any URL without the itok. If you're using Views, then for the Image field in your view change the Formatter to "Image Style" and choose the style in the view's config.

To do this from code, you should use the ImageStyle entity to generate the URL's, which give you the URL with token as well. If you have a $file file entity or just a file URI string you can generate it like this:

$style_name = 'test';
$style = ImageStyle::load($style_name);
$file_uri = $file->getFileUri();
$image_style_url = $style->buildUrl($file_uri);

or single line:

$image_style_url = ImageStyle::load('test')->buildUrl($file->getFileUri());

See also: Drupal 7.20 release notes where this change happened.

  • Here the original Image is getting created with the path sites/default/files/blog/images/testing.jpg But the cropped Image (Image of applied Image style) is not getting generated. But the path is getting created sites/default/files/styles/test/public/blog/images/testing.jpg Please provide more clarity on the above Answer Nov 18, 2020 at 12:56
  • @lakshmiHS added more info
    – Beebee
    Nov 19, 2020 at 12:07

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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