473,509 Members | 3,009 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

attach imagejpeg to email

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
3 3489
*** 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

"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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
4070
by: Joshua Beall | last post by:
According to the PHP manual, imagejpeg and imagepng have a return value of type "int" - but I do not see where it says what the values mean. Can anyone enlighten me? Here are the manual pages:...
17
2684
by: Yang Li Ke | last post by:
Hi guys, Im trying to use this code that I found on php.net to create a thumbnail from an image but it simply displays a black square. Anyone can tell me what am I doing wrong? <? function...
4
2287
by: Steven Stern | last post by:
I'm sketching out an application that would automagically do a photo gallery. As part of this, I want to examine each graphic in the a given directory, look for an embedded thumbnail and, if...
3
3217
by: Shawn Wilson | last post by:
Hi, I've created a PHP file called filename.jpg. It outputs a JPG. I've set up a .htaccess file to force the filetype to PHP. The file is displayed in a page on a browser. I cannot get the...
1
2758
by: Phil Powell | last post by:
I am using the imagejpeg() and the imagegif() (also imagepng(), etc.) commands that will write an image Object back into an existing image in a directory. Everything works fine, except that when...
1
2888
by: André Gasser | last post by:
hello newsgroup, I just discovered a weird effect in my php code. here is the flow of my code: 1. upload jepg file to server 2. create new (empty) jpeg file using imagecreatefromjpeg()...
21
21236
by: cman | last post by:
does anyone know why i can't generate images with: header("Content-type:image/jpeg"); imagejpeg($img_number); i've tried different examples but i always get a text output as if the header...
6
6787
Markus
by: Markus | last post by:
I'm adding to my script a section that allows a thumbnail to be created and saved. I get this error: Warning: imagejpeg() : Unable to open '../uploads/thumb/' for writing: Is a directory in...
9
1858
by: Tony Sosa | last post by:
Does anyone know what kind of tweaks I need to make to pertinent configs to render an image correctly? Right now, the text of the argument passed to imagejpeg is being shown instead of the image...
0
7234
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7136
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7344
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7505
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
4730
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3216
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
1570
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
775
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
441
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.