Tee problem is most likely that you are trying to send the image across in the same request as the HTML page. You can only send one content type per request, therefore you need two request.
The most used solution is to put your image code into a file and request it via img tag.
i.e.
image.php
header ("Content-type: image/png");
$theTitle ="Thjis is my wife";
//$im = imagecreatetruecolor(575, 400);
$im = imagecreatefromjpeg("images/bg_0012.jpg");
// Create some colors
//$background = imagecolorallocate($im, 25, 255, 15);
//$background= imagecreatefrompng("images/sotw_background.png");
$frontColor = imagecolorallocate($im, 252, 112, 0);
$backColor = imagecolorallocate($im, 105, 16, 16);
//imagefilledrectangle($im, 0, 0, 575, 40, $background);
// Replace path by your own font path
$font = 'font/Yukon Gold.ttf';
// Add the text
//imagettftext($im, 12, 10, 15, 200, $backColor, $font, stripslashes(htmlspecialchars_decode_php4(urldecode($theTitle))));
imagettftext($im, 12, 10, 15, 200, $frontColor, $font, stripslashes(htmlspecialchars_decode_php4(urldecode($theTitle))));
imagejpeg($im, '', 100);
imagedestroy($im);
<table><tr><td><img src="image.php" /></td></tr></table>
You could also use a GET query on the image URL to put the watermark text in your image.
i.e.
header ("Content-type: image/png");
$theTitle = urldecode(strip_tags($_GET['text']));
//$im = imagecreatetruecolor(575, 400);
$im = imagecreatefromjpeg("images/bg_0012.jpg");
// Create some colors
//$background = imagecolorallocate($im, 25, 255, 15);
//$background= imagecreatefrompng("images/sotw_background.png");
$frontColor = imagecolorallocate($im, 252, 112, 0);
$backColor = imagecolorallocate($im, 105, 16, 16);
//imagefilledrectangle($im, 0, 0, 575, 40, $background);
// Replace path by your own font path
$font = 'font/Yukon Gold.ttf';
// Add the text
//imagettftext($im, 12, 10, 15, 200, $backColor, $font, stripslashes(htmlspecialchars_decode_php4(urldecode($theTitle))));
imagettftext($im, 12, 10, 15, 200, $frontColor, $font, stripslashes(htmlspecialchars_decode_php4(urldecode($theTitle))));
imagejpeg($im, '', 100);
imagedestroy($im);
<table><tr><td><img src="image.php?text=This%20is%20a%20test" /></td></tr></table>