0

We are using a wacom pad that convert signatures to base64 strings encoded and we store these in a database. After that i retrieve these encoded strings and decode them in php using base64_decode() and then try to convert this decoded string to an image.The result im getting is the following:

�{�{|��;z�y�����N^~�N�ߏ��!��d�5uU%�#�sҲb@#���� �����8�=~���=�~����������=B��@�@��(@}}�9�z�:t�������1�\TL<0�����w�P0�C�@B�$C�phXH@o��!@?}�� ("&P��qaqaA"�D��{ ���ó����������$DXht� "B2bB2R�qa@"��G� �����Ֆ֖��QO�JG�z���������W_s�����������=�z�u�������~>~���@�}����xzz�y� ."*6>J��1!�Рxx����|�} ��:40*( " /@ /����ogG�޾�������'W�� �#c�d���C�B�a��@�@�����Ο��@���o����0 @0�!^��Ã��~ ��������������@���@E; ����~}����� (0_��@}�z���������p����� @$T�F�DBA��;����54��vwx�;��?@B����LjɊJ� �GE��A��~���������$0@L\p|q��a РP@�Ͽ�����Oo������Aq�����qP�� �;�<�<����(8H,48@PTd`h`XL8,��˻����{�<�=ޟ?�@�a�b�C�d�EeE�#��@@�=����$X@PXlt|���phTD0(����O_o���@p��A`#��@��$!# ,H�0`P` ��??�@��D�F����B>8.( ��������'0�����@��"��@IA�&" (0���0�!1aQ�q�q�!00�>�}<;���{������������?��Q��B����F_�L��+-).1^����$��@"H�sgO�@x��%ɒg����<��N;��[���|9w���n�k՛88�Ë,������ �D ��+Z�9��� B8�"���B�,`"�L@�0 ��@�x��߀>kB L�Be�8`��A��?x��`�x<��N���� ~�@�$^8h�Ft4P�� |@o�p �9���?��?�^����=��P@�!}0yIP|8h���_>����>��ӳ^�t��V��xt���?��@aB ��� �'�����'�C� ��0p��7��~� �(8a@�?� 6pۧ.o�z�y���� &4�c�$F��L 8Hp��}���;�ٿg-�;�� a�����т�������g-{rf�r�0jQ^��9�kٻ]w����H�*P����}�����|���ƂK��JW��K�.d?�"=�_���A����G g A�Dp,a!c�@?��ۗ �s�ɏ6]�o������.h�(G�Dh�4X�����ݬ=j׿���0�"H����r�Ȏ����n۳^��ٳo]z��!��&��B@��0@��� $ $@ 8(@?�y�ˎ���n;�����B"T��@���bd�� ��n;��ٷ������aX#7D8P@������]�o��AC �F�0�/����>}x���~~���@�� :� �a���b#��B�>{��ǟ9���>��N|xoݷ;v�ßo??�H"��$߀��@v���￀~�����GKrd�� <�"���{�P�E��F 00|�ۧ=땀�:� 3��&�@@@�@@�@O� ��Q��=?A� ������ݽ�����U;=>� ������������\�J:=* ����������������������������������������������ظ����]�^@BA ��������������0479 �������.31 � ����������� ��@�0dm�)}p����� ,�@X4��8 ����������������~G����|���>�������~@�0�0.����:���$��@����( � ���p}�4�� '����������������_��������0� 0�� }�:@����?���@�����O��?��������|>���D|�����/������������P @���"���<�}����~�?������?����4@.��5��& ��@�0h@D ,�:r��+�����~����w��������PA��<�@@�p��p�@@� @�������������߹�~�������?���@8 p8)����tA�4���$@:���������o��>��������������@p�l����<���@2������~��������~�����_�����@F�8P����~�������������o������X �D�� s��h0� >�?����/����������$x�d�@�E���:@� <�@�|���~O��d�������?�����@�����f A�4�pd���~���>���_o�����W�����p P��>r�l @( ��?����?���@ �� �@@��������0?���9o����� ����x���H���7������?��P��� �A� '�������0��� ��H�D ��4�d ��?��ߟ���������@�@ P4�A���6@� @x ����5���������}߫��W���������������~�����y�=��'����|/��~��������)z� p�������?���������?���������P@H�\�p� I �@)� �� ;@�P��������/��~������Oq�~W�������P �h�pX��o��A0 T����?��/���g�����/����������@���8 ��8A%��!���0���?������>������@p���DA!�h�0� ����O���?���{�}����g����X ��8��L����������(������������@8�8�@@��@x �,�� 0��� < �� �P�����?��_k�^J���@` ��p~��@0� �� �����0A_����@@�� ���~����>�����@<�B AH U�PB@�`�����������zO;���������O�����@\� ��A��P���9����.@P�L���}o������7�}�����h A�2��0<����������?���G�������v���0x l��P�p�����O���8���~�����> ���P&@p 8����������������8����g���G�}����w��x��h�{��h�X!P���������������|��?H�:�1�AŰt�2����&� ������/��?�}����/��� ������@ H&��@l��@���� ������������o������������?�������?��_�@���@��L P&���X 8� �� ������?���������������}��� /�@�p� ����� ��� @P����_�~���?W���~_����?���o�������������?���@�?��@�� ?��̀ �� t��A)p� ��0��0$d0�)p�p��P@!�p���аP&��A� A@���P� ����{������7����� � �@��?��?����� � � �����������?������������ �����������~�� ��������juZ���@�b6�A��X*����P@0� @ �������������@0�/��A������?������@�@�� ������?������������?����'������������?����@`� � ��?�O��?�������@ �� �������������@�����A�����?�?�_�?�@�P@������@������A�?�@@>� ����/���������@�C����?�� � @ ��� �������À9����������5� �Ϝ$�PO)¡@�8 y�|zz}N�U���P�0@�@�������g��p\�l���V}ó�֖7&�6�gC�uv��F�w2rs�V�FW'&�6S�u6W'f�6R6�s�b��sc�aU5ES�u5ER�Ss�"��#����Ss�5EQ�{��z@S�P�N�+��+� " />

And the code is:

$decoded = base64_decode($base64StringImg);
header("Content-type: image/GIF");
return'<img src="data:image/GIF;base64,"'.$decoded.'" />';

been fighting with this for hours, what can the problem be?

Matt
  • 14,906
  • 27
  • 99
  • 149
  • That means it's not base64 encoded – Panda May 11 '16 at 13:22
  • why you decode, when you send inlined image and point to browser that this is base64-encoded data? You need to send it as is (ofc if it is an image and properly encoded to base64 format). – Wizard May 11 '16 at 14:55

1 Answers1

0

If you want to deliver the signature image on browser. you don't need to decode it. just deliver base64 encoded string and browser will show it. Check this code:

$path = '1.gif';
$type = pathinfo($path, PATHINFO_EXTENSION);
$data = file_get_contents($path);
$base64 = 'data:image/' . $type . ';base64,' . base64_encode($data);

echo $base64;

echo '<img src="'.$base64.'" />';