![]() |
|
Ê×Ò³ ©¦ Apache ©¦ Linux©¦ Java©¦ MySQL©¦ ×¢²á©¦°ïÖú | |||
ÈçҪͶËß»òÌá³öÒâ¼û½¨Ò飬Çëµ½
Õ¾Îñ½¨ÒéͶËß°É·´À¡¡£
[PHP]<?php
/*
* ¹¦ÄÜ£ºPHPͼƬˮӡ (ˮӡ֧³ÖͼƬ»òÎÄ×Ö)
* ²ÎÊý£º
* $groundImage ±³¾°Í¼Æ¬£¬¼´ÐèÒª¼ÓˮӡµÄͼƬ£¬ÔÝÖ»Ö§³ÖGIF,JPG,PNG¸ñʽ£»
* $waterPos ˮӡλÖã¬ÓÐ10ÖÖ״̬£¬0ÎªËæ»úλÖã»
* 1Ϊ¶¥¶Ë¾Ó×ó£¬2Ϊ¶¥¶Ë¾ÓÖУ¬3Ϊ¶¥¶Ë¾ÓÓÒ£»
* 4ΪÖв¿¾Ó×ó£¬5ΪÖв¿¾ÓÖУ¬6ΪÖв¿¾ÓÓÒ£»
* 7Ϊµ×¶Ë¾Ó×ó£¬8Ϊµ×¶Ë¾ÓÖУ¬9Ϊµ×¶Ë¾ÓÓÒ£»
* $waterImage ͼƬˮӡ£¬¼´×÷ΪˮӡµÄͼƬ£¬ÔÝÖ»Ö§³ÖGIF,JPG,PNG¸ñʽ£»
* $waterText ÎÄ×Öˮӡ£¬¼´°ÑÎÄ×Ö×÷ΪΪˮӡ£¬Ö§³ÖASCIIÂ룬²»Ö§³ÖÖÐÎÄ£»
* $textFont ÎÄ×Ö´óС£¬ÖµÎª1¡¢2¡¢3¡¢4»ò5£¬Ä¬ÈÏΪ5£»
* $textColor ÎÄ×ÖÑÕÉ«£¬ÖµÎªÊ®Áù½øÖÆÑÕɫֵ£¬Ä¬ÈÏΪ#FF0000(ºìÉ«)£»
*
* ×¢Ò⣺Support GD 2.0£¬Support FreeType¡¢GIF Read¡¢GIF Create¡¢JPG ¡¢PNG
* $waterImage ºÍ $waterText ×îºÃ²»ÒªÍ¬Ê±Ê¹Óã¬Ñ¡ÆäÖÐÖ®Ò»¼´¿É£¬ÓÅÏÈʹÓà $waterImage¡£
* µ±$waterImageÓÐЧʱ£¬²ÎÊý$waterString¡¢$stringFont¡¢$stringColor¾ù²»ÉúЧ¡£
* ¼ÓˮӡºóµÄͼƬµÄÎļþÃûºÍ $groundImage Ò»Ñù¡£
* ×÷Õߣºlongware @ 2004-11-3 14:15:13
*/
function imageWaterMark($groundImage,$waterPos=0,$waterImage="",$waterText="",$textFont=5,$textColor="#FF0000")
{
$isWaterImage = FALSE;
$formatMsg = "Ôݲ»Ö§³Ö¸ÃÎļþ¸ñʽ£¬ÇëÓÃͼƬ´¦ÀíÈí¼þ½«Í¼Æ¬×ª»»ÎªGIF¡¢JPG¡¢PNG¸ñʽ¡£";
//¶ÁȡˮӡÎļþ
if(!empty($waterImage) && file_exists($waterImage))
{
$isWaterImage = TRUE;
$water_info = getimagesize($waterImage);
$water_w = $water_info[0];//È¡µÃˮӡͼƬµÄ¿í
$water_h = $water_info[1];//È¡µÃˮӡͼƬµÄ¸ß
print_r($water_info);
switch($water_info[2])//È¡µÃˮӡͼƬµÄ¸ñʽ
{
case 1
water_im = imagecreatefromgif($waterImage);break;
case 2
water_im = imagecreatefromjpeg($waterImage);break;
case 3
water_im = imagecreatefrompng($waterImage);break;
default:die($formatMsg);
}
}
//¶ÁÈ¡±³¾°Í¼Æ¬
if(!empty($groundImage) && file_exists($groundImage))
{
$ground_info = getimagesize($groundImage);
$ground_w = $ground_info[0];//È¡µÃ±³¾°Í¼Æ¬µÄ¿í
$ground_h = $ground_info[1];//È¡µÃ±³¾°Í¼Æ¬µÄ¸ß
switch($ground_info[2])//È¡µÃ±³¾°Í¼Æ¬µÄ¸ñʽ
{
case 1
ground_im = imagecreatefromgif($groundImage);break;
case 2
ground_im = imagecreatefromjpeg($groundImage);break;
case 3
ground_im = imagecreatefrompng($groundImage);break;
default:die($formatMsg);
}
}
else
{
die("ÐèÒª¼ÓˮӡµÄͼƬ²»´æÔÚ£¡");
}
//ˮӡλÖÃ
if($isWaterImage)//ͼƬˮӡ
{
$w = $water_w;
$h = $water_h;
$label = "ͼƬµÄ";
}
else//ÎÄ×Öˮӡ
{
// $temp = imagettfbbox(ceil($textFont*2.5),0,"./cour.ttf",$waterText);//È¡µÃʹÓà TrueType ×ÖÌåµÄÎı¾µÄ·¶Î§
// $w = $temp[2] - $temp[6];
// $h = $temp[3] - $temp[7];
$w = 100;
$w = 100;
// unset($temp);
$label = "ÎÄ×ÖÇøÓò";
}
if( ($ground_w<$w) || ($ground_h<$h) )
{
echo "ÐèÒª¼ÓˮӡµÄͼƬµÄ³¤¶È»ò¿í¶È±Èˮӡ".$label."»¹Ð¡£¬ÎÞ·¨Éú³Éˮӡ£¡";
return;
}
switch($waterPos)
{
case 0://Ëæ»ú
$posX = rand(0,($ground_w - $w));
$posY = rand(0,($ground_h - $h));
break;
case 1://1Ϊ¶¥¶Ë¾Ó×ó
$posX = 0;
$posY = 0;
break;
case 2://2Ϊ¶¥¶Ë¾ÓÖÐ
$posX = ($ground_w - $w) / 2;
$posY = 0;
break;
case 3://3Ϊ¶¥¶Ë¾ÓÓÒ
$posX = $ground_w - $w;
$posY = 0;
break;
case 4://4ΪÖв¿¾Ó×ó
$posX = 0;
$posY = ($ground_h - $h) / 2;
break;
case 5://5ΪÖв¿¾ÓÖÐ
$posX = ($ground_w - $w) / 2;
$posY = ($ground_h - $h) / 2;
break;
case 6://6ΪÖв¿¾ÓÓÒ
$posX = $ground_w - $w;
$posY = ($ground_h - $h) / 2;
break;
case 7://7Ϊµ×¶Ë¾Ó×ó
$posX = 0;
$posY = $ground_h - $h;
break;
case 8://8Ϊµ×¶Ë¾ÓÖÐ
$posX = ($ground_w - $w) / 2;
$posY = $ground_h - $h;
break;
case 9://9Ϊµ×¶Ë¾ÓÓÒ
$posX = $ground_w - $w;
$posY = $ground_h - $h;
break;
default://Ëæ»ú
$posX = rand(0,($ground_w - $w));
$posY = rand(0,($ground_h - $h));
break;
}
//É趨ͼÏñµÄ»ìɫģʽ
imagealphablending($ground_im, true);
if($isWaterImage)//ͼƬˮӡ
{
imagecopy($ground_im, $water_im, $posX, $posY, 0, 0, $water_w,$water_h);//¿½±´Ë®Ó¡µ½Ä¿±êÎļþ
}
else//ÎÄ×Öˮӡ
{
if( !empty($textColor) && (strlen($textColor)==7) )
{
$R = hexdec(substr($textColor,1,2));
$G = hexdec(substr($textColor,3,2));
$B = hexdec(substr($textColor,5));
}
else
{
die("ˮӡÎÄ×ÖÑÕÉ«¸ñʽ²»ÕýÈ·£¡");
}
imagestring ( $ground_im, $textFont, $posX, $posY, $waterText, imagecolorallocate($ground_im, $R, $G, $B));
}
//Éú³ÉˮӡºóµÄͼƬ
@unlink($groundImage);
switch($ground_info[2])//È¡µÃ±³¾°Í¼Æ¬µÄ¸ñʽ
{
case 1:imagegif($ground_im,$groundImage);break;
case 2:imagejpeg($ground_im,$groundImage);break;
case 3:imagepng($ground_im,$groundImage);break;
default:die($errorMsg);
}
//ÊÍ·ÅÄÚ´æ
if(isset($water_info)) unset($water_info);
if(isset($water_im)) imagedestroy($water_im);
unset($ground_info);
imagedestroy($ground_im);
}
//---------------------------------------------------------------------------------------
if(isset($_FILES) && !empty($_FILES['userfile']) && $_FILES['userfile']['size']>0)
{
$uploadfile = "./".time()."_".$_FILES['userfile']['name'];
if (copy($_FILES['userfile']['tmp_name'], $uploadfile))
{
echo "OK
";
//ÎÄ×Öˮӡ
imageWaterMark($uploadfile,9,"note.gif","HTTP://BLOG.CSDN.NET/LONGWARE/",5,"#FF0000");
//ͼƬˮӡ
// $waterImage="./ff.gif";//ˮӡͼƬ·¾¶
// imageWaterMark($uploadfile,0,$waterImage);
echo "";
}
else
{
echo "Fail
";
}
}
?>

