1
 $data = b"""
    \x00\x00\x01\x00\x01\x00\x10\x10\x00\x00\x01\x00\x18\x00h\x03\x00\x00\x16\x00\x00\x00(\x00\x00\x00\x10\x00\x00\x00 \x00\x00\x00\x01\x00\x18\x00\x00\x00\x00\x00\x00\x00\x00\x00d\x00\x00\x00d\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00X;ÿ%\x1Cï\t$÷\x07\x11ÿ$\x16ÿ\x11\x1Eü\x13\x19ôçó÷ÈÈø\x07\fû#\x1Fÿ\e\x15ÿ\x0E\x17û,$ú\x13\x17èAHÿODÿ%\x1Dÿ\t\x11ÿ\x18\x0Eú)\x04ô\x1C\n
    ñ-\x1AóïÝÿµ±ý\f\tï\x1F\x07ï \x07ñ\x19\x11ø%\tÿ(\x1AÿTOÿFLó!\x1Cô21ý•›þ©÷—–þ““÷üôÿêåÿŽÿ£‘ü¦žõƒ“ý'\x1Dó\e\x1DóISôELõ\e\x0FñO?þìüÿüÿ÷ñüÿêüÿúþÿûþÿóúÿÿúÿøÿõÒíÿ,)ô\e\e÷ORú;Mø\x13\fýN4ÿðõÿÿûýÿüÿÿÿéÿþ÷üÿïÿÿîÿþÿþþþÛãÿ*\eÿ$\x15ÿWLü0Aü\r\rùL;üòùÿÿýþϰ™’f\x1F•`.a+•g1ØÌ°ÿÿùÞáÿ$!ò\x15\x16ôACÿxÿYRùuëõü÷ÿþÿÎ¥„~6\x00C\x01@\x03‹3\x04àϨÿÿøëåübkëXañ}ÿÿÿòø÷ÿÿûÿÿÿéöïþͤ‹‹?\x00˜S\x03”M\x039\x11ÍÓ°øöõÿþûøùÿÿþýÿÿò‹}ÿLYûmoýøôÿÿþüǬl~A\x00‡D\x00E\x00z7\x06æØ£öÿéìîÿhe÷Saúˆ~ÿBFø\x00\fèD>÷ýüÿÿÿøÔ¨›”[\x1Ee*£c-•Z3ëÍÂÿÿôëãÿ,\x12ø\x06\fóFOöIIÿ\x12\x0FøM9þöþóÿÿôÿöÿÿþôÿøÿÿøÿÿüùý÷ÿûÿùìêÿ:\x14ÿ\x1F\x16ÿKRý?Gþ\x18\x1CñJBúîúÿöÿòúÿþÿÿþÿúýÿÿñýÿþñúýøÿùçóÿ7,ç\x1C ñCMþJAÿ&\x17ô6(ü”ŽÿŸ™ÿŸý üþûöçåñŸÿ˜•øŸ˜ÿŒÿ,&é&\x1AðYNÿQIÿ+\x1Cù\x16\x14ÿ\v\x11ø\t\tï\x06\fù\x0E\x0EöÑ÷ü©Ãÿ\x02\x00ô\x08\rò\f\x06í\n
    \x0Fô\x18\x18ÿ&\x15ùXOÿ;Aþ"\x1Eé\x1C\x1Eø\x19 ó'\x1Aò\e\x13ô3#ýææÿµ°ÿ \x12ì+\x1Eö5\eÿ\x19\eõ\e ÿ$\x1DðFLÿýüÿÿþúøøÿøÿþÿþýîþÿíõÿÿÿóÿÿùêýÿúÿÿÿõÿöþ÷øÿþÿÿøûùÿ\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00
    """

The above data is image binary data. I am converting the above binary data into actual image. I have written the code as follows:

Note: I am using image intervention package - Laravel and I have written the code for displaying favicons of banks(Financial Institutions). This api is provided by Yodlee Interactive.

$img = Image::make($data)->save('images/favicons/icon1.jpg');
 return $img->response();

OR

$img = Image::make($data)->save('images/favicons/icon1.ico');
   return $img->response();

When I am executing the code, I am getting following error,

NotReadableException in Decoder.php line 91:
Unable to init from given binary data.
Vadim Kotov
  • 8,084
  • 8
  • 48
  • 62
  • 2
    Possible duplicate: http://stackoverflow.com/questions/30334202/unable-to-init-from-given-binary-data Ultimately it can't decode your binary data. Where did it come from? – Matt Feb 16 '16 at 05:23

2 Answers2

1

The response you receive is not byteArray, it is string so you probably have to first convert into byte array and then into image.

This should give you some pointers to start.

<?php

   //Here write your code to get $byte_array
    $data = base64_decode($byte_array);
    $im = imagecreatefromstring($data);
    header('Content-Type: image/jpeg');
    imagejpeg($im);
    imagedestroy($im); 
?>

Or you can probably refer to these links.

Converting a byte array into an image using PHP and HTML

http://www.zoubi.me/blog/php-get-image-byte-array

Community
  • 1
  • 1
Apoorv Awasthi
  • 1,397
  • 1
  • 12
  • 20
0

Please use the following sample code for getting the captcha image.

$bytes = array(Paste byte-array from Yodlee-API response here Ex: 0,2,3,4,1,1,1);
$byteArray = implode(array_map("chr", $bytes));
$imgData =base64_encode($byteArray);
$img = "<img src= 'data:image/jpeg;base64,$imgData' />";
print($img);

Hope this helps.

Regards,

Krithik N

Krithik
  • 224
  • 1
  • 3