By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
444,190 Members | 1,412 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 444,190 IT Pros & Developers. It's quick & easy.

attach imagejpeg to email

P: n/a
I'm trying to add an imagejpeg result as an attachment of an email.

For creating the email I'm using phpmailer class
(http://phpmailer.sourceforge.net/)
Now I do create an image from a jpeg file for adding some text on it and
then send it to somebody:
here is the code:
$image = "/include/images/model.jpg";
$src = imagecreatefromjpeg($image);
$size = getimagesize($image);
$dst = imagecreatetruecolor($size[0],$size[1]);
$txt_color = ImageColorAllocate ($dst, 0, 0, 0);
ImageString ($dst, 5, 90, 30 ,"my name", $txt_color);
$tempimage = imagejpeg($dst);
if (!$mail->AddstringAttachment($tempimage,"model.jpg"))
echo ("<strong>failure attachment file</strong><br>");

Instead of attachment file, I get the failure attachment file message on the
screen after a lot of text (the jpeg file in text format).

What do I wrong ?
Jul 17 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
*** Bob Bedford wrote/escribió (Wed, 6 Jul 2005 10:52:50 +0200):
$image = "/include/images/model.jpg";


Is the path correct? Do you have a directory called "include" in system's
root directory?
--
-- Álvaro G. Vicario - Burgos, Spain
-- http://bits.demogracia.com - Mi sitio sobre programación web
-- Don't e-mail me your questions, post them to the group
--
Jul 17 '05 #2

P: n/a

"Alvaro G Vicario" <al******************@telecomputeronline.com> a écrit
dans le message de news: 1e*****************************@40tude.net...
*** Bob Bedford wrote/escribió (Wed, 6 Jul 2005 10:52:50 +0200):
$image = "/include/images/model.jpg";


Is the path correct? Do you have a directory called "include" in system's
root directory?

Yes of course is the first thing I checked.

In fact my problem was to create an image temporarly, then apply it to an
other (a mask in fact), then send it as attachment, without the need to save
the generated image in a file: here is the code:

I've been able to do so, but I've an error on the file function (look at the
comment):
$image = "/include/images/model.jpg";
$src = imagecreatefromjpeg($image);
$size = getimagesize($image);
$dst = imagecreatetruecolor($size[0],$size[1]);
imagecopy($dst,$src,0,0,0,0,$size[0],$size[1]); //make a copy of the
original model, the mask !!!
$txt_color = ImageColorAllocate ($dst, 0, 0, 0);
imagestring($dst, 16, 350, 220 ,"CODE: ".$code, $txt_color); //write a code
in a field
imagestring($dst, 20, 350, 300 ,"NAME: ".$RS->name, $txt_color); //write the
name on an other field.
$tempimage = "temp.jpg";
imagejpeg($dst,$tempimage); //create jpeg: mask + text on it.
if (!$mail->AddAttachment($tempimage,"model.jpg")) //attach the image using
phpmailer class.


Jul 17 '05 #3

P: n/a
Bob Bedford <be******@notforspammershotmail.com> wrote:
$tempimage = imagejpeg($dst);
if (!$mail->AddstringAttachment($tempimage,"model.jpg"))
echo ("<strong>failure attachment file</strong><br>");

Instead of attachment file, I get the failure attachment file message on the
screen after a lot of text (the jpeg file in text format).

What do I wrong ?


You didn't check the imagejpeg function prototype:
bool imagejpeg ( resource image [, string filename [, int quality]] )

IOW $tempimage does not contain an image (it's a boolean). imagejpeg
output the image directly to the httpd's buffer in your code.

Jul 17 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.