0

I am inserting texts in a jpg image, which serves as a template.

$jpg_image = imagecreatefromjpeg('images/receipt.jpg');
if ($jpg_image) {
    $color = imagecolorallocate($jpg_image, 0, 0, 0);
    imagestring($jpg_image,5,570,40,$rn,$color );
    imagestring($jpg_image,5,570,110,$tq,$color );
    imagejpeg($jpg_image,$filename);
}

I wish to save this edited image temporarily and then send it as an attachment by email. How do I save this file in the local folder (server) and attach in pear mail?

B. Desai
  • 16,414
  • 5
  • 26
  • 47
sridhar
  • 1,321
  • 5
  • 17
  • 26
  • You can base64 encode the image data to text and attach in a mail header. This question suggests to use PHPMailer as an example, use whatever is easiest for you. https://stackoverflow.com/questions/1851728/how-to-embed-images-in-html-email sending the image in the email itself means you don't need to save this on your server after the email is sent. – pokeybit Nov 08 '17 at 11:31

1 Answers1

0

For save image to your local folder you need to pass second parameter as path will file name. For example:

$jpg_image = imagecreatefromjpeg('images/receipt.jpg');
$save_path  = "PATH_TO_YOUR_DIR/filename.jpg";
if ($jpg_image) {
    $color = imagecolorallocate($jpg_image, 0, 0, 0);
    imagestring($jpg_image,5,570,40,$rn,$color );
    imagestring($jpg_image,5,570,110,$tq,$color );
    imagejpeg($jpg_image,$save_path);
}

Then you can attach this image in email. There is already lots of solutions for how to attach image in mail.

After attach if you want to remove image then simply unlink it

unlink($save_path);
B. Desai
  • 16,414
  • 5
  • 26
  • 47