Re: [GD-DEVEL] Problem with TTF file
[email protected] (Takeshi Abe) Sat, 18 Oct 2008 17:25:35 +0900 (JST)
| Newsgroups | php.gd.devel |
|---|---|
| Message-ID | <[email protected]> |
Hi, On Thu, 16 Oct 2008 21:14:43 +0200, "Marco van Oostende" <[email protected]> wrote: > function create_image() { > header('Content-type: image/png'); > $box = ImageTTFbbox($this->fontsize, 0, $this->fontfile, $this->article); > $src_img = ImageCreate(($box[2]+11), (abs($box[7]-$box[1])+6)); > $black = ImageColorAllocate($src_img, 0x00, 0x00, 0x00); > $white = ImageColorAllocate($src_img, 0xff, 0xff, 0xff); > ImageFill($src_img, 0, 0, $white); > ImageColorTransparent($src_img, $white); > ImageTTFText($src_img, $this->fontsize, 0, 3, abs($box[7]), $black, > $this->fontfile, $this->article); > ImagePNG($src_img); > ImageDestroy($src_img); > } (snip) > > The GPL font file I use can be downloaded from 'grandzebu dot net > slash informatique slash codbar slash ean13 dot ttf' and the string to > put in $this->article for testing is 3FJQRLA*cbgahj+ The above function seems to work well on my Debian lenny with php5-gd (php 5.2.6 + gd 2.0.35), resulting the attached png. Cheers, -- Takeshi Abe
barcode.php
(text/plain, 860 B)
<?php
class X {
private $fontsize = 30;
private $fontfile = "/home/tabe/ean13.ttf";
private $article = "3FJQRLA*cbgahj+";
function __construct()
{
}
function create_image() {
header('Content-type: image/png');
$box = ImageTTFbbox($this->fontsize, 0, $this->fontfile, $this->article);
$src_img = ImageCreate(($box[2]+11), (abs($box[7]-$box[1])+6));
$black = ImageColorAllocate($src_img, 0x00, 0x00, 0x00);
$white = ImageColorAllocate($src_img, 0xff, 0xff, 0xff);
ImageFill($src_img, 0, 0, $white);
ImageColorTransparent($src_img, $white);
ImageTTFText($src_img, $this->fontsize, 0, 3, abs($box[7]), $black,
$this->fontfile, $this->article);
ImagePNG($src_img);
ImageDestroy($src_img);
}
}
$x = new X();
$x->create_image()
?>