PHP Image from watermark

// Create the canvas
$canvas = imagecreate( 200, 100 );  
// Define the colours to use
$black = imagecolorallocate( $canvas, 0, 0, 0 );  
$white = imagecolorallocate( $canvas, 255, 255, 255 );  
// Create a rectangle and fill it white
imagefilledrectangle( $canvas, 0, 0, 200, 100, $white );  
// The path to the font
$font = "verdana.ttf"; 
// The text to use 
$text = "House"; 
// The font size 
$size = "30";   
// Set the path to the image to watermark
$input_image = "House.jpg"; 
// Calculate the size of the text 
// If php has been setup without ttf support this will not work.
$box = imagettfbbox( $size, 0, $font, $text );  
$x = (200 - ($box[2] - $box[0])) / 2;  
$y = (100 - ($box[1] - $box[7])) / 2;  
$y -= $box[7];  
// Add the text to the image
imageTTFText( $canvas, $size, 0, $x, $y, $black, $font, $text );  
// Make white transparent
imagecolortransparent ( $canvas, $white );  
// Save the text image as temp.png
imagepng( $canvas, "temp.png" );  
// Cleanup the tempory image canvas.png
ImageDestroy( $canvas );  
// Read in the text watermark image
$watermark = imagecreatefrompng( "temp.png" );  
// Returns the width of the given image resource  
$watermark_width = imagesx( $watermark );
//Returns the height of the given image resource    
$watermark_height = imagesy( $watermark );    
$image = imagecreatetruecolor( $watermark_width, $watermark_height );    
$image = imagecreatefromjpeg( $input_image );
// Find the size of the original image and read it into an array      
$size = getimagesize( $input_image );  
// Set the positions of the watermark on the image
$dest_x = $size[0] - $watermark_width - 100;    
$dest_y = $size[1] - $watermark_height - 200;    
imagecopymerge($image, $watermark, $dest_x, $dest_y, 0, 0, $watermark_width, $watermark_height, 50);   
// Save the watermarked image as watermarked.jpg 
imagejpeg( $image, "watermarked.jpg" );
// Clear the memory of the tempory image     
imagedestroy( $image );    
imagedestroy( $watermark );    
// Delete the text watermark image
unlink( "temp.png");