base64 encode image blob not showing in IE - php

echo '<img src="data:image/jpg/png/jpeg;base64,' . base64_encode( $row['image'] ) . '" height="150" />';
This is showing up images great in firefox, safari and chrome, but in internet explorer it shows a nice red cross, and I assume it is because of the encoding?

Try replacing data:image/jpg/png/jpeg; with either data:image/jpeg; or data:image/png; depending on the format of the image. You can't expect it to be both a PNG and a JPEG.

Most likely old IE or too big image for IE8.
IE7 and below definitely don't support it. IE9 support inline images just fine. I IE8 have limited support. - Check out http://en.wikipedia.org/wiki/Data_URI_scheme for list.

Related

convert base64 string to .tiff image

Case : I have images in BLOB format in database and from database getting the images in base64 string. My code was working fine when images was .jpeg.
Code:
<?php $img = $image['PRODUCT_IMAGE']->load(); ?>
<img src="data:image/jpeg;base64,<?php echo base64_encode($img); ?>" />
Now suddenly my db administrator converted all images in .tiff format and i have to change my code to support .tiff format. I have been trying for solution but didn't find anything in this case.
In most scenarios they have .tiff file to convert example.
please have me achieve one of the following solution
Convert base64 to .tiff that some browser don't support.
Ask our DB administrator to change the format of all images.
As you guess i don't have the solution to 1 and 2. 3 is not likely to happen.

How to load image blob?

I have an image in binary blob field and I am unable to read.
In the database looks like this:
Yes, this is the shape of the image into text.
This and how image:
I tried several things and the only one that approximates the expected result was:
echo '<img src="data:image/jpeg;base64,'.base64_encode( $result->fields['LOGO'] ).'"/>';
Resulting in:
Content 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 perform the reading of the image correctly in php?
OK, you are definitely using wrong MIME type. Since you said in the comment that original image is BMP, try:
echo '<img src="data:image/x-windows-bmp;base64,'.base64_encode( $result->fields['LOGO'] ).'"/>';
or:
echo '<img src="data:image/bmp;base64,'.base64_encode( $result->fields['LOGO'] ).'"/>';
If it still doesn't work, try skipping first 8 bytes, simple substr might work here. You need to skip 8 bytes, since bitmap adds 4 bytes as header for specific image type (in your case: BM) and 4 more for file size. You can find more info on Bitmap file header here.

Rough Edges Converting SVG to PNG with PHP

I'm using the following script to generate an scaled up PNG version of an SVG.
<img src="barrington.svg" width="418" height="188"/> //comparison
<?php
$im = new Imagick();
$im->setBackgroundColor(new ImagickPixel('transparent'));
$svg = file_get_contents("barrington.svg");
$im->setresolution(144,144);
$im->readImageBlob($svg);
$im->setImageFormat("png32");
echo '<img src="data:image/png32;base64,' . base64_encode($im) . '" />'
?>
When displayed/compared to the SVG version at the same size, the PNG has jagged edges around some of the image.
(see image here: http://i.stack.imgur.com/WGKIH.png)
I'm using ImageMagick (if it wasn't already obvious) and would like to fix this problem.
EDIT:
To clarify, for my purposes I need a PNG and not an SVG. This isn't an issue of fixing compatibility in browsers or something.
Generally there is confusion on setImageResolution and setResolution. So you may want to try setImageResolution along with setResolution and see if your edge issue is corrected. From my understanding setResolution is correct for density, but you want to still set your image size. Plus 144 may not be enough high enough density.
If not, then resizing an image is always a possibility. Make the image 2x larger then it needs to be and then resize it.

longblob base64 image from db

I am getting my image as a longblob from my mysql database, I got a bit of my code for you. This works in chrome but in IE8 the image do not render properly, or the img cannot be found.
<div class="car-image"><a href="carinformation.php?id='.$row["id"]. '"><img width="500px" height="200px" src="data:image/jpeg;base64,'. base64_encode($row["picture"]). '" />';
IE8 doesn't like data URLs that are over 32k characters long. Is your URL longer than that?
I tried the same logic and succeeded in IE 8.
Did you use base64encode for base64encoded string?

Base64 Encoding Image

I am building an open search add-on for Firefox/IE and the image needs to be Base64 Encoded so how can I base 64 encode the favicon I have?
I am only familiar with PHP
As far as I remember there is an xml element for the image data. You can use this website to encode a file (use the upload field). Then just copy and paste the data to the XML element.
You could also use PHP to do this like so:
<?php
$im = file_get_contents('filename.gif');
$imdata = base64_encode($im);
?>
Use Mozilla's guide for help on creating OpenSearch plugins. For example, the icon element is used like this:
<img width="16" height="16">data:image/x-icon;base64,imageData</>
Where imageData is your base64 data.
$encoded_data = base64_encode(file_get_contents('path-to-your-image.jpg'));
My synopsis of rfc2397 is:
Once you've got your base64 encoded image data put it inside the <Image></Image> tags prefixed with "data:{mimetype};base64," this is similar to the prefixing done in the parenthesis of url() definition in CSS or in the quoted value of the src attribute of the img tag in [X]HTML. You can test the data url in firefox by putting the data:image/... line into the URL field and pressing enter, it should show your image.
For actually encoding I think we need to go over all your options, not just PHP,
because there's so many ways to base64 encode something.
Use the base64 command line tool. It's part of the GNU coreutils (v6+) and pretty much default in any Cygwin, Linux, GnuWin32 install, but not the BSDs I tried. Issue: $ base64 imagefile.ico > imagefile.base64.txt
Use a tool that features the option to convert to base64, like Notepad++ which has the feature under plugins->MIME tools->base64 Encode
Email yourself the file and view the raw email contents, copy and paste.
Use a web form.
A note on mime-types:
I would prefer you use one of image/png image/jpeg or image/gif as I can't find the popular image/x-icon. Should that be image/vnd.microsoft.icon?
Also the other formats are much shorter.
compare 265 bytes vs 1150 bytes:
data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAMAAAAoLQ9TAAAAVFBMVEWcZjTcViTMuqT8/vzcYjTkhhTkljT87tz03sRkZmS8mnT03tT89vTsvoTk1sz86uTkekzkjmzkwpT01rTsmnzsplTUwqz89uy0jmzsrmTknkT0zqT3X4fRAAAAbklEQVR4XnXOVw6FIBBAUafQsZfX9r/PB8JoTPT+QE4o01AtMoS8HkALcH8BGmGIAvaXLw0wCqxKz0Q9w1LBfFSiJBzljVerlbYhlBO4dZHM/F3llybncbIC6N+70Q7OlUm7DdO+gKs9gyRwdgd/LOcGXHzLN5gAAAAASUVORK5CYII=
data:image/x-icon;base64,AAABAAEAEBAAAAEAIABoBAAAFgAAACgAAAAQAAAAIAAAAAEAIAAAAAAAAAQAAAAAAAAAAAAAAAAAAAAAAAD/////ZmZm/2ZmZv9mZmb/ZmZm/2ZmZv9mZmb/ZmZm/2ZmZv9mZmb/ZmZm/2ZmZv9mZmb/ZmZm/2ZmZv///////////2ZmZv9mZmb/ZmZm/2ZmZv9mZmb/ZmZm/2ZmZv9mZmb/ZmZm/2ZmZv9mZmb/ZmZm/2ZmZv9mZmb///////////9mZmb/ZmZm//////////////////////////////////////////////////////9mZmb/ZmZm////////////ZmZm/2ZmZv//////ZmZm/2ZmZv9mZmb/ZmZm/2ZmZv9mZmb/ZmZm/2ZmZv//////ZmZm/2ZmZv///////////2ZmZv9mZmb//////2ZmZv9mZmb/ZmZm/2ZmZv9mZmb/ZmZm/2ZmZv9mZmb//////2ZmZv9mZmb///////////9mZmb/ZmZm////////////////////////////8fX4/8nW5P+twtb/oLjP//////9mZmb/ZmZm////////////////////////////oLjP/3eZu/9pj7T/M2aZ/zNmmf8zZpn/M2aZ/zNmmf///////////////////////////////////////////zNmmf8zZpn/M2aZ/zNmmf8zZpn/d5m7/6C4z/+WwuH/wN/3//////////////////////////////////////+guM//rcLW/8nW5P/x9fj//////9/v+/+w1/X/QZ7m/1Cm6P//////////////////////////////////////////////////////7/f9/4C+7v8xluT/EYbg/zGW5P/A3/f/0933/9Pd9//////////////////////////////////f7/v/YK7q/xGG4P8RhuD/MZbk/7DX9f//////4uj6/zJh2/8yYdv/8PT8////////////////////////////UKbo/xGG4P8xluT/sNf1////////////4uj6/zJh2/8jVtj/e5ro/////////////////////////////////8Df9/+gz/P/////////////////8PT8/0944P8jVtj/bI7l/////////////////////////////////////////////////////////////////2yO5f8jVtj/T3jg//D0/P///////////////////////////////////////////////////////////3ua6P8jVtj/MmHb/+Lo+v////////////////////////////////////////////////////////////D0/P8yYdv/I1bY/9Pd9///////////////////////AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA==
Check the following example:
// First get your image
$imgPath = 'path-to-your-picture/image.jpg';
$img = base64_encode(file_get_contents($imgPath));
echo '<img width="100" height="100" src="data:image/jpg;base64,'. $img .'" />'
Google led me to this solution (base64_encode). Hope this helps!

Categories