First edition : 16/06/2006.

This page tries to write data into inline images...while other HTML contents are present (such as this line)
This was done before HTML 5's Canvas did exist, of course.
Mthode 1 - data URL with base64()
foo
4812 octets
Mthode 2 - data URL without base64()
fooP@]L"c* #c͈S^ͺװc˞M۸sͻ NM 4+ЋQ_P Ë@P6Zy]0WT/D!lܵ' l %|zCU >WUf9PaHSE$Œgikm%B"CDc/4kt23H#L.z8N;&X Ʉ#`2]9XJfIVR%! 9{-&j喖prDchH*u& h00VX&袌6裐F*餔Vj饘f馜v,MEQ!*tXgꪲxz:J~5.C 40n!ԕCa`\HIQυ6\*XT &QAX}KB y.EV|̕,koK&*T2_E$3AJ1lEFf#2f_kZ`fLgPjFjˤ d+]~%w>s ̇m~V>HDtX!!S<]帒.Ӎ9Q0PĮL@bVhqC[W=92!%&acY3f[lV,y/o?^g_f 0at)X#W3,4<:ǝ nXGc'"W&$=xL2!U .G/x`6%[Ft'רR?-GZE[q7"_]'_bEɰi[T2!3\8ƒIz̹Ò0Ye{LU ΋L\%3^Ǥ1ax2 #ʪa3a+vl=C@6\M?/IbFzLH{4ui҆pt/rW UEp`g J 锥5C{hK\K(h['0!f6aOn`@pA8'S] JO®oJ2Q;::s*I%.L!‹PiI-w YI,ĬrqgH"c^nj0ˌéHOs?^n+aYGqiYCfAP6;tkaR/50z}ȨUf9$[b()v ;3,UqcuvJ/}$%t>-VSSaOWRƂeV- qzJ=meL[s pK#r9^ @lIvSlBNu.T|h `M: xUJ"o'۫jsYѭ8c󩱰϶RB#K0W@qO"ܢNmz_q4*z&Ȝ $vlTK\]RvF<C(pb!2Y|;i'WS*Zتo+2Yx*#EӣA w*U Quð~ *msxg~J9C3$4pdT=?QH=I&2u֐HeQJ'&Ghduevu2Z f \f /fQx8:<؃>@B8DX4&FЄOHN( " [2 :PHjX JXWq-9#0o8P W(~h.# C0\8ls " X"Њ+ (XHgRZU@¨xh[hu8rh)Zx$Hc(cXЈ娅chꨌV8؍"0ax hQ脼xȋ脪kt$M(8|Qh9yh$iXh0s($A/iXxWhP"*ɋ9(YHyx9脄؅9IȨɅ(%! le#p9|ȐSx'p9PUɊ]")mȆ HXً𠙘ydsJP腗y "ɋY0)J,]ciMɅk)pX^r<9(\%@0XX#)yyۉp؞X9 fiY\yyZ#Iu u(ahM H iZcy[ZX7ZH٠ jXi#0l 80Z\ȡYX  jXO0II|( xgz8Wz߹_F 2b*e6;">Mthode 3 - javascript URL
foo
Code :
$NbLignes=9;
$lines=array('test 1st line','2nd line','3rd line','last line','autre ligne','encore une ligne','et encore une...','on va s\'arrter l ?','on termine ici...');
$imgname='test.gif';

// cre l'image
// le chemin doit tre absolu (ne marche d'ailleurs pas avec Zindoze et PHP <= 4.2.3
$path_to_font_file=dirname($_SERVER['SCRIPT_FILENAME']).'/jGara2.ttf';
$haut=ImageFontHeight(3);
$larg=ImageFontWidth(3);
$im=imagecreate(80*$larg,40+18*$NbLignes);
$black=ImageColorAllocate($im,255,255,255); // est blanc en fait
$white=ImageColorAllocate($im,0,0,0); // est noir en fait
$grey=ImageColorAllocate($im,153,153,153);
$poubBool=True;
for ($i=0;$i<$NbLignes;$i++) {
  //VGR18102004 OLD for bitmaps :       ImageString($im,$fontcode,2,20+20*$i,"$lines[$i]",$white);
  ImageTTFText($im,14,0,2,20+20*$i,$white,$path_to_font_file,"{$lines[$i]}");
} // for

ImageTTFText($im,10,0,2,20+20*$NbLignes,$grey,$path_to_font_file,'offert par VGR, http://www.edainworks.com');

// get image real contents
ob_start();
ImageGIF($im); //VGR REM add ,$imgname to push to disk and return with a Header('Content-type: image/gif');
$ImageData = ob_get_contents();
$ImageDataEnc = base64_encode($ImageData);
ob_end_clean();

// renvoi de l'image - mthode 1 data URL
echo 'Mthode 1 - data URL with base64()<br>
<img alt="foo" src="data:image/gif;base64,';
echo $ImageDataEnc;
echo '">';
echo '<br>'.strlen($ImageDataEnc)." octets<br>";
echo 'Mthode 2 - data URL without base64()<br>
<img alt="foo" src="data:image/gif;';
echo $ImageData;
echo '">';
echo 'Mthode 3 - javascript URL<br>
<img alt="foo" src="javascript:\'';
echo $ImageDataEnc;
echo ';\'">';

Rsultats :
Mthode 1 OK avec FX, KO-BrokenImg avec IE6
Mthode 2 KO-garbage avec FX et IE6
Mthode 3 KO-BrokenImg (enc64) ou KO-garbage avec FX et IE6

Vincent Graux (VGR) for European Experts Exchange and Edan Works  back to list of test scripts
Last update 2024-05-10 14:04:24