我试图弄清楚如何编写一个gd类,它将显示任何字体类型的字符串

Here is the class I have so far:

<?php

class txt2img {
    var $image;
    var $headertype;
    var $forecolor;
    var $fontsize;
    var $fontangle;
    var $font;
    var $string;

    //font size
    function fontsize($fontsize) {
        return $this->fontsize;
    }

    //forecolor
    function forecolor($forecolor) {
        return this->imagecolorallocate($this->img(),$this->forecolor);
    }

    //image file
    function img($image) {
        return imagecreatefrompng($this->img);
    }

    function display($string,$font) {
        //display all errors
        ini_set("display_errors", "1");
        error_reporting(E_ALL);

        header('content-type: image/png');
        $fcolor = $this->forecolor();

        imagettftext($this->img(),$this->fontsize(),0,0,$this->forecolor(),$this->font,$this->string);

        imagejpg($this->img());
        imagedestroy($this->img());
    }
}

?>

Anyone have any idea? Either it's late or I don't know, for some reason I feel blank when writing this one.

I want to be able to write the attributes first like

$gd = new gd;
$gd->fontsize('12');
//..etc

then the actual output would be written like this

$gd->display('this is my string','myfont.ttf');

I think this line is not good

imagettftext($this->img(),$this->fontsize(),0,0,$this->forecolor(),$this->font,$this->string);

because you set nulls whit $this->fontsize() and etc.

it shuld be

imagettftext($this->imgage,$this->fontsize,0,0,$this->forecolor,$this->font,$this->string)

I this this helps :)

  1. Get an IDE with SyntaxHighlighting
  2. Learn PHP5 OOP Basics
  3. Read the error messages

You have a wild mix of $this->img, $this->image, $this->img() and $image there ...