I believe we all know how to use PHP for images to add text watermark, but if the watermark effect is a picture it? What should I do? Don't worry, the following will break it down for you. I also recently used this feature, so to Baidu on the collection of this document, I hope you have some help.
Dragon's Heart column phpshao.cublog.cn
if ($_post[' action ']== ' Doup ')
{
$uptypes =array (' image/jpg ', ' image/jpeg ', ' image/pjpeg ', ' image/gif ');//Upload picture file type list
$wFile =$_files[' upfile '];//get the file path
$waterimg = "water.gif";//Watermark Picture path//print_r ($wFile);
if (In_array ($wFile [' type '], $uptypes))
{//Check file type, add watermark if upload file is jpg or GIF picture
if (Strstr ($wFile [' type '], "JP"))
{//If the upload image type is jpg,pjpeg,jpeg, the target file is read 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 upload image type is gif, use Imagecreatefromgif to read the target file
$im = Imagecreatefromgif ($wFile [' tmp_name ']);
$wfilew =imagesx ($im);//Get the width of the picture
$wfileh =imagesy ($im);//Get the picture high
}
Setting the blending mode
Imagealphablending ($im, true);
Read Watermark File
$im 2 = imagecreatefrompng ($waterimg);//If the watermark image is jpg, then this go can be changed to $IM2 = Imagecreatefromjpeg ($waterimg)//$white = Imagecolorallocate ($im 2, 255, 255, 255);
Imagecolortransparent ($im 2, $white); Set the transparent color, these two sentences can not $waterw=imagesx ($im 2);//Obtain the width of the watermark picture
$waterh =imagesy ($im 2);//Get a high watermark image
Random release to the picture
$randval = rand (0,9);//Generate random numbers between 0-9
if ($randval ==0| | $randval ==3| | $randval ==2| | $randval ==8| | $randval ==7) {//Here can also be improved to put more locations
$WIMGX =5; $wimgy =5;//the upper left corner
}else{
$WIMGX = $wfilew-$waterw; $wimgy = $wfileh-$waterh;//top-right corner
}//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!! ";
}
?>
http://www.bkjia.com/PHPjc/371650.html www.bkjia.com true http://www.bkjia.com/PHPjc/371650.html techarticle I believe we all know how to use PHP for images to add text watermark, but if the watermark effect is a picture it? What should I do? Don't worry, the following will break it down for you. I also recently used this feature ...