phpbar.de logo

Mailinglisten-Archive

[php] [gd-lib] kein text mit ttftext auf png-bild?

[php] [gd-lib] kein text mit ttftext auf png-bild?

Dario Nuevo php at xbe.ch
Die Sep 2 22:54:12 CEST 2003


hi leute ;-)

ich hatte eine wunderbar funktionierende klasse zum generieren von bildern
mit ttf-text drauf. der sinn der bilder ist eben, die fonts zu zeigen.

nun, seit 4.3.2 hat sich anscheinend etwas mit dem handling geändert, nun
hab ich einfach keinen text mehr auf den bildern.
ich fand bei den user comments zur imagecopymerge() funktion folgenden text:

"I've recently had a problem with a image script that overlays text on top
of a truecolour image, using the imagettftext function.  The problem is
the any text on the image just simply refuses to appear, regardless of
specifying the full path of the font file or not.

The script used to work fine, until version 4.3.0, and the same problem
seems to exist in version 4.3.1 and 4.3.2

For those who are stuck with this problem, here is my work around.

You need to create a 2nd overlay image which is the same size as the using
the imagecreate function.  Then you set the background colour to a
transparent colour.

Once this is done, use the imagettftext functions to draw the text onto
the overlay image.

When you have completed drawing onto the overlay image, the image needs to
be overlayed onto the truecolour image.  Just use the imagecopymerge
function with a PCT value of 100.

Then continue to use the imageJPEG and imagePNG functions as normal,
hopefully with your text on it!"

nun, also habe ich dies umgesetzt, gibt diese source:.
<?
	$this->fontfile = "/opt/www/fontz-files/{$this->alpha}/".$this->font.".ttf";
	//echo $this->fontfile;
	//$this->pic = imagecreate($this->width,$this->height);
	$im = imagecreatefrompng($this->imgtmpl);

	$this->pic = imagecreate(300,80);
	//$this->pic = imagecreatefrompng($this->imgtmpl);
	$this->fontcolor = $this->rgb2gd($this->fontcolor);

	$this->bgcolor = $this->rgb2gd("#CCCCCC");
	$this->bordercolor = $this->rgb2gd($this->bordercolor);

	imagecolortransparent($this->pic,$this->bgcolor);
	imagefilledrectangle($this->pic, 0, 0,  $this->width,$this->height,
$this->bgcolor);
	imagettftext($this->pic, $this->fontsize, $this->textangle,
$this->start_x, $this->start_y, $this->fontcolor, $this->fontfile,
$this->text);

	//imagefilledrectangle($this->pic, $this->borderwidth,
$this->borderwidth, $this->width-$this->borderwidth,
$this->height-$this->borderwidth, $this->bgcolor);
	if($this->custom == false) {
		$this->ressize();
		$this->getxy();
	}
	//ImageAlphaBlending($im, true);
	//imagecopy($this->pic,$im, 0, 0, 0, 0, 300, 80);
	imagecopymerge($im,$this->pic, 0, 0, 0, 0, 300, 80, 99);
?>
(das ganze ist eben innerhalb dieser klasse)

rgb2gd() ruft imagecolorallocate() auf und returned diese farbe..

nun, ich bin ziemlich am ende meines lateins. _ein_ bild bekomme ich,
jedoch ist es komplett weiss, ausser dass man am oberen rand rund
1pixel-ausschnitt der schrift sieht, glaub jedenfalls es ist die schrift..
jedenfalls einen unregelmässigen streifen in der farbe der schriftart..

wieso bekomm ich das kein gutes resultat? irgendwo ein denkfehler? geb
auch gerne mehr source falls benötigt..

mein php ist soweit 100%ig ok, hab alles was man benötigt ->
www.xbe.ch/~dn/info.php ;-)

danke für jeden tipp! ;) brauch dringend hilfe ;(

regards
dario

php::bar PHP Wiki   -   Listenarchive