Image won't view with post

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Gadgetmo
Forum Newbie
Posts: 14
Joined: Sun Nov 01, 2009 7:17 am

Image won't view with post

Post by Gadgetmo »

I've made an image with PHP that will work if you put text in:

Code: Select all

<?php
     header ("Content-type: image/png");
     $text = "text";
     $im = imagecreate (400, 30);
     $black = imagecolorallocate ($im, 0, 0, 0);
     $white = imagecolorallocate ($im, 255, 255, 255);
     imagettftext ($im, 20, 0, 10, 20, -$white, 
              "Arial.ttf", $text);
     imagepng ($im);
     imagedestroy ($im);
?>
(as shown on http://testphp.comlu.com/123.php), but if I do:

Code: Select all

<?php
     header ("Content-type: image/png");
     $text = $_POST("text");
     $im = imagecreate (400, 30);
     $black = imagecolorallocate ($im, 0, 0, 0);
     $white = imagecolorallocate ($im, 255, 255, 255);
     imagettftext ($im, 20, 0, 10, 20, -$white, 
              "Arial.ttf", $text);
     imagepng ($im);
     imagedestroy ($im);
?>
,
it won't work and just shows blank (an example is on http://testphp.comlu.com/testform.php).
Please help!

Thanks,
Arthur
User avatar
jackpf
DevNet Resident
Posts: 2119
Joined: Sun Feb 15, 2009 7:22 pm
Location: Ipswich, UK

Re: Image won't view with post

Post by jackpf »

Try commenting out the header() function. I think you're getting an error/warning, but you can't see it because of the content type.
User avatar
McInfo
DevNet Resident
Posts: 1532
Joined: Wed Apr 01, 2009 1:31 pm

Re: Image won't view with post

Post by McInfo »

$_POST is an array, not a function.

Code: Select all

$_POST("text")
should be

Code: Select all

$_POST["text"]
Why is $white negated on line 7?

Edit: This post was recovered from search engine cache.
Last edited by McInfo on Thu Jun 17, 2010 1:13 pm, edited 1 time in total.
Gadgetmo
Forum Newbie
Posts: 14
Joined: Sun Nov 01, 2009 7:17 am

Re: Image won't view with post

Post by Gadgetmo »

McInfo wrote: Why is $white negated on line 7?
I'm gonna use it later on.

Thanks,
Arthur
Gadgetmo
Forum Newbie
Posts: 14
Joined: Sun Nov 01, 2009 7:17 am

Re: Image won't view with post

Post by Gadgetmo »

Why is $white negated on line 7?
Oh right, that. I dunno. 8O
Post Reply