473,569 Members | 2,793 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 = imagecreatefrom jpeg($image);
$size = getimagesize($i mage);
$dst = imagecreatetrue color($size[0],$size[1]);
$txt_color = ImageColorAlloc ate ($dst, 0, 0, 0);
ImageString ($dst, 5, 90, 30 ,"my name", $txt_color);
$tempimage = imagejpeg($dst) ;
if (!$mail->AddstringAttac hment($tempimag e,"model.jpg" ))
echo ("<strong>failu re 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 3496
*** 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************ ******@telecomp uteronline.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 = imagecreatefrom jpeg($image);
$size = getimagesize($i mage);
$dst = imagecreatetrue color($size[0],$size[1]);
imagecopy($dst, $src,0,0,0,0,$s ize[0],$size[1]); //make a copy of the
original model, the mask !!!
$txt_color = ImageColorAlloc ate ($dst, 0, 0, 0);
imagestring($ds t, 16, 350, 220 ,"CODE: ".$code, $txt_color); //write a code
in a field
imagestring($ds t, 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,"mod el.jpg")) //attach the image using
phpmailer class.


Jul 17 '05 #3
Bob Bedford <be******@notfo rspammershotmai l.com> wrote:
$tempimage = imagejpeg($dst) ;
if (!$mail->AddstringAttac hment($tempimag e,"model.jpg" ))
echo ("<strong>failu re 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
4076
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: http://us4.php.net/manual/en/function.imagejpeg.php http://us4.php.net/manual/en/function.imagepng.php -Josh
17
2695
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 ImageCopyResampleBicubic(&$dst, &$src, $dstx, $dsty, $srcx, $srcy, $w, $h, $zoomX, $zoomY = '') { if (!$zoomY) $zoomY = $zoomX;
4
2292
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 present, output it instead of the image. Version 2... If there is no embedded thumbnail, create one and save it in the directory. I have an image...
3
3226
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 damn thing to save as my suggested filename or even as anything but a BMP in IE6. I've tried a bunch of different combinations of the content-type...
1
2760
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 I compare image filesizes between the original and the one created via imagejpeg(), the size of the latter is 50% of that of the former. ...
1
2893
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() function 3. use imagecopyresampled to resize src image and store in newly created image from step 2.
21
21250
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 doesn't make a difference at all. <?php //random_number.php $img_number = imagecreate(100,50);
6
6795
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 /home/.gobbles/mahcuz/mahcuz.com/upload/uploaded.php on line 129 And this is some of the code from the page: /* New code for thumbnails. Will on work...
9
1866
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 itself. Here's the code. This used to succeed until my hosting provider changed something on his end. Now he's struggling to restore the...
0
7695
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7612
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
8119
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
0
6281
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5509
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
3653
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3637
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2111
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 we have to send another system
1
1209
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.