Adding copyright to image and sending it

Hello Everybody!
I have a php issue… And the thing is… I understand whats happening but I dont know what to do to solve it.
Well I wrote this simple function to add a copyright bar on the bottom of my images

function go_img($path) {
 $img = imagecreatefromjpeg($path);
 $text_colour = imagecolorallocatealpha   ( $img, 255, 255, 255 ,0);
 $line_colour = imagecolorallocatealpha  ( $img, 0, 0, 0 ,20);
 $black = imagecolorallocate($img, 255, 255, 255);
 $x = imagesx($img);
 $y = imagesy($img)-6;
 
 $text = "©copyright 2008 ...........";
 //simple convert string
 imagesetthickness ( $img, 12 );
 imageline( $img, 0,$y, 290, $y, $line_colour );
 $font_file = 'trebucbd.ttf';
 
 imagefttext($img, 7, 0, 5, $y+3, $black, $font_file, $text);
  
 header( "Content-type: image/jpeg" );
 imagejpeg( $img,"temp.jpg",80);
 imagecolordeallocate( $line_color );
 imagecolordeallocate( $text_color );
 imagecolordeallocate( $black );
 imagedestroy( $img );
}

It works this way, the user chooses some images from the site, and he can send them to his own email through the site. However those images, need to be copyrighted, so I take the image, use this function to add it and attach the image to the message.

 for ($i=0;$i<$len;$i++) {
             
  $fileatt_type = "application/octet-stream"; // File Type 
  $start= strrpos($attachment[$i], '/') == -1 ? strrpos($attachment[$i], '//') : strrpos($attachment[$i], '/');
  $fileatt_name = substr($attachment[$i], $start, strlen($attachment[$i])); // Filename that will be used for the file as the  attachment 
 
 //create temporal image
  go_img("path/".$attachment[$i]);
  $file = fopen("temp.jpg",'rb'); 
  $data = fread($file,filesize("temp.jpg")); 
  fclose($file); 
  $data = chunk_split(base64_encode($data)); 
 

as youu see I save every image as a temporal file temp.jpg, once is copyrighted, I just open the file, read it and add attach it to message.

The big problem is… The image converting/creation is taking too long, and sometimes the file is opened but still hasnt been fully created, so when the image arrives, it is cut.

What can I do to solve this?

Thank you