<?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(!emptyempty($waterImage) && file_exists($waterImage))
{
$isWaterImage = TRUE;
$water_info = getimagesize($waterImage);
$water_w = $water_info[0];//
$water_h = $water_info[1];//
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(!emptyempty($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*5),0,”./cour.ttf”,$waterText);// TrueType
$w = $temp[2] - $temp[6];
$h = $temp[3] - $temp[7];
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( !emptyempty($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);
}
//―――――――――――――――――――――――――――――
$id=$_REQUEST['id'];
$num = count($_FILES['userfile']['name']);
print_r($_FILES['userfile']);
print_r($_FILES['userfile']['name']);
echo $num;
echo “<bR>”;
if(isset($id)){
for($i=0;$i<$id;$i++){
if(isset($_FILES) && !emptyempty($_FILES['userfile']) && $_FILES['userfile']['size']>0)
{
$uploadfile = “./”.time().”_”.$_FILES['userfile'][name][$i];
echo “<br>”;
echo $uploadfile;
if (copy($_FILES['userfile']['tmp_name'][$i], $uploadfile))
{
echo “OK<br>”;
//
//imageWaterMark($uploadfile,5,”",”HTTP://www.lvye.info”,5,”#cccccc“);
//
$waterImage=”logo_ok1.gif”;//
imageWaterMark($uploadfile,9,$waterImage);
echo “<img src=\”".$uploadfile.”\” border=\”0\”>”;
}
else
{
echo “Fail<br>”;
}
}
}
}
?>
<form enctype=”multipart/form-data” method=”POST”>
<?php
for($a=0;$a<$id;$a++){
echo “ : <input name=\”userfile[]\” type=\”file\”><br>”;
}
?>
<input type=”submit” value=” ”>
</form>