Mega Code Archive

 
Categories / Php / Graphics
 

WBMP for WML

<? // This is file awbmp.php header ("Content-type: image/vnd.wap.wbmp"); $sx = 95; $sy = 44; //Database $dsn = "GraphWAP"; $uid = ""; $pwd =""; // Open ODBC $fn = odbc_connect($dsn,$uid,$pwd); // Select Data $sql = "Select x,y From Graph;"; $ln = odbc_exec($fn,$sql); //LOAD PROTOTYPE $im = ImageCreate($sx,$sy); // Set Color $bgc = ImageColorAllocate ($im, 255, 255, 255); $tc = ImageColorAllocate ($im, 0, 0, 0); ImageFilledRectangle ($im, 0, 0, $sx, $sy, $bgc); // Point Start $ix = 10; $iy = 38; ImageLine($im,$ix,$iy,$ix,0,$tc); ImageLine($im,$ix,$iy,$sx,$iy,$tc); $x1 = $ix; $x2 = $x1; $y1 = $iy; $y2 = $y1; //Max X and Y $mx = 0; $my = 0; //$i=0; // Read Line while ( odbc_fetch_row($ln)) { // Read From Data Base $x2 = odbc_result($ln,1); $y2 = odbc_result($ln,2); // Check Max X and Y if($mx < $x2) $mx = $x2; if($my < $y2) $my = $y2; //Check //$i++; //echo "$i: x=$x2 y=$y2 <br>"; $x2 += $ix; $y2 = $iy - $y2; //Check Limited if($x2 > $sx) $x2 = $sx; if($y2 < 0) $y2 = 0; // Draw Line ImageLine($im,$x1,$y1,$x2,$y2,$tc); // Next Point $x1 = $x2; $y1 = $y2; } // Put Max X and Y Text; ImageString ($im, 1, 1, $iy - $my, $my, $tc); ImageString ($im, 1,$mx + $ix,38, $mx, $tc); // Put Image ImageWBMP($im); ImageDestroy($im); ?> <? // This is file "graph.php" Header("Content-type: text/vnd.wap.wml"); Header("Cache-Control: no-cache, must-revalidate"); Header("Pragma: no-cache"); echo ("<?xml version='1.0'?>"); ?> <wml> <card title ="Create Graph" id="graph" newcontext="true" > <p> <img src="abmp.php" height="45" width="96" alt="graph" /> </p> </card> </wml>