attach imagejpeg to email

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Bob Bedford

    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 ?


  • Alvaro G Vicario

    #2
    Re: attach imagejpeg to email

    *** Bob Bedford wrote/escribió (Wed, 6 Jul 2005 10:52:50 +0200):[color=blue]
    > $image = "/include/images/model.jpg";[/color]

    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
    --

    Comment

    • Bob Bedford

      #3
      Re: attach imagejpeg to email


      "Alvaro G Vicario" <alvaro_QUITAR_ REMOVE@telecomp uteronline.com> a écrit
      dans le message de news: 1eflxxsop2euu$. iy62hb8le9iq.dl g@40tude.net...[color=blue]
      > *** Bob Bedford wrote/escribió (Wed, 6 Jul 2005 10:52:50 +0200):[color=green]
      >> $image = "/include/images/model.jpg";[/color]
      >
      > Is the path correct? Do you have a directory called "include" in system's
      > root directory?
      >[/color]
      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.




      Comment

      • Daniel Tryba

        #4
        Re: attach imagejpeg to email

        Bob Bedford <bedford1@notfo rspammershotmai l.com> wrote:[color=blue]
        > $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 ?[/color]

        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.

        Comment

        Working...