timer=new crono(); //creamos crono $this->timer->_start(); //arrancamos el crono $this->gestor=file($source) or die(\"Cannot open file\"); if(($tmp1=strpos($this->gestor[0], \"\\n\"))==FALSE) $tmp1=strlen($this->gestor[0]); if(($tmp2=strpos($this->gestor[0], \"\\r\"))==FALSE) $tmp2=strlen($this->gestor[0]); $tmp3=($tmp1>$tmp2)?$tmp2:$tmp1; $this->size_X=$tmp3; //obviamos \\n y/o \\r $this->size_Y=count($this->gestor); $this->dictionary=array(\'M\',\'N\',\'H\',\'#\',\'Q\',\'U\',\'A\',\'D\',\'0\',\'Y\',\'2\',\'$\',\'%\',\'+\',\'.\',\' \'); ; //paleta de grises personalizada; $this->ini_pal(array(50,65,80,95,110,125,145,160,175,195,210,220,235,240,245,250)); imagefill($this->img, 0, 0, $this->color[0]); //color de fondo de paleta, para ahorro de renderizado $this->render(); $this->getImage(); } //iniciamos paleta function ini_pal($param){ $this->color=array(); $this->img = @imageCreateTrueColor($this->size_X, $this->size_Y) or die(\"Cannot Initialize new GD image stream\"); foreach ($param as $key => $value) $this->color[$key]= imageColorAllocate($this->img,$value,$value,$value); } //Realiza el render por defecto con crono function render(){ $fondo=$this->dictionary[0]; foreach ($this->gestor as $_y => $lineas){ $_x=0; while($_x<$this->size_X){ while($lineas[$_x++]==$fondo){}//no se procesa el fondo de paleta $c=$lineas[--$_x]; $_x_old=$_x; while($c==$lineas[++$_x]/*&&$_x<$this->size_X*/){} if($_x>($_x_old+1)) imageline($this->img, $_x_old, $_y, $_x-1, $_y, $this->color[array_search($c, $this->dictionary)]); else imagesetpixel($this->img, $_x_old, $_y,$this->color[array_search($c, $this->dictionary)]); } } //mostramos crono imagestring ($this->img, 2, 0, 0, $this->timer->_getTime().\" s.\", 205 ); } //genera archivo temporal de imagen function getImage(){ header(\"Content-type: image/png\"); //generamos la imagen imagepng($this->img); //liberamos la memoria ocupada por la imagen imagedestroy($this->img); } } //clase que crea un cronometro class crono{ var $timer_ini; function _start(){ $this->timer_ini=$this->microtime_float(); } function _reset(){ $this->timer_ini=$this->microtime_float(); } function _getTime(){ return ($this->microtime_float()-$this->timer_ini); } function _print(){ echo \"Timer: \".$this->_getTime(); } function microtime_float() { list($useg, $seg) = explode(\" \", microtime()); return ((float)$useg + (float)$seg); } } ?>