Re: PHP Warning: imagettftext() expects parameter 2 to be double

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Title: Re: PHP Warning:  imagettftext() expects parameter 2 to be double
Hi,

Thank you for getting back to me, your the first.

The array works fine – I have tested it using var_dump().

Attached are the two files – xml.test – this holds the array of the text blocks which is being parsed by image.php.

Line 38 is the problem, if you comment around the foreach() statement and un-comment the commented lines you should see it working fine, its when its within the foreach statement when it errors.

Regards,

James


Jochem Maas Wrote:

James wrote:
> Hi there,
>
> I have been using the GD functions from PHP5.0 on Mac OS X.
>
> I have a simple script that creates a PNG image with text on the image using
> fonts using FreeType 2.
>
> I am trying to use the imagettftext() function within a foreach loop – but I
> get the following error:
>
> PHP Warning:  imagettftext() expects parameter 2 to be double

what does paramter 2 contain in each case? var_dump(), print_r(), echo ?!?

>
> The code is as follows:
>
>     $font['type']="./fonts/font.ttf”;
>
>     
> $font['color']=imageColorAllocate($card['png'],$font['hexcolor']['r'],$font[
> 'hexcolor']['g'],$font['hexcolor']['b']);
>
>     imageFill($card['png'],0,0,$card['color']);
>
>     foreach ($xml->textblock as $text) {
> $fontsize=$text->fontsize;        $fontangle=$text->fontangle;
> $fontxpos=$text->fontxpos;        $fontypos=$text->fontypos;
> $text=$text->text;

try var_dump($text); or print_r($text); to see what you have
(if its an XML node object - dump $fontsize, $fontxpos instead!!!)

> imagettftext($image['png'],$fontsize,$fontangle,$fontxpos,$fontypos,$font['c
> olor'],$font['type'],$text);        }
>
> It works fine if I add just one line outside of the loop – but as soon as
> its within the loop it errors.
>
> Cheers,
>
> James
>

<?php

if (file_exists('test.xml')) {

	$xml=simplexml_load_file('test.xml');
	
	$image['name']=$xml->name;
	
	$image['hexcolor']=$xml->frontcolor;
	$image['intcolor']=hex2int($image['hexcolor']);
	
	$image['width']=$xml->width;
	$image['height']=$xml->height;
	
	$font['type']=$xml->font;
	
	$font['hexcolor']=$xml->fontcolor;
	$font['intcolor']=hex2int($font['hexcolor']);	
	
	$font['type']="./fonts/".$font['type'];
	
	$image['png']=imageCreateTrueColor($image['width'],$image['height']);
	
	$image['color']=imageColorAllocate($image['png'],$image['intcolor']['r'],$image['intcolor']['g'],$image['intcolor']['b']);
	
	$font['color']=imageColorAllocate($image['png'],$font['intcolor']['r'],$font['intcolor']['g'],$font['intcolor']['b']);
	
	imageFill($image['png'],0,0,$image['color']);
	
	foreach ($xml->textblock as $text) {
	
		$fontsize=$text->fontsize;
		$fontangle=$text->fontangle;
		$fontxpos=$text->fontxpos;
		$fontypos=$text->fontypos;
		$text=$text->text;
		
		imagettftext($image['png'],$fontsize,$fontangle,$fontxpos,$fontypos,$font['color'],$font['type'],"$text",array());
	
	}

/*	imagettftext($image['png'],"83",0,10,120,$font['color'],$font['type'],"Happy",array());
	imagettftext($image['png'],"55",0,10,178,$font['color'],$font['type'],"Birthday",array());
	imagettftext($image['png'],"104",0,8,280,$font['color'],$font['type'],"Cunt",array());
*/
	
	#$image['png']=imagerotate($image['png'],90,0);
	
	header("Content-type: image/png");
	
	imagepng($image['png']);
   
} else {

   exit('Failed to open test.xml.');
   
}

function hex2int($hex) {

	return array(
		'r' => hexdec(substr($hex, 0, 2)),
		'g' => hexdec(substr($hex, 2, 2)),
		'b' => hexdec(substr($hex, 4, 2))
	);
	
}

?>
<?xml version='1.0' standalone='yes'?>
<card>
	<name>Welcome</name>
	<frontcolor>003366</frontcolor>
	<width>360</width>
	<height>360</height>
	<font>princetown.ttf</font>
	<fontcolor>CC6666</fontcolor>
	<textblock>
		<fontsize>83px</fontsize>
		<fontangle>0</fontangle>
		<fontxpos>10</fontxpos>
		<fontypos>140</fontypos>
		<text>Welcome</text>
	</textblock>
	<textblock>
		<fontsize>60px</fontsize>
		<fontangle>0</fontangle>
		<fontxpos>10</fontxpos>
		<fontypos>240</fontypos>
		<text>to</text>
	</textblock>
	<textblock>
		<fontsize>83px</fontsize>
		<fontangle>0</fontangle>
		<fontxpos>10</fontxpos>
		<fontypos>340</fontypos>
		<text>My Website</text>
	</textblock>
</card>
-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux