Referencing a temporarily generated image

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
violet
Forum Newbie
Posts: 24
Joined: Wed May 23, 2007 12:13 pm
Location: Manila, Philippines
Contact:

Referencing a temporarily generated image

Post by violet »

Hello. I'm (super) new to PHP & GD

:D

First off, if this topic has already been brought up here, then I'm sorry. I've probably read it but couldn't understand the solution to it. And actually I'm confused about people saying start a new topic if you have a question & others saying don't start a new topic if you have a question. So I decided to start a new topic. Hopefully I'm using the right terms.

What I'm trying to create is fairly simple: an image generated by the user that could be attached to a form (without having to be saved by the user) and emailed to a particular email address. I've already succeeded in creating the image using a form and the GET method (the image only saves properly when I use GET and not POST).

Now herein lies the problem...

How do I reference the temporarily generated image or give it a temporary name or get a form to get the values 'added' to the generated image by the user? I noticed that--since I'm using the GET method, these values are passed on :arrow: to the browser's address bar. However, I don't know how to get these values :arrow: to the second form (which will be used to email the image to a particular email address).

Thanks in advance :)
User avatar
aaronhall
DevNet Resident
Posts: 1040
Joined: Tue Aug 13, 2002 5:10 pm
Location: Back in Phoenix, missing the microbrews
Contact:

Post by aaronhall »

fwiw, the "terms" here are not to hijack other persons' threads, and to search before you post.

Anyway, the question is a little vague without any specific context.. can you post some of your code?
toasty2
Forum Contributor
Posts: 361
Joined: Wed Aug 03, 2005 10:28 am
Location: Arkansas, USA

Post by toasty2 »

This doesn't answer all of your questions, but I can help you with the GET variables.

Lets say in a forum you have:

Code: Select all

<input type="text" name="field1"></input>
In that form, field1 is the variable that the information will be stored in. You can access it in PHP with $_GET['field1']

GET variables are stored in the global array $_GET
User avatar
violet
Forum Newbie
Posts: 24
Joined: Wed May 23, 2007 12:13 pm
Location: Manila, Philippines
Contact:

Post by violet »

I'm assuming fwiw means for what it's worth.

I feel so frustrated. I'm not sure I even know how to ask this question properly but I'm hoping someone would bother to reply again :)

The generated image shows up fine.

I have no PHP script for the form because I can't begin to understand how to create it (that's some big prob I got there, hehe).

What I'd like to know is how I could attach this generated GD image to a form and email it (plus form contents) to one email address. That's all... :cry:
User avatar
violet
Forum Newbie
Posts: 24
Joined: Wed May 23, 2007 12:13 pm
Location: Manila, Philippines
Contact:

Post by violet »

And thank you toasty2! :D
User avatar
onion2k
Jedi Mod
Posts: 5263
Joined: Tue Dec 21, 2004 5:03 pm
Location: usrlab.com

Post by onion2k »

Why would you want to email an image to someone when you've generated it yourself? Email text instead.
smudge
Forum Contributor
Posts: 151
Joined: Sun May 20, 2007 12:13 pm

Post by smudge »

Could you please post the code you wrote for the form? That might help clear some things up.
User avatar
violet
Forum Newbie
Posts: 24
Joined: Wed May 23, 2007 12:13 pm
Location: Manila, Philippines
Contact:

Post by violet »

onion2k wrote:Why would you want to email an image to someone when you've generated it yourself? Email text instead.
Here's an idea :idea: because I'm not generating it myself.
User avatar
violet
Forum Newbie
Posts: 24
Joined: Wed May 23, 2007 12:13 pm
Location: Manila, Philippines
Contact:

Post by violet »

And now, for the much-awaited code (don't laugh) :D

Code: Select all

<?php header("Content-type:image/gif");
	$image = imagecreatetruecolor(231,200);
 	$black = imagecolorallocate($image,0,0,0);
	$white = imagecolorallocate($image,255,255,255);
	$golden = imagecolorallocate($image,171,143,36);
	$ltyel = imagecolorallocate($image,254,243,174);
	$yel = imagecolorallocate($image,250,235,139);
	imagefill($image,0,0,$white);
	imagerectangle($image,0,0,230,199,$black);
	$bgring = imagecreatefromgif("bgR.gif");
	$x = imagesx($bgring);
	$y = imagesy($bgring);
	$px = ((231-$x)/2);
	$py = 25;
	imagecopy($image,$bgring,$px,$py,0,0,$x,$y);
	$caption = "NCI";
	
	$Llet = $_REQUEST["Llet"];
	if (!isset($Llet))
	{ 
	$Llet = "AL.gif";
	}
	$Clet = $_REQUEST["Clet"];
	if (!isset($Clet))
	{
	$Clet = "AC.gif";	
	}
	$Rlet = $_REQUEST["Rlet"];
	if (!isset($Rlet))
	{
	$Rlet = "AR.gif";
	}
	
	$LletICFG = imagecreatefromgif($Llet);
	$RletICFG = imagecreatefromgif($Rlet);
	$CletICFG = imagecreatefromgif($Clet);
	
	$Lletx = imagesx($LletICFG);
	$Llety = imagesy($LletICFG);
	$Lletpx = 1;
	$Lletpy = 24;
	imagecopy($image,$LletICFG,$Lletpx,$Lletpy,0,0,$Lletx,$Llety);
	
	$Rletx = imagesx($RletICFG);
	$Rlety = imagesy($RletICFG);
	$Rletpx = 0;
	$Rletpy = 25;
	imagecopy($image,$RletICFG,$Rletpx,$Rletpy,0,0,$Rletx,$Rlety);
	
	$Cletx = imagesx($CletICFG);
	$Clety = imagesy($CletICFG);
	$Cletpx = 0;
	$Cletpy = 26;
	imagecopy($image,$CletICFG,$Cletpx,$Cletpy,0,0,$Cletx,$Clety);
	
	$font = "CenturyGothic.ttf";
	imagettftext($image,20,0,3,23,$golden,$font,$caption);

	imagegif($image);	
	if ($image === false) {
        die ("Unable to open image");
}	
	$size = getimagesize($image);
	$fp = fopen($image, "rb");
	if ($size && $fp) {
    header("Content-type: {$size['mime']}");
    fpassthru($fp);
    exit;
	} else {
    // error
}
	imagedestroy($image);
	imagedestroy($LletICFG);
	imagedestroy($RletICFG);
	imagedestroy($CletICFG); 
	imagedestroy($caption); 
?>
OK, now how do I reference this GIF image? or turn it into a mail attachment?

Please help :?
User avatar
violet
Forum Newbie
Posts: 24
Joined: Wed May 23, 2007 12:13 pm
Location: Manila, Philippines
Contact:

Post by violet »

In Elouai's dollmaker page (http://elouai.com/doll-makers/new-dollmaker.php) there is an option to email the set of images (as a compiled GD image) to a friend..

This is a lot like what I'm trying to create, (except I'm not making dolls)...
User avatar
violet
Forum Newbie
Posts: 24
Joined: Wed May 23, 2007 12:13 pm
Location: Manila, Philippines
Contact:

Post by violet »

How do I retrieve data for the image generated by the user (values submitted using a form)? Anyone? I just need to know how to retrieve this "temporary" data that is to be processed/encoded..

At the moment, this is what I have (a chunk of the code from the form's action). I know it's wrong because the output .gif file is 2kb and won't open in Photoshop.. Please help? :)

Code: Select all

$file =	file_get_contents("gdImage.php", "rb");
 	 
$message .=	"Content-Type: image/gif; name=\"gdImage.php\"\r\n" 
 	."Content-Transfer-Encoding: base64\r\n"
 	."Content-disposition: attachment; file=\"gdImage.php\"\r\n"
 	."\r\n"
 	.chunk_split(base64_encode($file))
 	.$bound_last; 
I think this is the part I need to modify to get the attachment to work.

Please point me in the right direction or provide search terms or a URL, & I will try to help myself... Anything!
Post Reply