<form action= "<?=$_server[' php_self ']?>" method= "post" enctype= "Multipart/form-data" Name= "Form1" id= " Form1 ">
<table width= "486" border= "0" align= "center" cellpadding= "0" cellspacing= "0" >
<tr>
<TD width= "498" height= "background=" image/top.gif ><div "center" align= "class=" > Upload pictures style2 ></td>
</tr>
<tr>
<td> </td>
</tr>
<tr>
<td><div align= "Right" >
<table width= "426" border= "0" align= "center" cellpadding= "0" cellspacing= "0" >
<tr>
<TD width= "height=" nowrap= "nowrap" > Path:</td>
<TD width= "362" ><input name= "upfile" type= "file" id= "Upfile" size= ""/></td>
</tr>
<tr>
<TD height= "colspan=" "2" ><div align= "center" >
<input type= "Submit" name= "Submission" value= "submitted"/>
<input type= "reset" name= "Submit" value= "reset"/>
</div></td>
</tr>
</table>
</div>
<div align= "center" ></div></td>
</tr>
<tr>
<td> </td>
</tr><input type= "hidden" name= ' action ' value= ' Doup ' >
<tr>
<TD height= "background=" "Image/top.gif" > </td>
</tr>
<tr>
<td> </td>
</tr>
</table>
</form>
<br>
<a href=http://www.bianceng.cn target=_blank> Programming Gateway Bianceng.cn</a>
?
if ($_post[' action ']== ' Doup ')
{
$uptypes =array (' image/jpg ', ' image/jpeg ', ' image/pjpeg ', ' image/gif '); Upload picture file type list
$wFile =$_files[' upfile '];//get file path
$waterimg = "water.gif";//Watermark Picture Path
Print_r ($wFile);
if (In_array ($wFile [' type '], $uptypes))
{//Check file type, if the uploaded file is a jpg or GIF picture then add watermark
if (Strstr ($wFile [' type '], "JP"))
{///If upload picture type is jpg,pjpeg,jpeg, read target file with Imagecreatefromjpeg
$im = Imagecreatefromjpeg ($wFile [' tmp_name ']);
$wfilew =imagesx ($im);//Get the width of the picture
$wfileh =imagesy ($im);//Get the picture high
}
Else
{//Otherwise, if the uploaded picture type is GIF, read the target file with Imagecreatefromgif
$im = Imagecreatefromgif ($wFile [' tmp_name ']);
$wfilew =imagesx ($im);//Get the width of the picture
$wfileh =imagesy ($im);//Get the picture high
}
Set Blending mode
Imagealphablending ($im, true);
Read Watermark File
$im 2 = imagecreatefrompng ($waterimg);//If the watermark picture is JPG, then this can be changed to $IM2 = Imagecreatefromjpeg ($waterimg)
$white = Imagecolorallocate ($im 2, 255, 255, 255);
Imagecolortransparent ($im 2, $white); Set the transparent color, these two can not
$waterw =imagesx ($im 2);//Get the width of the watermark picture
$waterh =imagesy ($im 2);//Get watermark Picture High
Random water prints to the picture
$randval = rand (0,9);//Generate a random number between 0-9
if ($randval ==0| | $randval ==3| | $randval ==2| | $randval ==8| | $randval ==7) {//Here you can also improve your placement
$WIMGX =5; $wimgy =5;//in upper left corner
}else{
$WIMGX = $wfilew $waterw; $wimgy = $wfileh;
}
Copy Watermark to target file
Imagecopy ($im, $im 2, $WIMGX, $wimgy, 0, 0, $waterw, $waterh);
Output picture
if (Strstr ($wFile [' type '], "JP")) {//Ibid.
Imagejpeg ($im, $wFile [' tmp_name ']);
}else{
Imagegif ($im, $wFile [' tmp_name ']);
}
Imagedestroy ($im);
Imagedestroy ($im 2);
Copy ($wFile [' Tmp_name '], $wFile [' name ']); Upload
}
else echo "picture does not match!! ";
}
?>