Problem on a remote server (while the same php script works on a local) is:
1) PNG image is loaded from a system path:
$imgpath = "absolute/path/to/a/png/image";
$img = imagecreatefrompng($imgpath);
File and folder where file is stored has proper chmod and chown setup and I can output correct image size (for test):
echo imagesx($img)." x ".imagesy($img);
Above line outputs 256 x 64
which is expected image size. I assume this means that $img
object is properly loaded from the file.
2) When I try to output the image using:
header('Content-type: image/png');
imagepng($img);
imagedestroy($img);
...browser shows an empty image of 16 x 16
pixel size.
Screenshot of how it looks like
3) If I try to open the same file using direct http url, browser opens it correctly (expected 256 x 64
image with some colorful content).
Here is how image looks like when opened with direct link
4) If I remove header('Content-type....
, imagepng outputs png file content as expected:
�PNG IHDR@z?>� pHYs���+�IDATx��]ytչ����͒-�Y����$�� ��f!$� Jh M)-�+=��q�Bii�e����ihi d!!!�B�=^B�D��E��}��y���I�H��s��䜌>ݙ{�߽�~����ct�e���]���~....
(showing only part of the output here)
5) When I compare the output to what I can see on remote server using nano, seems 100% match in bytes and in file size. Also file size is exactly the same if I download the image using direct URL in browser.
6) I've also tried to output image with different methods, such as fpassthru
and echo file_get_contents(...
and setting up header for that purpose (adding content size etc.). All resulted the same.
I'm going nuts here. Anyone has any idea what could be the problem?
P.S. request status is 200, no errors and no server errors in log file.
P.P.S. I have compared request and response headers when I open image with direct link and via PHP script. They are exactly the same.