<?php
class imgtohtml {
    
public $orig;
    
public $img;

    
public function __construct($img) {
        
$this->orig=$img;
        
$this->img=$img;
    }

    
public function resize($size$x=TRUE) {
        
$ox=imagesx($this->img);
        
$oy=imagesy($this->img);
        
$nx=($x)?$size:($size/$oy);
        
$ny=($x)?($size/$ox):$size;
        
$tmp=imagecreatetruecolor($nx$ny);
        
imagecopyresampled($tmp$this->img0000$nx$ny$ox$oy);
        
$this->img=$tmp;
    }

    
public function tohtml() {
        
$img=&$this->img;
        
$out='';
        for(
$y=0$y<imagesy($this->img); $y++) {
            for(
$x=0$x<imagesx($this->img); $x++) {
                
$clr=imagecolorat($img$x$y);
                
$rgb=imagecolorsforindex($img$clr);
                
$hex='#'.dechex($rgb['red']).dechex($rgb['green']).dechex($rgb['blue']);
                
$out.="<font color=\"$hex\">@</font>";
            }
            
$out.="<br />\n";
        }
        return 
$out;
    }
}
?>