2

I'm stuck at a weird problem regarding imagepng() and similiar.

Whatever I do, the output is disliked by my browser (and my desktop programs) and the image is considered corrupted.

I've so far tried

header('Content-Type: image/png');
imagepng(imagecreatefrompng($str_file_path));
exit;

and

header('Content-Type: image/png');
echo file_get_contents($str_file_path, TRUE);exit;

Both gives data which looks like actual image data. Neither should have any blank space since header() doesn't complain and I exit; the script afterwards.

There are no errors given which would ruin the output either.
The functions are there, obviously. So what seems to be the problem?

I couldn't find any question answering this either.

The output I get:

�PNG


IHDR�������,����PA����tEXtSoftware�Adobe ImageReadyq�e<
[IDATx��\Mn�Vo?
�Z�L/�پYD>A�'����~�����fo�  �>Aԋ^�Y�*�Z}��|�|�!��$=IZ�$Y,?��\__]�����"������>4?֦��͠��O�H����ze������Dž�æ�:`uEJ��vj�����sSli��v�4��WF�f��������a��g
��)�@��3j�%kЦ�Օ?
ۇ
�saL��~lmujj��Q(&���#�;�6u%7u�MOt�zu��Z������b�8q9�)|}e����c����g:�ӭ��*4TGFs�,y�^`P��=@�+�m���M���z�K�X����Ӥ���D9�ySPu��uq�'��LM�3���
�8?������k�/�����I4�/5�0U�V42��?YPI´4�m�L����gEK2VkM����J�
ͼ3�]i��5�Q�US�~r�e�}�`�P�[0V�/�}�+�8����1�}�V}�1����%
+h�4���U�����ʗ?������m�J+�Ȁlf����"�.pY?�e9��L7�������cA�I��>CG�|�f��Z?�n�':'�;�]��.��;I��$r2χ��.���Ҙy�mA'W�ZT�Iѧ���ӱ]���Y~��?���za�e��A�X�p�ZXA�C0�w�
�ϑ��Յ�(w� ���>�,1���
��9#0�{�AU*:}�I��sG.I���Co�^@�M=�F��ʚ@�S2�j�_c-,����V   ���z��;������9@�    9�BVJ�p���9-�@'��*����Ԛ8��|�g;�C�oX�w8�����͔���{4�*9d�ƙ�L���������a���9�����,�]��3��#W���V;�ML  GFSG~&�k���S�t�?W<���<��i-��5�d:R|�x^P��Tm����M%�/������택w�Oa͎���=jk�}��i{�/;1��Z���/�G�M0d
H��@������V����n-yV��G��P6o��T�Ƿ&��M��m�[9O�f+)E�;�6K|�*s;B�'�c��7I�ՕH�5��� ����]8��V�@���G�3�s�p�Tufl�19�Ԁ+��֭�SKb65MڱÛV��*�(@��ɚ$U��}В7������FW@�lʵ������F~��Z��=`�mv�� ����'�Tj�ME�f�@P�<�>��K<�������1�m�ƕ�AQPRT�o�4��l��0���)�+g�
��[���`�R���)��"eD��b��g��WN-`��i{U�D|(�dhS�0&8K��S���E����Q�x�Ǫ!�K��ܑ�d�O%@c͠d,�,p�(
3t�8T�����:ذ�qߵ�&�y��Ҽ��2�vJ� ���{;>5�J��2`�9��"hC>�%>\�Զ�(fZ�C�]9�ܼaR3w�a"M'�)'�w���p����) ��O^
3�v�/
�VM� _��Q/u�k�э�춏�UGz�/�>IV9�
    �}�@�T�%��{ƚCV�Ǒ��VZ��A�#b�t~��O�@����
�(�8.�|0�
o�C�Ĵ�y�w�xϧr�W��@���O�8+��s��#%�J@V��)V��g�XM�~����G^O]���u~�bA�+�J��y-
�^���k3]y��ok_�[�?Txv��G��ʛx�;���>���1���]8he���z\  ��ď �u��#5�3�g��w~�%$�Z>2����g�Ι�����c�6r�R�\�r%��w���%a)��G@?C�Q@�Ǚ>'��KH��y?�֊V����_��7�����f��Dlv����Kn�D�an�B��ȼ,�ğR��P�,�jC��[�\9��m/��Wȹ����XߣD�J�*�ӧM��~6:��",ҭ@��   ���WL������ވ�P�3,�����i���v37�s��-|,I.)���y_@�K��*��},k�枰v���o�}��w�r�b��R_����L�
��C��I��kP�-�$��?�uZ��r�3�)��lߧ�{�xv~��Ic}�y�Ax׿ᑅZC�U����>�aJ����qc$
���w����e���/���O���ǫ�c�4�\�aB?��҇��9'�X�Tf��K�{MڨG�_I���Hm������s  A��/>?Ś5��B8�Y��a�AO�\��c�Ѿ�՞�O���rܝ�Ur��g���ǚ�T4LZ4�Ga)�5u},����,_�D.���$j��L,�;i=Vm#b����<�ϥ�B���G4��Q���]cY����~�����$�#�ةVH)��7��O[cq�L��Qpwn7/    �|�)-򐼟l��hė
D6������Kpw�Gn���Q�:�s�Jwy�%��K�%HJ�KN�Rު��FqB+q${��ZPm������
@;��*>�u�˹
��<���y�G�H]�s-���%Hc%�F�N����/�|�+/���J��t�~�[���/�`��X����IEND�B`�
4
  • Have you tried readfile()? And just because header doesn't complain doesn't mean there is no leading whitespace - output buffering might be enabled...
    – DaveRandom
    Apr 27, 2012 at 13:18
  • Thanks for your help. readfile() gives the same result as the other 2. There are no blank spaces judging by the source code. The image works by it's own too. Apr 27, 2012 at 13:22
  • 4
    Is the original image considered corrupt? Did you perhaps encode your file as UTF-8 with BOM (header would complain though)
    – Halcyon
    Apr 27, 2012 at 13:27
  • Thanks! You nailed the issue! The file I used had a BOM header. Converting it to utf8 without BOM solved the issue. Please post it as an answer so I can accept it :) Apr 27, 2012 at 13:30

1 Answer 1

1

All credits to @Frits for his comment

Basicly I had the file saved as UTF-8 when I instead should have had it as UTF-8 without BOM. Changing this solved the problem perfectly.

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.