This article mainly introduces the method of thinkphp water mark and setting watermark location, and analyzes the related operation steps and concrete implementation skills of thinkphp printing and setting watermark with instance form, and the friends who need can refer to the following
Recently in the use of thinkphp water seal function, found only hit in the lower left corner. PHP water printing is still very easy, the most use of
Copy the Code code as follows:
BOOL Imagecopymerge (Resource $DST _im, resource $src _im, int $dst _x, int $dst _y, int $src _x, int $src _y, int $src _w , int $src _h, int $pct)
Starts the coordinates in the src_im image from Src_x,src_y, with a width of src_w, and a portion of the height of Src_h copied to the Dst_im and dst_x locations in the dst_y image. The two images will be based on the PCT to determine the degree of consolidation, with values ranging from 0 to 100. When pct = 0 o'clock, actually did nothing, when 100 for the palette image this function and imagecopy () exactly the same, it is the true color image to achieve alpha transparency.
Watermark Demo Diagram:
I need to hit the watermark to the real middle of the picture and see the thinkphp code. Found that the author is actually writing dead, I can only make a change
/*** Add a watermark to a picture * @static public* @param string $source The original file name * @param string $water watermark Picture * @param string $ $savename add watermark after image name * @ param string $postion The exact location of the watermark Leftbottom rightbottom lefttop Righttop Center < new >* @param string $alpha The transparency of the watermark * @ret Urn void*/static public Function water ($source, $water, $savename =null, $postion = "center", $alpha =80) {//check if the file exists if (! File_exists ($source) | | !file_exists ($water)) return false;//picture information $sinfo = Self::getimageinfo ($source); $wInfo = Self::getimageinfo ($water);// If the picture is less than the watermark picture, do not generate a picture if ($sInfo ["width"] < $wInfo ["width"] | | $sInfo [' height '] < $wInfo [' height '] return false; Create an image $sCreateFun = "Imagecreatefrom". $sInfo [' type ']; $sImage = $sCreateFun ($source); $wCreateFun = "Imagecreatefrom". $wInfo [' type ']; $wImage = $wCreateFun ($water); Sets the image's color-blending mode imagealphablending ($wImage, true); Image position, default to right bottom right corner $POSARR = $this->waterpostion ($postion, $sInfo, $wInfo); Add//Generate mixed Image Imagecopymerge ($sImage, $wImage, $POSARR [0], $POSARR [1], 0, 0, $wInfo [' width '], $wInfo [' height '], $alpha); Output image $ImageFun = ' image '. $sInfo [' type ']; If the save file name is not given, the default is the original image name if (! $savename) {$savename = $source; @unlink ($source); }//Save Image $ImageFun ($sImage, $savename); Imagedestroy ($sImage); } Private Function Waterpostion ($postion, $sInfo, $wInfo) {$posY = $sInfo ["height"]-$wInfo ["height"]; $posX = $sInfo ["width"]-$wInfo ["width"]; Switch ($postion) {case "Rightbottom": Return Array ($posX, $posY); Break Case "Leftbottom": Return Array ($wInfo ["width"], $posY); Break Case "Lefttop": Return Array ($wInfo ["width"], $wInfo ["height"]); Break Case "Righttop": Return Array ($posX, $wInfo ["height"]); Break Case "Center": Return Array ($posX/2, $posY/2); Break }}
Summary: The above is the entire content of this article, I hope to be able to help you learn.