我正在尝试弄清楚如何编写一个 gd 类来以任何字体类型显示字符串

发布于 2024-07-27 05:10:33 字数 1214 浏览 2 评论 0原文

这是我到目前为止的课程:

<?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());
    }
}

?>

有人有什么想法吗? 要么是晚了,要么是我不知道,不知为何,写这篇文章的时候我感觉一片空白。

我希望能够先编写属性,

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

然后实际输出会这样写

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

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');

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

Smile简单爱 2024-08-03 05:10:33

我认为这条线不好,

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

因为你设置了空值 $this->fontsize() 等。

它应该是

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

我,这有帮助:)

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 :)

飘逸的'云 2024-08-03 05:10:33
  1. 获取带有 SyntaxHighlighting 的 IDE
  2. 学习 PHP5 OOP 基础知识
  3. 阅读错误消息

您有 $this->img$this->image的疯狂组合$this->img()$image 那里...

  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 ...

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文