我正在尝试弄清楚如何编写一个 gd 类来以任何字体类型显示字符串
这是我到目前为止的课程:
<?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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我认为这条线不好,
因为你设置了空值 $this->fontsize() 等。
它应该是
我,这有帮助:)
I think this line is not good
because you set nulls whit $this->fontsize() and etc.
it shuld be
I this this helps :)
您有
$this->img
、$this->image
、的疯狂组合$this->img()
和$image
那里...You have a wild mix of
$this->img
,$this->image
,$this->img()
and$image
there ...