How to change Background5

Asked by At

I have here a php script, and this make from text a picture.

Now is it text with and background from png ist black.

Left and rigth from the png is background black.

The png is in center, that is ok.

how can left and rigth from the png change to Gray ?

I suspect that I have to insert something with html for the background, but I do not know

<?php
class ascii2image
{
var $nfo;
var $font;
var $file;
var $id;

function loadnfo($id)
{
    $this->id = $id;
    $path = $id;
    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($font.".phpfont") ) {
        $this->font = $font;
    } else {
        exit("No font file found");
    }
}

function doImage($savepath)
{
    $nfolines = explode("\n", $this->nfo);
    $font = imageloadfont($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($image, 0, 0, 0);
    imagecolortransparent($image, $white);

    $black = ImageColorAllocate($image, 0, 0, 0);

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

    $poweredby = "MEEE";
    $wid = ($width - ($fontwidth*strlen($poweredby) ) ) / 2;
    ImageString($image, $font, $wid, $i, $poweredby, $black);

    ImageAlphaBlending($image, true);
    if ($this->file == true ) {
        ImagePNG($image,$savepath);
    } else {
        ImagePNG($image);
    }
    ImageDestroy($image);
}

}

0 Answers