<?

//=============================//
//                             //
//   ascii2image class           //
//   ascii2image.class.php     //
//   by Razvan Stanga          //
//   razvan_stanga@yahoo.com   //
//   http://www.phprebel.org   //
//                             //
//       MADE IN ROMANIA       //
//                             //
//=============================//

class ascii2image {
    var 
$nfo;
    var 
$font;
    var 
$file;
    var 
$id;

    function 
loadNFO ($id) {
        
$this->id $id;
        
$path "nfos/".$id.".nfo";
        if ( 
file_exists $path ) ) {
            
$filesize            =    filesize ($path);
            
$filenum            =    fopen ($path"r");
            
$cache                =    fread ($filenum$filesize);
            
fclose ($filenum);
            
$this->nfo $cache;
        } else {
            exit (
"No nfo file found");
        }
    }

    function 
loadFont ($font) {
        if ( 
file_exists "fonts/".$font.".phpfont" ) ) {
            
$this->font $font;
        } else {
            exit (
"No font file found");
        }
    }

    function 
doImage () {
        
$nfolines explode ("\n"$this->nfo);
        
$font imageloadfont ("fonts/".$this->font.".phpfont");

        
$width 0;
        
$height 0;
        
$fontwidth     ImageFontWidth ($font);
        
$fontheight ImageFontHeight ($font);

        foreach ( 
$nfolines as $line ) {
            if ( (
strlen ($line)*$fontwidth) > $width ) {
                
$width strlen ($line) * $fontwidth;
            }
            
$height += $fontheight;
        }

        
$width += $fontwidth*2;
        
$height += $fontheight*3;

        
$image ImageCreate ($width$height);

        
$white ImageColorAllocate ($image255,255,255);
        
imagecolortransparent ($image$white);

        
$black ImageColorAllocate ($image000);

        
$i $fontheight;
        foreach ( 
$nfolines as $line ) {
            
ImageString ($image$font $fontwidth$i$line$black);
            
$i += $fontheight;
        }

        
$poweredby "powered by ascii2image (c) www.phprebel.org";
        
$wid = ($width - ($fontwidth*strlen($poweredby) ) ) / 2;
        
ImageString ($image$font $wid$i$poweredby$black);

        
ImageAlphaBlending($imagetrue);
        if ( 
$this->file == TRUE ) {
            
ImagePNG ($image"png/".$this->id.".png");
        } else {
            
ImagePNG ($image);
        }
        
ImageDestroy($image);
    }

}

?>