I believe it has happened after recently my webhost did some maintenance ; but also - I was lazy with updating last 2 weeks; but earlier it was working.....

so - when I upload an image in Article Edit - no images appears. and probably they are not produced, I couldn't find in file folder....

I had all image styles set like Large, medium, small, this and that....nothing....

what should I check now? (and hosting is shared)

Comments

Stefan Lehmann’s picture

Check: admin/reports/status

It's probably just file permissions in your public files directory. The webserver must be able to write into all the folders inside that directory.

I like cookies!

cmsMinds’s picture

Hi ZambalaRed ,

If you Give 777 permissions to sites/all/default/files folder then it works fine.. and also check whether your style is created or not in this path sites/all/default/files/styles
I hope this will work perfectly.

Thanks.

Stefan Lehmann’s picture

If you Give 777 permissions to sites/all/default/files folder then it works fine..

Sorry, but this is a very naive approach of setting file permissions and I have seen it far too often to let it pass uncommented. Especially the last '7' almost never makes sense in any scenario whatsoever. Here is a guide to setup proper file permissions / ownership for a webserver running Drupal.

Just as an example. All of our websites, which had setup proper file permissions during the Drupageddon last year were basically immune against code changes and therefore there was no danger of the whole server being compromised, whilst all the websites with "lazy" file permissions gave us quite some headaches. :-)

I like cookies!

ZambalaRed’s picture

Indeed, it is not so easy;

I am still reading this, but I believe they have something server side about security....

So, a few days back hosting support where trying to play around with this for a good while and told me they have made some fix; later on they said - sorry, we just added fix for PNG and now we added fix for JPG too....

- and I checked, it was working at the moment;

- now, after a few days I am updating again, and it doesn't work again....and now waiting for support...

But earlier it was working all the same for 1 whole year....but they did some server maintenance and not anymore...

Krishna Mishra’s picture

See is GD library is installed or not here Check: admin/reports/status, if not install GD library on server.

Denes.Szabo’s picture

On my new server I needed to add 775 to my redefined tmp directory ($conf['file_temporary_path'] = '/home/mysuer/tmp';), seems PHP could not write to this directory.

So, just check the tmp directory access rights too.

--
Denes Szabo - http://internode.hu

allysin’s picture

I am having the same error on a Drupal 8.0.1 site. Image styles are not applied to a node or in a view. However, I see them applied to during view preview.

Any idea how to solve this?

yuseferi’s picture

I check permission and permission of folder is 775 and it is Ok. but image styles in views preview not generated, I look at the path, the file not generated also when I check Drupal recent log just see image not found.

I have be born to be mankind

melow’s picture

I have the same error on a Drupal 8.1.7 site... On my local website, I haven't the problem, it's just online.
I've check any permissions.

Someone found a solution ?

Thank for help

atul_shin’s picture

Hi Drupalers,

Posting on this forum with hope someone can provide insight about the Drupal thumbnail creation i.e. image styles. I am using views to display image thumbnails on the pages. The directory permission i.e. for /sites/default/files/ is writable and have even tried 777 but thumbnails are not created for few new records generally. the behavior is inconsistent and not acceptable on site.

Its very strange issue and need to know how it all works. The image thumbnails using styles do appear but not as soon as images are uploaded. Image style thumbnails start appearing after some time which can be few days as well.

Questions:-

1. When are style related thumbnails supposed to created? When page is accessed or images are uploaded in the content ?

2. In case of Views how does this happen ?

3. What can be possible reasons for this issue ?
Few of the reason I can think are:-

  • file permissions (which is not the case in my case as permission is set to 777 ).
  • htaccess

file settings

I have gone through a lot of documentation and nothing seems to help. Its better to understand the functioning of this.

Thanks very much for any help

VM’s picture

as the thread is old and in reference to D7, I suggest a new thread.

IIRC image styles are generated on request. Though I don't know if this changed in D8. Drush has a generate command that may be worth looking at.

also of note: Rules Image Styles & Image Style Pregenerate modules may aid.

atul_shin’s picture

I had suppressed image token appending to image URL by adding a line of code to settings.php. It did suppress the token but thumbnails also stopped generating. So I had to revert back and again not all images are being created.

Anyway thanks for your comment but both the modules you mentioned are not ported to D8.

VM’s picture

The modules I mentioned align with the version of the thread (may not aid you but may aid others like you that find this thread for D7). For D8, try drush generate as mentioned.

atul_shin’s picture

Hi VM,

I worked more on this and now image styles are being generated. The source code of images is like /path-to-image/img.jpg?itok=cJsLb4Qr but problem is that not all images appear on first load of page. I have to ctrl +f5 many times to get the images on page. This can not be acceptable from end users perspective.

How do you suggest to deal with this ?

Thank a lot for your support. I really appreciate it.

whop’s picture

I finally got working preview in styles setting. In folder is now created styles subfolder, with test thumbnail.
But when working with files, it doesnt work.
I have files on private, next to www, so ../something is set as path.
Files are visible in content if format is original.
but whenb choose thumbnail, doesnt work.
can you help me?
i think I have correct rights and www-data everywhere.
thank you!!

taes_rvr’s picture

Your file permissions in your sites/default/files directory should be set to 775. If so and your site is still not generation image styles, try delete the .htaccess in sites/default/files. Refresh your site so Drupal rebuilds it. Hopefully that will help...

whop’s picture

thanks.
I have reviewed rights and owners of whole structure, and it works now.
strange that for drupal7, different setting was working....anyway, its ok now

f1mishutka’s picture

  • create sites/default/files/styles folder manually
  • set its permissions to 775
  • create .htaccess file with following content:
<Files *>
  SetHandler none
</Files>
smfsh’s picture

I can echo that this worked for me as well...

This feels really broken though. This seems to be overriding the security handlers that Drupal has in place for this directory.

smfsh’s picture

For my issue specifically that was resolved with this htaccess hack, the actual problem ended up being that mod_rewrite was not enabled for the Apache build hosting the code. Because mod_rewrite wasn't enabled, Drupal couldn't redirect to the appropriate call to generate the image.

phannphong’s picture

This way working. Thanks

Richard15’s picture

For me too, Drupal 7

vija’s picture

Unfortunately it hasn't worked for me...
Is there any way to force drupal 8 to generate these images?
My problem is, that sometimes they are being generated, sometimes not, sometimes after visiting the page for many times

russellt’s picture

Drupal 8.2.2
My problem was that a custom content type, which included text fields and an image upload field, would not create or show the image thumbnail on the form after a user browses for an image and selects it for upload. After a crazy amount of searching for clues, following f1mishutka’s idea, I commented out the SetHandler reference to SA_2013_003 in the sites/default/files .htaccess file, and added a SetHandler set to ‘none’. Then cleared cache.

After that, the file upload thumbnails were generated and visible . Then I uncommented the SetHandler reference to SA_2013_003 and commented out the SetHandler ‘none’ setting. (So, back to the original settings) – and the thumbnails now show up when a file is uploaded.

Can’t say I really understand why.

(My first comment on d.o - Invaluable community)

bhupendra_kanojiya’s picture

+1, Above suggested solution worked for me

kanaan.ngutu’s picture

This is working but I am not sure why the files are not even created inside the image style folder.

robertoperuzzo’s picture

It works for me too.

wazzzaonthebeat’s picture

Got mine working with this advice! Thank you!

ec-adam’s picture

I'm running 8.1.9 and all image styles are broken (drupal default and my custom styles). All images work perfectly if the style is set to None (original image).

All sites/default/files and files/styles and accompanying subfolders are set to 775 and all have .htaccess folders with the following:

SetHandler none

Permissions and the htaccess thing are the only possible solutions I've found after several hours of googling. Neither solutions have worked for me.

golubovicm’s picture

Had the same issue. Instead of generating thumb in some image style I was redirected to home page. Then started turning modules one by one and found that Domain access Locale is causing this. Later found that bug is already submitted:

https://www.drupal.org/node/2573879

And comment #11 did the trick form me! Hope it will help someone.

vija’s picture

are you talking about drupal 7 or 8? How to apply this to drupal 8?

sachinsuryavanshi’s picture

Hello,
For Drupal 7/8, set media files permission to 755 and Broswer will render them correctly.

Hope it will help.

golubovicm’s picture

This issue caused by SMTP module is for Drupal 7 only as far as I know. Didn't use D8 much so far. But anyway, it's possible that some other module is causing the trouble so turning them off temporarily and checking won't hurt.

Mohammed Nur’s picture

This has happened to me many times when moving a site from dev server to live server. The problem is always caused by file permissions in the sites/default/files folder.

Hope this helps.

ktobiasson’s picture

Hi, I'm usually more of a reader than a poster because almost all problems have a solution already, but this problem seems to be lagging on without any solid answers. While this isn't exactly a super solid answer because I don't know the exact cause of the problem and I did a few things and it could have been a combination of them or just the last thing that I tried.

If you have the Devel module installed, clear the cache using the module. ( Press the Devel tab in the toolbar and then select the "cache clear" tab that pops up in the toolbar below ). Clearing the cache using Devel was the last thing that I did and I think it would be best to just do this first instead of changing all folder permissions to 777, which is what I did first off and I didn't have luck after I just changed permissions and cleared the browser cache, but using Devel cache clear worked for some reason..

I don't think that my folder permissions were poorly set, but I was grabbing at straws.

I am developing using Dev Desktop on a local machine in Google Chrome and in developer mode and I have the cache disabled so I don't understand why I had to clear the cache. On top of that, just for more straw grabbing, I tried clearing the cache in the browser like I said above before finding the "cache clear" option in Devel, and it didn't work. Maybe Devel performs extra steps while it clears the cache. I don't know because I'm quite new at developing and ultra new at Drupal. Maybe someone shed some light on that.

Anyhow, I hope this helps someone because I was searching for an answer with no luck for a while.

ec-adam’s picture

Thanks for the awesome suggestion about devel cache clear. I can confirm that this does work, although I am not sure why you have to do ti this way rather than just through a regular cache clear or drupal cr all.

I will also note for other people running into this, that if you change your file permission as suggested by previous comments BEFORE you create any custom image styles you have a much better chance of avoiding those style being broken. Changing permission afterwards did not fix the issue for me until I cleared devel cache.

anthonyf’s picture

ktobiasson, the Devel Cache Clear worked for me on D8 (Acquia Lightning 8.x-2.13-core) - thank you! The other suggestions about changing file permissions or .htaccess settings did not work in my case. And those did not really make sense because the image style directories were being populated automatically for awhile, and then just stopped working one day. Not sure what changed.

paperscenery’s picture

Thanks @ktobiasson for this solution! Like several other people who have commented, this issue arose suddenly for me after checking out site from Acquia Cloud to local Dev Desktop—all had been working 100% correctly over the course of many push/pulls of the codebase, then suddenly no thumbnails, no image styles generated.

I tried every singe permissions and .htaccess solution proposed above and none of them work for me.

I do not even use the Devel module, but I installed it and simply cleared the cache as suggested... and image styles are all working fine once more. Such a bizarre issue—no Drush cc, cr, or if would resolve it, but Devel Clear Cache did. If anyone who is more familiar with Devel comes across this, maybe they can suggest what it's doing that we could use as reference to fix this issue.

Thanks again to @ktobiasson and all other commenters for the guidance on this.

riannuzzi’s picture

I searched high and low for a solution to this problem. I finally came across this, and Devel cache clear immediately solved the issue.

abbym’s picture

This worked for me after trying at least a dozen other seemingly logical but complex solutions. Thanks for sharing!

hectorplus’s picture

I had the same issue, but this trick did it for me too!

revoltpuppy’s picture

Incredibly, this worked for me, too. I couldn’t tell you why, but going to (Admin bar)/Configuration/Development/Performance and clicking the “clear cache” button worked a treat. Thanks for taking the time to post!

maskedjellybean’s picture

+1 for this solution. I don't understand why but it worked immediately. In case this is relevant I am also using Acquia Dev Desktop.

Strangely the images do not appear in the directory itself but they do load in the browser. None of this makes any sense at all.

Andrew211’s picture

Try popping this in your settings.php
Ditch itok

$config['image.settings']['allow_insecure_derivatives'] = TRUE;
$config['image.settings']['suppress_itok_output'] = TRUE;
HongPong’s picture

the allow_insecure_derivatives line worked for me when there were forbiddens and I knew the permissions were okay.

hectorplus’s picture

This issue depends on the hosting, tested it, i got a hosting with namecheap and works fine no changes to the settings, then we have another account with x10 hosting, here with them, i have this issue!! Folders are not being created on the fly, permission denied & so on.

Jeff Veit’s picture

As this comment seems to be the top hit for "Drupal 8 image styles not created", let me add that styles are created by a call from Drupal to itself. As this is an internal call, there's no need for https. In my case, I had been messing around with http2, which works over SSL - so it's encrypted - aka https. While I was doing this I broke the plain old http of my webserver, and bam!, image styles broke. As did image and media uploads.

morleman@gmail.com’s picture

It was permissions of the var/www/sites/default/files/styles folder. I tried to clear the cache with Devel as suggested above but no dice. When I updated the permissions of the folder images showed. So if your running a dev environment behind a firewall and just simply want to get something up and running then chmod 777 -R the styles folder. Otherwise if prod... then a more secure solution will need to be introduced.

dman’s picture

I was continually running into this in D8 for the last year, I think I finally found what made it go away.

Using Acquia Dev Desktop,
This tool creates a *symlinked* alias from sites/my.site.dd/ to sites/default/ - which means *most of the time*, most things work.
However, when accessed via the web, half the site *thought* that my site name was my.site.dd, and would generate URLs to /sites/my.site.dd/files/styles/medium/img.jpg
This would NOT WORK and the image would not be generated.
I would get mixed results when using drush, as drush may or may not recognise the site id depending on the context I was in when I called it.
...and, um , never mind...

LONG STORY SHORT:
My problems went away when I added

$settings['file_public_path'] = 'sites/default/files';

to my settings.(local).php.

ALSO a solution, was correctly updating my /sites/sites.php alias array to include the

$sites['my.site.dd'] = 'default';
chamilsanjeewa’s picture

I am using PHP7,drupal 8 in apache RHEL still I have same issue

UnsettlingTrend’s picture

I'm running PHP 7, D8 and CentOS. I tried rolling back to PHP 5.6, and my sites were still experiencing the issue.

It seems to be limited to files in the private file system though.

chamilsanjeewa’s picture

Looking at watchdog messages I fond that thumbnails are not generated due to pgpGd error, since I was manually install the php in RHEL it was fix by configuring phpGd with php and jpeg support.
http://php.net/manual/en/image.installation.php

drup16’s picture

@dman, Settings the file_public_path variable as you suggested worked for me. 

karolus’s picture

And, going further down this line:

I recently relaunched a site (D7 to D8) where I was using Capistrano deployments, and shared folders, such as sites/default.

Naturally, I went to set the 

$settings['file_public_base_url']

to its shared folder path.

Everything was working fine on the site, aside from this issue, with little other indication of issues. I could generate images at will on local dev sites, so couldn't see what the problem was, and looking at system logs only related that the image style couldn't be found. Of course, this was because the style wasn't there, but gave no further indication. 

I tried all the other solutions here, including the .htaccess fix, the file_public_path and suppression of itok, but to no avail.

Once I commented out the file_public_base_url, all was OK. Running

drush image-flush

confirmed this.

netw3rker’s picture

I want to add an addition to this. This was *exactly* my problem. Dev Desktop creates a symlink site directory that points to the sites/default directory. 

The main problem here is that the Image module generates a cached route to the public://files/styles location. When you first access the page via the browser, that path is sites/[symlink name]/files/styles and that gets cached. If however you bootstrap the site through a drush command, that route will be built as sites/default/files/styles and then cached.

When a file such as sites/[symlink name]/files/styles/example.jpg is requested, the Image module changes the requested route to the directory path of the image, and returns that path for route processing. If the route was initially generated during a drush bootstrap, then it will not match the route requested by browser, and a 404 will be generated.

If you or your process requires both that site directory symlink, *and* the use of drush for cache clearing, either follow the instructions of explicitly setting your public files folder, *or* instruct drush on which site it is clearing using the --uri=example.com command. (for example: "drush cr --uri=example.com" )

hope this helps someone!

ph7’s picture

I had a similar issue (re-)generating image styles.

The ?itok= security token was added as of D7.20 to address denial of service vulnerability

Include this in your Nginx configuration:

# Media: images that have ?itok in uri call php rewrite
location ~ ^/sites/.*/files/styles/(.*\.[^.]*)(jpg|jpeg|gif|png|svg)(\?.*)?$ {
try_files $uri @rewrite;

}

I haven't looked into Apache servers but there must be a similar rewrite rule for Apache as well.

UnsettlingTrend’s picture

I'm still having this issue, and nothing above has helped.

HA77’s picture

Drupal 7 + nginx. Using drupal in a subfolder.

I'm gonna leave this answer here just in case. I tried most of the answers here. It wasn't a permissions error, and I was not getting any errors on watchlog or php/nginx logs. I was restoring a site from a backup (backup and migrate).

In my case, disabling clean urls solved the problem. So I have the suspicion that we have something misconfired on Nginx about having drupal sites on subfolders (eg: domain.com/drupal1, domain.com/drupal2)

AmVet’s picture

I've been working on this for over a month. I can get it to work but only if the styles folder is 777. I have deleted all images styles from drupal and then deleted the styles folder to narrow the scope (it remakes automatically). Changing owner and group or either has had no effect at 775 it works with any owner group at 777 when the image styles directory is built after creating a new style, it will be at 775 and they work fine like that. If the styles folder is changed back to 775 it wont work. I'm not using styles because I don't want to keep it at 777. The site is live and already a lot of work. Dont need security issues.

Stefan Lehmann’s picture

If 777 works, but 775 doesn't - it's very much likely that it is just an ownership problem. Did you check all the available error logs?

In order to generate the folders / files etc. the user used by the web server must be able to write into these folders. I think in most situations that would be the user "www-data".

I like cookies!

Cedric Web’s picture

I found a solution for my issue here:

https://www.nginx.com/resources/wiki/start/topics/recipes/drupal/

This part near the bottom:

    # Fighting with Styles? This little gem is amazing.
    # location ~ ^/sites/.*/files/imagecache/ { # For Drupal <= 6
    location ~ ^/sites/.*/files/styles/ { # For Drupal >= 7
        try_files $uri @rewrite;
    }
UnsettlingTrend’s picture

Just noting for anyone else...

ZambalaRed’s picture

Hello everyone!

I am the original Author of this long thread,

I were almost forgotten about this old thread - and the Problem was partially resolved long time ago - but it was very persistent problem - so:

1. Suddenly on a production site - I was not able to produce Image Styles....

2. Came Host - also could not really resolve this problem

3. then I found out to my Surprise - I can work with images ending .JPEG , but cannot with .jpg .....

4. after some 6-8 months of struggling - my Host said - Now they are able to add me to exclusions of their new Varnish Cache, so my images are now excluded form Caching serverside....

5. well, may be not really perfect solution, but my problem was solved...

wd4t’s picture

I've been evaluating a new host with a D8 site and hit problems with image styles not being generated. I tried many suggestions from reading many posts. In the end the solution was to switch off Cachewall in the hosting panel. It appears to be messing with permissions so I've contacted the hosting service to see what can be done.

Andrew211’s picture

Hey Mate,

TBH I don't see how cachewall could mess with permissions. Some caching sytems are simply incompatable with itok.

Here's the solution and to anyone else using a 3rd party cache such as Varnish, add the following lines to settings.php, then obviously clear cache:

d7
$conf['image_allow_insecure_derivatives'] = TRUE;
$conf['image_suppress_itok_output'] = TRUE;

d8
$config['image.settings']['allow_insecure_derivatives'] = TRUE;
$config['image.settings']['suppress_itok_output'] = TRUE;

wd4t’s picture

Thanks for the suggestion. I will try this when I get a chance and post the outcome.

hectorplus’s picture

@Andrew211, thank you!! That worked for me.

ccaajj’s picture

I updated to the latest d7+various 2015-era modules on 2018-02-01 and, I don't know where in the stack a change was made in caching, but URLs to all of my derived images in ...images/styles/* were ending in the ?=iotk+ gibberish

Adding these two comments to settings.php fixed it (the last one mostly, I'm sure), though I am wondering what caused the problem.

d7
$conf['image_allow_insecure_derivatives'] = TRUE;
$conf['image_suppress_itok_output'] = TRUE;

meytad’s picture

This works for me, Thx

hazit’s picture

Have been struggling with image handling on my Drupal sites for months. Wish I had discovered this thread earlier.

I'm on shared hosting and after messing with folder permissions, php versions, manually creating styles folders and all sorts of things, simply disabling Cachewall solved the problem immediately.

This was a tricky problem as it took a very long time to diagnose (I would still count myself as a novice). Neither my hosting provider nor my theme developer could figure it out.

Posting this here as a +1 for the Cachewall solution

drup16’s picture

Hi,

This is going to sound silly, but did you try setting another theme as the default and then switching back to your desired theme? For some odd reason, after i switched to another theme and then back, the image styles were generated. I did not have to do anything else. 

Rainer F. Gottlieb’s picture

Hello, https://www.drupal.org/forum/support/post-installation/2015-06-16/image-... worked for us with 8.4.4

in settings.php we added:

$config['image.settings']['allow_insecure_derivatives'] = TRUE;
$config['image.settings']['suppress_itok_output'] = TRUE;

we needed this never before but after complete new setup/migration (with existing config) of a site and an updat from 8.3.7 to 8.4.4 no images style-pics were rendered, thanks for this solution.

binodc’s picture

This worked for me.

binodc’s picture

This worked for me.

cristian100’s picture

This worked for me on Drupal 8.5.3

nguyentuanxuyen’s picture

Image styles not generating you Please store it

jmadden27’s picture

Unfortunately none of the suggestions thus far have worked for us on 8.4.4. Oddly enough, the problem only exists if we block hotlinking of apk, log, and pdf files in our conf.d file...

https://drupal.stackexchange.com/questions/255474/image-styles-not-gener...

ccarnnia’s picture

I recognize a few of usernames on this tread. That makes me think that this is not a trivial issue. 

php: 5.6.36 - apache: 2.2.15 - drupal 8.5.3 - rhel server

If I use the local file system image styles work as expected.  But switching to NFS file system [ nfs (rw,nfsvers=3,addr=nnn.nnn.nnn.nn)] results in: Unable to generate the derived image located at public://styles/thumbnail/public/uploads/images-slide/1.jpeg

My styles directory is owned by apache:web 

There goes my weekend!

Agata_r’s picture

In my case nginx was a reason of this problem. Instead of going through custom server configuration I installed Imageinfo Cache module and it helps me. I hope this solution helps someone else too.

kyryliv’s picture

/sites/default/files/.htaccess

- Options -Indexes -ExecCGI -Includes -MultiViews
+ Options -Indexes

detected by review error.log in apache

forko’s picture

it did help in my case but i don't know why? i have created a new content type with multiple image field and started slowly add content. a few weeks later when new content that i add of this content type stoped render thumbnails for images same case when i edit older content (change images). anyway solution by

kyryliv helped

Please explain somebody what we do by those changes. THANKS

ekeyser’s picture

I saw this issue when using CDN module. Turned off the module and image thumbnails started working. Turned it on and thumbnail generation failed on CDN request.

MaxMendez’s picture

I'm facing this problem, did you find a solution?

SergeBr’s picture

I confirm, for me it was a cache proble (Varnisk).
Hosted on Fastcomet, I had to go in the Cpanel and open Cachewall.
Then just stitch off for your drupal url.
Easy, but it took me a long time :-)
Hope it helps !

anandkp’s picture

If you use Nginx, you'll need to ensure that, if you've used the Nginx Drupal Recipe, that you have the "try_files" directive in that location block!!!

INCORRECT CONFIG

location ~* ^.+\.(jpg|jpeg|gif|css|png|js|ico|html|eot|woff|ttf|flv|swf)$ {
    access_log off;
    expires    30d;
}

CORRECT CONFIG

location ~* ^.+\.(jpg|jpeg|gif|css|png|js|ico|html|eot|woff|ttf|flv|swf)$ {
    access_log off;
    expires    30d;

    # This is VERY MUCH NECESSARY here. Without it, the server simply stops
    # processing the request if a real file is not found. For Image Styles in
    # Drupal installations, Drupal ONLY GENERATES THE IMAGE STYLE CACHE IMAGE
    # when it receives a request for a file that doesn't exist!
    #
    try_files $uri $uri/ @rewrite; # <- THIS WAS MISSING!!!
}

Hope this saves someone's time!

Credit: This post on Drupal Stackexchange pointed me in the right direction.

vsviridov’s picture

yes, that is correct

here is from my config

```
location ~* \.(js|css|png|jpg|jpeg|gif|ico|svg)$ {
            try_files $uri @rewrite;
            expires max;
            log_not_found off;
        }
```

but

try_files $uri @rewrite;

is placed at the top

zuhair_ak’s picture

Thanx Man!! This solved my issue as well. But I had a dev server which didn't have this directive and everything seems to be working there. Have to figure out why is that? 

Brod Solutions’s picture

Drupal 7 - Image Style - Views - Views Bootstrap - Bootstrap Sub-theme

Try the following one at a time:

  1. Increase PHP memory in last line of settings.php ini_set('memory_limit', '512M'); helps give site more resources to load
  2. Turn off AJAX on views
  3. drush image-flush --all
  4. Recreate Image Style to shorter name, loading shorter url for each image:
    • /responsive-rectangle-640-480-.....jpg
    • /640x480....jpg
jweedman’s picture

I was having trouble, specifically with images in JPG format.  Original image was there in "sites/default/files" but could never generate styles off that original image.  Apparently GD image toolkit has libraries to support different image formats.

Thanks to this thread, I ran a command to see GD's information output, to see if this was the issue.  Sure enough - JPG library was not compiled.  So for me, the answer was to compile PHP / GD Image Toolkit with JPEG support.  Hope that helps someone save the multiple weeks it took me!

zatarain21’s picture

I had the same issue and after tried all the sugestions. I solved add this line in settings.php

$config['image.settings']['allow_insecure_derivatives'] = TRUE;

It seems that my server (The specific characteristics of hosting: shared plan with cpanel) as some security issues with https, because cpanel generate SSL Certificate for free but is not enought, so the styles images are not generating. 

Regards
rwilson0429’s picture

Setting the configuration setting: $config['image.settings']['allow_insecure_derivatives'] = FALSE is a default security fixed going back to Drupal 7,20.  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.   Setting the "allow_insecure_derivatives" to "FALSE" is a security fix that changes all image derivative URLs generated by Drupal to append a token as a query string settings meant to address this vulnerability.

If your watcdog shows file not found errors when generating image styles, I would suggest rechecking the folder permissions or using Devel module to clear-caches as mentioned in other threads here.

ReggieW

MrPaulDriver’s picture

I have built many Drupal sites and have never met this problem until now. I am finding that image styles are not generated until a cron run takes place.

Does this provide any clues about what is going wrong?

---
Paul Driver
www.easable.uk
Ilkley, West Yorkshire, UK

markusd1984’s picture

Me too run into this issue, even though image styles were working fine before. I also couldn't solve it so far, after trying everything here.

Styles folder have 755 permission and I'm able to write files with the Apache user. GD library is also installed, supporting JPEGs.
I cleared cache, flushed image styles and even tried with itok disabled etc. but nothing helped.

Anything else we can check? :)

UPDATE: Fixed! I noticed that it worked without clean urls, thus realised it was an issue with rewrite rules, after inserting the rule for the folder location it worked again

RewriteCond %{REQUEST_URI} !/sites/default/files/styles(.*?)/?.*
paperscenery’s picture

Hi @markusd1984 — we are still stuck after having tried all of the above solutions. Can you please clarify where you inserted this rewrite rule?

Brod Solutions’s picture

The above mentioned Rewrite Rule is placed in the .htaccess at root of your drupal install.

mmjvb’s picture

For D7 .htaccess in the root

 117   # Pass all requests not referring directly to files in the filesystem to
    118   # index.php. Clean URLs are handled in drupal_environment_initialize().
    119   RewriteCond %{REQUEST_FILENAME} !-f
    120   RewriteCond %{REQUEST_FILENAME} !-d
    121   RewriteCond %{REQUEST_URI} !=/favicon.ico
    122   RewriteRule ^ index.php [L]

For D8, find similar lines in .htaccess in web folder.

kkalaskar’s picture

I was facing same issue in drupal 8, I followed the following steps. (This issues was on local  [Windows 10 with docker] so this only for LOCAL environment and not for Production environment)

  • In settigns.php 
$config['image.settings']['allow_insecure_derivatives'] = TRUE;
$config['image.settings']['suppress_itok_output'] = TRUE;
$settings['file_public_path'] = 'sites/default/files';
  • Sites web root folder .htaccess
RewriteCond %{REQUEST_URI} !/sites/default/files/styles(.*?)/?.*
  • Under /sites/default/files folder .htaccess
<Files *>
  SetHandler none
</Files>

After this I can see images are loading on site.

sorabh.v6’s picture

Thanks, It works fine for me.

figover’s picture

Your solution is very good. It is working for me with drupal 8.9.

Thanks for your help.

littledynamo’s picture

I had a site where the image style was not being generated and it turns out the image style did not exist!  Worth checking...

inst’s picture

Hi,
I installed media and media library.
I am on an Ubuntu PC with docker environement for my Drupla 8.8.2 install.
(PHP 7.3.14, Apache 2.4.38, MySql 5.7.29)

When I try to upload an image I get this error:

Warning: imagesx() expects parameter 1 to be resource, null given in Drupal\system\Plugin\ImageToolkit\Operation\gd\Resize->execute() (line 67 of core/modules/system/src/Plugin/ImageToolkit/Operation/gd/Resize.php).
Warning: imagesy() expects parameter 1 to be resource, null given in Drupal\system\Plugin\ImageToolkit\Operation\gd\Resize->execute() (line 67 of core/modules/system/src/Plugin/ImageToolkit/Operation/gd/Resize.php).
Warning: imagecopyresampled() expects parameter 2 to be resource, null given in Drupal\system\Plugin\ImageToolkit\Operation\gd\Resize->execute() (line 67 of core/modules/system/src/Plugin/ImageToolkit/Operation/gd/Resize.php).
Warning: imagesx(): supplied resource is not a valid Image resource in Drupal\system\Plugin\ImageToolkit\GDToolkit->getWidth() (line 328 of core/modules/system/src/Plugin/ImageToolkit/GDToolkit.php).
Warning: imagesy(): supplied resource is not a valid Image resource in Drupal\system\Plugin\ImageToolkit\GDToolkit->getHeight() (line 343 of core/modules/system/src/Plugin/ImageToolkit/GDToolkit.php).

All other functions of the site are OK.
I can also upload PDFs with media manager but not images.

thx.

javihun’s picture

I went crazy trying the options above but in my case it was a Varnish issue. When I disabled varnish everything went back to normal. This was happening in my test environment only so disabling varnish in test is not an issue.

drattar’s picture

All the members ’comments were not helpful to me .. In the end, Drupal documents were useful .. https://www.drupal.org/docs/security-in-drupal/securing-file-permissions...

i use Drupal 8, CentOS VPS

joro78’s picture

We are using currently Varnish 6 with ssl termination on Apache 2.4. The problem persists and a possible (but not best) solution is to exclude the path for the image styles from caching. Then the image styles are rendered as expected.

sub vcl_recv {

# Do not cache these paths.
                      if (req.url ~ "^/status\.php$" ||
                      req.url ~ "^/update\.php" ||
                      req.url ~ "^/install\.php" ||
                      req.url ~ "^/apc\.php$" ||
                      req.url ~ "^/admin" ||
                      req.url ~ "^/admin/.*$" ||
                      req.url ~ "^/user" ||
                      req.url ~ "^/user/.*$" ||
                      req.url ~ "^/users/.*$" ||
                      req.url ~ "^/info/.*$" ||
                      req.url ~ "^/flag/.*$" ||
                      req.url ~ "^.*/ajax/.*$" ||
                      req.url ~ "^.*/styles/.*$" ||
                     req.url ~ "^.*/sites/default/files/styles/.*$" ||

                      req.url ~ "^.*/ahah/.*$") {
        return (pass);
}

We have to address the issue and handle it to the group which works with Varnish implementation.

arefen’s picture

Hi. I have the same issue with OpenLiteSpeed. I read all comments on this post but can't resolve my issue.

I created an issue separately for that. please help if you can

https://www.drupal.org/forum/support/post-installation/2021-11-23/drupal-8-cant-generate-image-style-on-openlitespeed

izus’s picture

From f1mishutka's answer
I had this issue on a Windows 10 and to bypass it in localhost, the Following was suffisant :

is sites/default/files/.htaccess

<Files *>
  SetHandler none
</Files>

Twitter: @ismaeil_

izus’s picture

From f1mishutka's answer
I had this issue on a Windows 10 and to bypass it in localhost, the Following was suffisant :

is sites/default/files/.htaccess

<Files *>
  SetHandler none
</Files>

Twitter: @ismaeil_

fonant’s picture

An Apache security update causes spaces in filenames to trigger "AH10411: Rewritten query string contains control characters or spaces" errors in the error log, and "Permission denied".

This is because the spaces get double-encoded during the rewrite process. I find that a fix is to change the index.php rewrite rule from

RewriteRule ^(.*)$ index.php?q=$1 "[L]"

to

RewriteRule ^(.*)$ index.php?q=$1 "[B= ?,L,QSA]"

The "B" flag says to not encode spaces and question marks during the rewrite, and QSA allows any itok= URL parameters to be appended to the query string.

http://www.fonant.com - Fonant Ltd - Quality websites