<?php
class mail2image {
	
	public $color;
	public $dir;
	
	public function __construct($color, $dir) {
		$this->color = explode(',', $color);
		
		$this->dir = $dir;
	}
	public function text($text) {
		$text = explode(' ', $text);
		foreach ($text as &$value) {
		    if(preg_match('/^[a-zA-Z0-9._-]+@[a-zA-Z0-9-]+\.[a-zA-Z.]{2,5}$/', $value))
		    {
			    $this->gen_image($value);
			    $value = '<img src="'.$this->dir.sha1($value).'.png">';
		    }
		}
		return implode(' ', $text);
	}
	private function gen_image($mail) {
		$font = imageloadfont('courier8.gdf');
		$width = imagefontwidth($font)*strlen($mail);
		$height = imagefontheight($font);
		
		$image = imagecreatetruecolor($width, $height);
		$trns = imagecolortransparent($image, imagecolorallocate($image, 1, 1, 1)); //Gebruiken we hiervoor 0,0,0 dan kunnen we deze kleur niet meer voor de tekst gebruiken
		$color = imagecolorallocate($image, $this->color[0], $this->color[1], $this->color[2]);
		
		imagefilledrectangle($image, 0, 0, $width, $height, $trns);
		
		imagestring($image, $font, 0, 0, $mail, $color);
		
		imagepng($image, $this->dir.sha1($mail).'.png');
		imagedestroy($image);
	}
}

$image = new mail2image('0,0,0', 'afbeelding/'); //kleur van tekst, directory waarin afbeeldingen worden opgeslagen(zelf aanmaken)
echo $image->text('Hier komt je tekst met email adressen bijv. email@burgerking.com');
?>