Originally posted by jon31:
Hey all,
I'd like print text onto an image with GD, then e-mail that image, but I haven't figured out how to use the image created by GD. All I can do it output it to the browser. How do you make the image created by GD an actual image, that can be downloaded from the browser or e-mailed? Any ideas?
Thanks!
jon
There's one very small step, then you're sorted. Instead of piping the output to the browser, just pipe it to a file like so:
[php]
$image = imagecreatetruecolor($height,$width);
...do yer image thing...
imagejpeg($image,'/tmp/image.jpg',95);
[/php]
So now your manipulated image is sitting in the '/tmp' folder, ready for you to email it. Here's a simple script using the PEAR classes:-
[php]
require_once('Mail.php');
require_once('Mail/mime.php');
$content['html'] = "<p>Please find your image attached</p>";
$content['text'] = "Please find your image attached";
$mime = new Mail_mime("\n");
$mime->setTXTBody($content['text']);
$mime->setHTMLBody($content['html']);
$mime->addAttachment('/tmp/image.jpg','image/jpeg',null,true);
$body = $mime->get();
$headers = $mime->headers(array('From' => $from, 'Subject' => $subject));
$mail =& Mail::factory('mail');
$result = $mail->send("noone@nowhere.com",$headers,$body);
[/php]