imagecreatefrompng() headaches?

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
User avatar
icarpenter
Forum Commoner
Posts: 84
Joined: Mon Mar 07, 2005 8:12 am
Location: Kent, England

imagecreatefrompng() headaches?

Post by icarpenter »

Hi

I am trying to pass a value into a function that creates an image using imagecreatefrompng()

but I keep getting headers already sent errors...

I can display the image if I move the script out of a function and into another document and reference this using...

Code: Select all

<img src="createimage.php"  />
However I cant seem to pass any values into this and I am reluctant to use $_SESSION variables for this...

Does anyone have any ideas on how this could be implemented?

Rgds Ian
User avatar
pickle
Briney Mod
Posts: 6445
Joined: Mon Jan 19, 2004 6:11 pm
Location: 53.01N x 112.48W
Contact:

Post by pickle »

You could pass variables using GET:

Code: Select all

&lt;img src = &quote;createimage.php?id=12&quote;&gt;
then in createimage.php:

Code: Select all

&lt;?PHP
$id = $_GET&#1111;'id'];
?&gt;
Real programmers don't comment their code. If it was hard to write, it should be hard to understand.
User avatar
icarpenter
Forum Commoner
Posts: 84
Joined: Mon Mar 07, 2005 8:12 am
Location: Kent, England

Post by icarpenter »

Pickle you are a Legend!!!

It works better than Paracetamol no more headaches!!!

Thanks Ian
User avatar
pickle
Briney Mod
Posts: 6445
Joined: Mon Jan 19, 2004 6:11 pm
Location: 53.01N x 112.48W
Contact:

Post by pickle »

Glad to help.
Real programmers don't comment their code. If it was hard to write, it should be hard to understand.
deep_fire
Forum Newbie
Posts: 7
Joined: Fri Jun 24, 2005 2:34 pm
Contact:

I use this

Post by deep_fire »

this is gcode.php

Code: Select all

<?
session_start();
$im = imagecreate(70, 23)
   or die(&quote;Cannot Initialize new GD image stream&quote;);
$background_color = imagecolorallocate($im, 255, 255, 255);
$text_color = imagecolorallocate($im, 0,0 , 0);
imagestring($im, 5, 6, 6,  $random_num, $text_color);
imagegif($im);
imagedestroy($im);
?>
and I call gcode.php like this

Code: Select all

<?
/* security code */
$maxran = 1000000;
$random_num = mt_rand(0, $maxran);
session_register('random_num');
/* security code end */
 ?>
 <img src=&quote;gkod.php&quote; align=&quote;absmiddle&quote;>
Post Reply