if?($_POST)?{
????
//?No?image?
????
if?(empty($_FILES['image'])?OR?$_FILES['image']['error']?!=?UPLOAD_ERR_OK)?{
????????die?(
'Invalid?image?uploaded.??Please?go?back?and?try?again.');
????}

????if?(empty(
$_POST['watermark']))?{
????????die(
'Please?enter?some?text?for?your?watermark.');
????}

????
$imagepath?=?$_FILES['image']['tmp_name'];

????
//?Load?image
????
$image?=?open_image($imagepath);

????if?(
$image?==?false)?{
????????die?(
'You?uploaded?an?invalid?image.?Please?go?back?and?try?again.');
????}

????switch(
$_POST['color'])?{
????????case?
'black':
????????????
$color?=?imagecolorallocate($image,?0,?0,?0);
????????????break;
????????case?
'red':
????????????
$color?=?imagecolorallocate($image,?255,?0,?0);
????????????break;
????????case?
'blue':
????????????
$color?=?imagecolorallocate($image,?0,?0,?255);
????????????break;
????????case?
'yellow':
????????????
$color?=?imagecolorallocate($image,?255,?255,?0);
????????????break;
????????case?
'green':
????????????
$color?=?imagecolorallocate($image,?0,?255,?0);
????????????break;
????????case?
'white':
????????default:
????????????
$color?=?imagecolorallocate($image,?255,?255,?255);
????}

????
//?Add?text?to?image
????
imagestring($image,?3,?5,?imagesy($image)-20,?$_POST['watermark'],?$color);



????
//?Display?image
????
header('Content-type:?image/jpeg');
????
imagejpeg($image);
????die();

}

//?Display?the?upload?form:
?>

????
????????Image?Watermarker

????
????????th?{?text-align:?right;?}
????

????

????
????????
????????
????????????
????????????????
????????????????
????????????

????????????
????????????????
????????????????
????????????

????????????
????????????????
????????????????
????????????

????????????
????????
????



function?open_image?($file)?{
????
#?JPEG:
????
$im?=?@imagecreatefromjpeg($file);
????if?(
$im?!==?false)?{?return?$im;?}

????
#?GIF:
????
$im?=?@imagecreatefromgif($file);
????if?(
$im?!==?false)?{?return?$im;?}

????
#?PNG:
????
$im?=?@imagecreatefrompng($file);
????if?(
$im?!==?false)?{?return?$im;?}

????
#?GD?File:
????
$im?=?@imagecreatefromgd($file);
????if?(
$im?!==?false)?{?return?$im;?}

????
#?GD2?File:
????
$im?=?@imagecreatefromgd2($file);
????if?(
$im?!==?false)?{?return?$im;?}

????
#?WBMP:
????
$im?=?@imagecreatefromwbmp($file);
????if?(
$im?!==?false)?{?return?$im;?}

????
#?XBM:
????
$im?=?@imagecreatefromxbm($file);
????if?(
$im?!==?false)?{?return?$im;?}

????
#?XPM:
????
$im?=?@imagecreatefromxpm($file);
????if?(
$im?!==?false)?{?return?$im;?}

????
#?Try?and?load?from?string:
????
$im?=?@imagecreatefromstring(file_get_contents($file));
????if?(
$im?!==?false)?{?return?$im;?}

????return?
false;
}
?>
Image:
Text:
Text?Color:
????????????????????
????????????????????????Black
????????????????????????White
????????????????????????Blue
????????????????????????Red
????????????????????????Yellow
????????????????????????Green????????????????????????
????????????????????????????????????
????????????????