After enabling the latest Mosaico on one site, we found the icons are not loaded after adding a new template. After dragging the image from the left to place on the template the image is displayed as below -

enter image description here

On opening the ajax url in a new window, it says -

The Image <258*150_url> cannot be displayed because it contains errors`

1 Answer 1


After looking for a while, I found this was due to the whitespace before <?php i.e

<space><?php (starting of the file)

in civicrm_settings.php file which was messing the png file generation. On removing this space, the image was loaded correctly without errors. So if anyone encounters this error, make sure all your included files are white-space free before <?php.

Update: This normally occurs due to an invalid image that is formed by the headers. Flushing the headers with ob_clean() just before specifying the same have also worked for some users. There is a great answer https://stackoverflow.com/a/2591854/4243217 which explains about the space issue while creating image using ImagickDraw(used by Mosaico).

  • Jintendra - thanks for this diagnosis. I am facing exactly the same issue and do not have a whitespace before <?php in my civicrm.settings.php file. A search in the directory tree uncovers many files that have such whitespaces before <?php, including WordPress theme files, plugins, civicrm extensions, etc. Can you explain why such a whitespace is an issue for this pop-up, and how to mitigate it? Which files are loaded by Imagick when generating the image? Thanks.
    – cividesk
    Oct 6, 2017 at 0:06
  • For further reference - there was a ?>\n\n<?php in the functions.php file of the WordPress Church theme. Removed it and it fixed the issue. I believe this issue would be corrected by resolving github.com/veda-consulting/uk.co.vedaconsulting.mosaico/issues/…
    – cividesk
    Oct 6, 2017 at 5:38
  • will soon update the answer of why it is actually needed. Oct 6, 2017 at 6:12
  • I encountered the same issue. In my case it was due to a Drupal module that contained UTF8 files with a byte order mark (BOM). So I can confirm that it's due to "spaces" before <?php, as Jitendra mentioned. But beware that 1) it can be anywhere in your website php files, 2) the "spaces" can be invisible (I used a hex editor to see the BOM)
    – AlainB
    Jun 22, 2020 at 10:01

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.