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

From: Date: Thu, 08 Dec 2005 12:26:09 +0000
Subject: Re: PHP Warning: imagettftext() expects parameter 2 to be double
References: 1 2  Groups: php.general 
Request: Send a blank email to php-general+get-227131@lists.php.net to get a copy of this message
Jeffrey Sambells wrote:
You've got 83px in you XML file for the fontsize. the 'px' is messing it up change it to just 83 in the XML file or cast the value to (float) which will extract the 83 and remove the px:
well spotted Jeffery; James didn't I say to var_dump() the vars you create inside the loop?? print_r() and var_dump() are your friends!
<snip>
    foreach ($xml->textblock as $text) {
            $fontsize=(float)$text->fontsize;
        $fontangle=(float)$text->fontangle;
        $fontxpos=(int)$text->fontxpos;
        $fontypos=(int)$text->fontypos;
        $text=$text->text;
i.e. var_dump($fontsize, $fontangle, $fontxpos, $fontypos, $text);
                imagettftext($image['png'],$fontsize,$fontangle,$fontxpos,$fontypos,$fon t['color'],$font['type'],"$text",array());
one other thing, there is no point in writing: "$text" the quotes have no use (assuming $text is a string), in fact its a [very small] waste of processing power.
        }
</snip> - Jeff On 7-Dec-05, at 7:06 AM, James wrote:
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,$f ont['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
<image.php><test.xml>-- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php


« previous php.general (#227131) next »