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