Txt2Img - Header Already Sent Problem

Hi Friends,

I am running a phone directory on my site, but i don't want to protect my phone numbers to be copied in bulk.

I found this useful piece of a script which convert text string to image.


header ("Content-type: image/png");
$string = '9896214589';
$font   = 6;
$width  = ImageFontWidth($font) * strlen($string);
$height = ImageFontHeight($font);

$im = @imagecreate ($width,$height);
$background_color = imagecolorallocate ($im, 255, 255, 255); //white background
$text_color = imagecolorallocate ($im, 0, 0,0);//black text
imagestring ($im, $font, 0, 0,  $string, $text_color);
imagepng ($im);

But the issue is when i placed it in my theme its giving me the error --> "Warning: Cannot modify header information - headers already sent by"

Is there any quick solution?