1

Getting raw png data from an api I am using, from the docs it is supposedly base64 png but it does not look like it to me. The data comes back in either of 2 forms

PNG%0D%0A%1A%0A%00%00%00%0DIHDR%00%00%00�%00%00%00�%08%06%00%00%00=�%062%00%00%00%09pHYs%00%00%0E�%00%00%0E�%01�+%0E%1B%00%00 %00IDATx%01%00��q~%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00

or like

PNG   IHDR��=�2 pHYs���+ IDATx��q~J@7J@7�ɭ� IDATJ@72.*D2.*D������'$ �2-($J@7����.)&j��������6 6��n����J@7����(%!R���M���H� ���$�������N�����>�0����J����M+(���������J@7����/*&���< ���"������ �����������  ��� ����"�D#!-����2-

could someone help me identify what this is being returned, and how can I decode it to be used as a img src?

E.Crompton
  • 11
  • 1
  • 1
    The second is definitely not base64 encoded. The first string doesn't seem to be valid either? – evolutionxbox Feb 07 '22 at 21:06
  • Well, it's pretty easy. If it's actually base64 encoded PNG, then you can use a data: URI to reference it in HTML (see [convert base64 to image in javascript/jquery](https://stackoverflow.com/q/21227078/215552)) – Heretic Monkey Feb 07 '22 at 21:08
  • 1
    If it's not, go back to the people who told you it is, explain how they are wrong, and let them modify their code to get you the correct data in the correct format :). – Heretic Monkey Feb 07 '22 at 21:10
  • It's not a base64. The first one is an URL-encoded binary %)), the second one is binary. Your data source is screwed up. – Kosh Feb 07 '22 at 21:16
  • Actually you might use binary as well. Please show your code where you receive the data and apply it to the image. – Kosh Feb 07 '22 at 21:18
  • After, binary was suggested, I tried this hextobase64 function `function hexToBase64(str) { return btoa(String.fromCharCode.apply(null, str.replace(/\r|\n/g, "").replace(/([\da-fA-F]{2}) ?/g, "0x$1 ").replace(/ +$/, "").split(" "))); }` seems to give variations of AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAPwAAAAAAAAA= this result. – E.Crompton Feb 07 '22 at 21:27

0 Answers0