Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
I'm having an issue about image derivatives rendered as broken links after flushing image styles. The links are not in fact broken when checked from firebug. Images are displayed only after page refresh and image style are created normally. This issue is not page or node specific and having the issue on only one of installations. I've checked permissions and ownership of files directory, cleared the cache, disabling apc and memcache and nothing helps. I posted a sample image file that gets generated.
Comment | File | Size | Author |
---|---|---|---|
#1 | 8728791228_d7eda3aa44_k.jpg | 77.76 KB | sozkara |
Comments
Comment #1
sozkara CreditAttribution: sozkara commentedComment #2
longwaveThe first character in your broken image file is a newline. If you remove the first byte the image can be successfully displayed (it looks like some kind of industrial robot!)
This means that somewhere in your PHP code you have a unexpected new line, either before the <?php tag or after a closing ?> tag. If this is only happening on one site then template.php in your theme is a good place to start looking.
Comment #3
sozkara CreditAttribution: sozkara commentedThanks for your suggestion, im looking into my php files right now... But if it is a PHP issue, how do images generate correctly by refreshing the page?
Comment #4
sozkara CreditAttribution: sozkara commentedNevermind, by your suggestion, I found out that there's a new line on settings.php before <?php tag. Working perfectly now, thank you so much!
Comment #5
longwaveComment #7
bpadaria CreditAttribution: bpadaria commentedThank you so much @longwave.
I had space before <?php with my index.php file
Comment #8
gokulnk CreditAttribution: gokulnk at Azri Solutions commentedI had space before <?php with my custom module file. Removing that fixed the issue for me in Drupal 8 as well.
Comment #9
heldercor CreditAttribution: heldercor at morfose, lda for Azores Tourism Association commentedWow, I tried several regexes to find that whitespace but with no success. Had to try a new installation, uninstall and install back lots of modules to get to the culprit... after many hours turned out it was an empty custom .module file! Finally fixed (Drupal 8).
Comment #10
majidlahmidi CreditAttribution: majidlahmidi commentedI have the same error and spent lot a time. After deleting the white line before <?php in my custom .module, it worked for me. Thks
Comment #11
majidlahmidi CreditAttribution: majidlahmidi as a volunteer commentedComment #12
gokulnk CreditAttribution: gokulnk at Azri Solutions commentedThe white space/ empty line before <?php was the culprit in my case as well.
Comment #13
geerlingguy CreditAttribution: geerlingguy commentedWow. I ran into this on a site that was using the Block Styles module. See: #2641330: Extra space in block_styles_bootstrap.module causes problems.
This affects Drupal 7 and Drupal 8 alike, and is totally not obvious when debugging.
Comment #14
pixelwhip CreditAttribution: pixelwhip at Aten Design Group commentedOy!! Wasted a couple hours on this gem. Had a blank line at the top of a module.
Comment #15
RenrhafSame here, but the issue was a blank line at the end of the "settings.php" file, after the php ending tag.
Comment #16
joe_carvajalSorry to "reanimate" a closed issue, but I really want to thanks the people of this thread.
I had this problem and looked like a crazy and I only found people with this problem with Nginx and people saying "Have you tried to fix permissions?". As you say, an empty line before the opening PHP tag at a custom module was the problem in my case.
Thank you!! :D
Comment #17
russellt CreditAttribution: russellt commentedThanks all for the clues. My image style page refresh issue was due to a kint debug function elsewhere in the code which I had forgotten to comment out.
Live and learn. Hope this helps someone.
Comment #18
russellt CreditAttribution: russellt commentedSo, I'm back here 6 months later, having stumbled into the errant single line before the <?php tag in my settings file, causing image derivatives not to display without a browser Ctl F5. Removing the errant line solved the problem immediately.
(Btw, I use drush cr to clear cache. I noticed that the drush response to cr started to jump a line before responding as usual with the standard '[success] Cache rebuild complete' message. It was the first sign that something had changed. As soon as I removed the errant line in settings.php, the drush cr response performed as normal.)
Comment #19
James Hawthorn-Byng CreditAttribution: James Hawthorn-Byng commentedI cannot believe that a single blank line at the beginning of my settings.php file caused me so many hours of frustration!
Its interesting that I had no problems with this on my local ddev environment, but did the moment I hosted it on an apache server.
Comment #20
zachminner CreditAttribution: zachminner commentedI had the almost the same exact experience as James did except my "single blank line" was at the top of a custom module. I had no issues with it during local development but on production servers, image styles were not working. I removed the blank line and everything works again. Bit of a wild bug.
Comment #21
crasx CreditAttribution: crasx as a volunteer and at Bounteous commentedI also just got bit by this. Here is a script I used to find the blank line before a PHP tag:
I was able to tell I was affected by this issue by the content length difference between pre and post cached requests:
Note the first request transferred one more byte(?) than the second one.
Comment #22
turtletrail CreditAttribution: turtletrail as a volunteer commented#21 helped locating the faulty file.
Thanks a lot, crasx
Comment #23
ltb1986 CreditAttribution: ltb1986 commentedTHANKS! We have wasted a fair few hours debugging this issue. Phew!
Comment #24
Luca Cattaneo CreditAttribution: Luca Cattaneo commentedThanks a lot @crasx!
After a few years (!) with this annoying problem on a website, I finally find the blank line at the beginning of a file with your script #21.
Amazing, now it finally works!
Comment #25
muhammad.tanweer CreditAttribution: muhammad.tanweer as a volunteer and at App Desk Inc. commentedI recently had an issue where when I would upload a new image (and before saving the form), the image uploads via ajax (standard with drupal), but the thumbnail showed broken. I checked and the thumbnail was available in files directory. The image would show when i would right lcick on the broken thumbnail and hit "load image". After stumbling on many things I found it was a blank space at the start of one of my custom module files.
So it is likely the space is at a place where you have added/updated some code. Check your custom modules, themes etc files.
Comment #26
Markisich CreditAttribution: Markisich commentedHi, I was 2 weeks with this issue, looking for problem in cache and reverse proxy, until I found this post.
I had a space in a custom module in front of <?php
the version of drupal i'm using drupal 9.5.11
I would like to know if the problem is Drupal, symfony or PHP?