How to load blob field image?

Asked

Viewed 782 times

5

I have a binary image of a blob field and I can’t read it.

In the database it looks like this:

inserir a descrição da imagem aqui

Yes, this is the text image shape.

This is how image:

inserir a descrição da imagem aqui

I tried several things and the only thing that came close to the expected result was:

echo '<img src="data:image/jpeg;base64,'.base64_encode( $result->fields['LOGO'] ).'"/>';

Which resulted in:

inserir a descrição da imagem aqui

Contents of the blob taken from a select:

BM606(@@0``ÿÿÿÿÿÿøøøøøøÿÿÿÿÿÿÿÿÿèèèOOOBBBTTTTTTSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSQQQPPPPPPPPPPPPRRRTTTSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSTTTBBBOOOèèèÿÿÿÿÿÿgggEEE===,,,@@@======@@@+++>>>EEEgggÿÿÿÉÉÉ666+++    444111111444  ***666ÉÉÉ$$$     ;;;777777;;;      $$$     !!!???;;;;;;???"""  #GVLqz ¨´­gih     $$$BBB>>>>>>BBB$$$!+$/J8@cNX{eu® ¿ÌÄ   ³³³&&& '''FFFBBBBBBFFF&&&(D2.Z>6dGGqVap¡¬ÁµÐÝÖMOO*N8&K5#9+' %%%´´´ÄÄÄ---)))JJJFFFFFFJJJ((( %"*N7(Z;/`A?mQLqaOcZT[S`c`lmh'L4(a?(_=-`A0F8---ÄÄÄÑÑÑ555+++NNNJJJJJJNNN***)P7%[9+^=;iO5E=:)H$P$M K"O, 9&!A0)b@)dA.eC(5-666ÑÑÑÝÝÝ@@@...RRRMMMMMMRRR---'C2&\:'^<8bL/0)H#^/`3^/X&^/`3_2U, 1E0*iF,fC*gA2aD@@@ÝÝÝèèèKKK000VVVQQQQQQVVV000!*$([<'a=5eJ.1,O'c4`-[&rK%¢rK%[&_,g1J@/M@)N8,kD.jF,B4LLLèèèñññUUU222ZZZUUUUUUZZZ222'F2(d?/gD,@8C!f6m< |d{T5ÈÒÚ{T5|dm< e5K(&$-fC-oG3_CUUUñññúúú]]]555^^^YYYYYY^^^333!+Z<+iB4cJ-$c4n7eAÈÎÕÄÈÊÊÑ×ÃÇÊÊÑ×ÄÈÊÈÎÕe@m5g81$'R;.sI4oJ)1,]]]úúúÿÿÿiii777bbb]]]]]]bbb777,<2,fB/nF-M?=#o>t:u>ÂÀ¾ÍÑפw\6¤wÍÑ×ÂÀ¾u>t:o>E* :01tK4vN?YG iiiÿÿÿÿÿÿxxx"""999gggaaaaaaggg9998YC.mF2qJ)=6H' v>^.µ¤ÖÜã±s4x<s4±ÖÜ㵤_-u=R0#5/1uL4{P@jO"""xxxÿÿÿÿÿÿ%%%===lllffffffmmm>>>&O40rI5uN'84I${<«kèöÿÜàè¦Y}=P}=¦ZÜàèèöÿ¬ky;T/%613zO7S9fJ%%%ÿÿÿÿÿÿ(((@@@sssllllllsss???2Z@2vK5xO)<6J) IZ¯cãéîÌÀ²H@HÌÀ²ãéî¯cZHR1#:25R:WHlV***ÿÿÿÿÿÿ,,, !!! !!! !!!  !!!   !!!!!!CCCxxxqqqqqqxxxCCC6N>3wL5|P/K?8"JS\ßÝÛìôþÕɺº~ÕɺìôýßÝÛ\SJA+%J98W=Z;KA---ÿÿÿÿÿÿ©©©000 ###### """"""!!!!!!""""""""" ###"""!!! """$$$""" """!!!!!!FFF{{{tttttt{{{FFF '.*3rJ5R7fJ) i;WµLñøÿäáÛðõûð÷þðõûäáÛñøÿµLUo?2,,2pL;\?}X)))111©©©ÿÿÿÿÿÿµµµ444 !!!"""#########$$$"""###!!!!!!###""""""""""""###"""!!!$$$"""###$$$"""###GGGyyyyyyGGG###$##3bD7T9~S+63;"I¯fºE¦bÌ«ÿÿÿÌ«¦bºE­dIG-)C8;Y=_?fM""" 444¶¶¶ÿÿÿÿÿÿÀÀÀ888!!!###$$$$$$%%%%%%%%%######"""$$$%%%$$$$$$###$$$$$$$$$$$$%%%$$$%%%%%%$$$###KKK~~~~~~JJJ$$$$$$/D77S9W9hK,TDII(I±f²e¹zÒªn¹z²e°dMT3/648T>bDa183### 888¿¿¿ÿÿÿÿÿÿËËË;;;"""&&&%%%%%%%%%%%%%%%&&&((($$$%%%%%%%%%%%%%%%$$$%%%&&&%%%%%%%%%%%%$$$%%%(((LLLLLL&&&%%%(((6oK:Y9U9X<[HB$r?Y¨b¦[§aYuB I-187:{V@dAdAdN$$$&&&$$$<<<ÊÊÊÿÿÿÿÿÿÔÔÔ@@@%%%&&&&&&&&&((('''((('''((((((%%%&&&&&&&&&&&&''')))''''''%%%'''''''''''''''PPPPPP'''&&&&&&0=58T;[<Y9bI'''3*%C*N)S+ U/H-9316SF@]C hBgI~\,*+''''''%%%AAAÕÕÕÿÿÿÿÿÿÞÞÞDDD$$$'''((('''(((((())))))(((((()))(((((((((((()))'''&&&((('''((()))))))))'''@@@jjjeeeeeekkk???$$$'''(((3N<:U<Z;[AwT''' ¶¯j|uYkbMf[Fr_IfIkG¦lE¡iH]222((())))))%%%EEEÞÞÞÿÿÿÿÿÿçççJJJ&&&(((***+++***))))))+++((()))***+++***)))++++++)))(((***+++***)))***!!!OOO¹¹¹³³³²²²µµµµµµ²²²³³³¹¹¹LLL ***-1.0834J<9fI8fIGJHÎäÖºÞÈϱÀkµ\°}R®vL¨pJjCjR/,.******)))***'''JJJæææÿÿÿÿÿÿîîîUUU)))+++***+++***++++++++++++---+++)))+++++++++,,,***++++++***+++***+++!!!XXXÞÞÞØØØÍÍÍÃÃÃÃÃÃÍÍÍ×××ÝÝÝXXX ***+++)))+++,,,***rxt±Æ¹¦Í´Ç¥w¼g³Y¨wNgCoT7?:***+++******++++++)))WWWíííÿÿÿÿÿÿóóó___+++---,,,+++---,,,...,,,***---,,,+++,,,...---,,,+++---...+++,,,,,,---!!!WWWÚÚÚÔÔÔÄÄÄÃÃÃÃÃÃÄÄÄÓÓÓÙÙÙXXX$$$,,,,,,,,,,,,---++++++9:9U\Wh~po{[yeCRH000,,,------+++,,,,,,...++++++aaaóóóÿÿÿÿÿÿùùùjjj---------...000---...///............///......///------------111---...$$$^^^ãããØØØÙÙÙïïïîîîÙÙÙ×××âââ\\\###,,,//////---//////............000///......---------...000---...---000kkkøøøÿÿÿÿÿÿýýýsss222///...///000/////////111///000///000000//////111000///...000//////###MMMÌÌÌ¿¿¿ÅÅÅÖÖÖÖÖÖÅÅÅÀÀÀËËËLLL$$$...000000/////////000///000000000000...///111000...///000//////...333tttýýýÿÿÿÿÿÿÿÿÿ666000222222///111111111111222111111333111111111111222222222000111111111hhheee000111111///222222111111222111222222000111111111222222222000111111///666ÿÿÿÿÿÿÿÿÿÿÿÿ222000111111111111222000000111111222222222333333111222111111111111...:::ÆÆÆÑÑÑÌÌÌÊÊÊÉÉÉÇÇÇÇÇÇÆÆÆÊÊʾ¾¾999...111111222111111000222222222333111333222222222111111111111222...222ÿÿÿÿÿÿÿÿÿÛÛÛWWWIIIJJJIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIHHHIIIIIIIIIIIIJJJIIIIIIIIIIIIEEEQQQÛÛÛäääÞÞÞÝÝÝÜÜÜÛÛÛÚÚÚÙÙÙÝÝÝÒÒÒQQQFFFIIIIIIIIIIIIIIIIIIIIIIIIHHHIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIHHHHHHWWWÛÛÛÿÿÿõõõkkk888ÁÁÁ÷÷÷ïïïîîîíííííííííìììòòò»»»888kkkõõõ¢¢¢999PPPöööîîîììììììììììììîîîöööPPP999¢¢¢^^^+++UUUùùùñññïïïîîîîîîîîîðððøøøUUU+++]]]PPP&&&       ZZZÿÿÿøøøõõõõõõôôôóóó÷÷÷ÿÿÿZZZ !!!     &&&QQQaaa&&& !!!""""""""""""!!!###!!!"""""""""!!!!!!"""###!!! """"""""""""!!!"""ZZZøøøöööõõõôôôôôôõõõõõõ÷÷÷ZZZ!!!!!!""""""###!!!""""""!!! !!!"""###!!!!!!""""""!!!"""!!!"""!!!"""!!!&&&bbbwww((("""###$$$$$$######$$$############$$$""""""$$$############$$$######$$$###!!!---AAAiiihhhAAA---!!!$$$"""$$$$$$###$$$"""############$$$######"""$$$#########$$$######$$$!!!(((www+++$$$$$$%%%&&&%%%%%%&&&%%%%%%$$$$$$%%%%%%%%%$$$%%%%%%%%%$$$&&&%%%%%%&&&%%%&&&"""DDD||||||FFF!!!'''%%%%%%&&&%%%%%%&&&$$$$$$%%%$$$%%%$$$%%%&&&$$$%%%%%%%%%&&&&&&%%%%%%$$$"""+++///%%%''''''((('''(((''''''&&&&&&'''((('''''''''''''''((('''''''''''''''''''''&&&PPPPPP'''((('''''''''&&&'''&&&&&&'''((('''''''''''''''''''''(((''''''''''''&&&&&&&&&...¯¯¯333''')))))))))***))))))***+++)))))))))((())))))((())))))))))))***)))*********))) TTTTTT!!!))))))))))))))))))******))))))((())))))))))))***)))))))))***)))))))))***)))'''333°°°½½½;;;***++++++***,,,,,,,,,+++,,,,,,,,,,,,++++++,,,,,,,,,+++***+++,,,---,,,+++,,,,,,###YYY      ZZZ###+++***+++,,,,,,+++,,,,,,,,,,,,+++***++++++---,,,+++******,,,,,,,,,+++,,,,,,***999½½½ÉÉÉAAA+++,,,............//////---............///.........,,,---...///......///...---%%%aaa¬¬¬££££££­­­aaa###---............//////......///...///...//////---,,,---............///......---@@@ÉÉÉÕÕÕGGG///000111111111111000111000111111111111000111111111///111111111000000000111111'''iii»»»±±±±±±»»»hhh%%%000111111000000000111000111000222111///111111111000111111111000000111000000///GGGÕÕÕàààTTT555888777777777777888888666888777666666777888777666888777777888777777888666888---qqqÉÉɾ¾¾¾¾¾ÉÉÉqqq,,,888777777666777888777777888777666777888888777777999777777777666888888666888666UUUáááëëëiiiBBBFFFGGGEEEFFFEEEFFFFFFDDDFFFFFFEEEFFFGGGFFFEEEDDDEEEGGGDDDFFFEEEFFFFFFDDDEEE;;;~~~ÖÖÖËËËËËËÖÖÖ~~~999GGGEEEEEEFFFFFFFFFEEEEEEFFFEEEDDDFFFFFFFFFEEEDDDFFFFFFEEEFFFEEEFFFFFFDDDFFFCCCiiiìììôôôVVVXXXVVVVVVZZZVVVXXXYYYXXXWWWWWWWWWXXXXXXXXXWWWXXXWWWWWWUUUYYYWWWWWWYYYYYYWWWLLLâââ××××××âââMMMWWWUUUXXXYYYVVVXXXXXXWWWWWWWWWWWWXXXXXXXXXWWWWWWXXXVVVWWWYYYVVVXXXXXXYYYWWWVVVôôôûûûiiijjjiiijjjiiiiiijjjiiikkkjjjjjjjjjjjjhhhhhhhhhkkkkkkjjjjjjiiiiiiiiiiiijjjkkk___êêêààààààêêêbbbkkkjjjjjjiiijjjiiiiiikkkiiijjjkkkiiiiiigggiiikkkjjjiiijjjiiiiiiiiihhhjjjjjjhhhûûûÿÿÿ¥¥¥xxxzzz{{{zzzxxxyyy|||xxxxxx{{{zzzyyy|||zzz{{{zzzyyy{{{{{{zzzyyywww{{{yyywwwyyyppp¥¥¥ïïïææææææïï襤¤ppp{{{{{{zzzwwwzzzzzzxxxyyyzzzyyyzzz|||zzz|||yyyyyyzzzzzzzzzxxxyyy{{{xxxwwwzzzxxx¦¦¦ÿÿÿÿÿÿ²²²}}}¬¬¬ñññééééééñññ¬¬¬²²²ÿÿÿÿÿÿ¹¹¹­­­íííååååååììì°°°¹¹¹ÿÿÿÿÿÿººº¥¥¥áááÚÚÚÚÚÚáá᧧§~~~ºººÿÿÿÿÿÿÅÅÅpppmmmooonnnmmmmmmnnnmmmnnnoooooolllnnnmmmlllooonnnnnnnnnooolllnnnmmmmmmmmmooohhhÏÏÏÈÈÈÈÈÈÏÏÏeeemmmnnnmmmnnnmmmmmmllloooooonnnllloookkkmmmooommmmmmnnnnnnmmmnnnnnnlllnnnnnnrrrÅÅÅÿÿÿÿÿÿííí]]]MMMOOOOOOQQQOOOMMMQQQMMMMMMOOOOOOOOONNNNNNOOOOOONNNOOOOOOPPPPPPMMMPPPOOOMMMGGG{{{ººº²²²²²²ºººzzzFFFNNNOOOPPPQQQMMMNNNPPPLLLNNNOOONNNNNNNNNNNNPPPOOONNNOOOOOOPPPOOOMMMQQQMMMLLL]]]îîîÿÿÿÿÿÿÿÿÿ¼¼¼666---............---...///......///...,,,,,,,,,------++++++//////------///%%%___££££££^^^%%%...---///...///******------------...---------...///---......///...---...666¼¼¼ÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿËËËlllNNNMMMNNNMMMMMMNNNNNNMMMRRRCCC!!!!!!!!! !!! !!!$$$IIIQQQNNNNNNOOOFFFwww±±±ªªªªªª±±±wwwGGGOOONNNNNNQQQJJJ### !!! !!! !!!CCCRRRMMMNNNNNNNNNNNNOOONNNMMMlllËËËÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿëëëzzz||||||}}}qqq|||õõõÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿõõõ|||qqq~~~||||||zzzëëëÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿéééåååÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿåååéééÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÙÙÙRRRHHH\\\hhhsss{{{{{{sssiii]]]HHHSSSÚÚÚÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿ§§§¤¤¤EEE111222000///...------,,,,,,------...///000111000EEE¤¤¤¨¨¨ÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿ¢¢¢mmm```dddfffgggiiijjjjjjkkkjjjjjjjjjiiigggeeeccc```mmm¢¢¢ÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿùùù¼¼¼lllYYYYYYUUUTTTRRRRRRRRRQQQQQQPPPQQQRRRSSSUUUXXXYYYjjj¼¼¼ùùùÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿðððãããÛÛÛÔÔÔÎÎÎÉÉÉÇÇÇÃÃÃÁÁÁÁÁÁÂÂÂÃÃÃÈÈÈÍÍÍÔÔÔÛÛÛãããïïïÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿ

How can I read this image correctly in php?

  • When you save her from Base64? when displaying would not be Decode?

  • I didn’t save her, I just read, I asked a developer from Delphi, who saves this image, he said he uses a component for this and he doesn’t know about her internal process, see if he can ? what I know he is a binary type blob field.

  • and Code and Pure do not work?

  • Can extract binary content from the database and post it as well?

  • @rray neither of the two forms, Luis updated the question with the contents

  • I would recommend you to make an HTTP call to load the image, I already did the way you showed it with a large image, and it was bad for the browser to render the page.

  • @Giancarloabelgiulian as well ?

  • I created an answer to that

Show 3 more comments

1 answer

0

As I mentioned in comment on the question I prefer to make calls HTTP to display the image instead of passing a base64 in the element img.

I do this way to show the image(s)):

Controller.php:

if ($_GET['tipo'] == 'GET_FOTO_OR_IMAGE'){      
    header("Content-type: image/png");
    $codigo_exemplo = $_GET['codigo_exemplo'];
    $foto_or_image = ObjetoController::getFotoOrImage($codigo_exemplo);
    $blob_data = ibase_blob_info($foto_or_image);
    $blob_hndl = ibase_blob_open($foto_or_image);
    $image = base64_encode(ibase_blob_get($blob_hndl, $blob_data[0]));
    echo base64_decode($image);
    ibase_blob_close($blob_hndl); 
}   

Objetocontroller.php:

public function getFotoOrImage($codigo_exemplo){

    $connect = OpenConnection();
    $query = ibase_query($connect, "select FOTO from CAD_OBJETOS
        where CODIGO_EXEMPLO = ?", $codigo_exemplo);

    if ($query){

        $row = ibase_fetch_object($query);              
        $foto_or_image = new FotoOrImage();
        $foto_or_image->setFoto($row->FOTO);

        return $foto_or_image->getFoto();

        } else {
        return "Erro técnico: ".ibase_errmsg();
    }

    unset($query);
    unset($row);
    ibase_close($connect);          
}

HTML:

echo '<img src="Controller.php?tipo=GET_FOTO_OR_IMAGE&codigo_exemplo='.$codigo.'" />';

Thus avoiding the browser to lock in case the image or photo is too large when using base64, which was my case. And I believe this may be the solution to your problem including.

So the call is HTTP because instead of passing a base64 step image URL in attribute src of the element img.

  • I’m sorry, but I found your example a little confusing and I couldn’t reproduce it here. you could define just what it is to do after having all the contents of a blob image in a variable ?

  • Create a mechanism to recover the image through a URL, the example is in the file Controller.php.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.