This paper illustrates the method of thinkphp water printing and setting watermark location. Share to everyone for your reference, specific as follows:
Recently in the use of thinkphp water printing function, found only in the lower left corner. PHP Water printing work is still very easy, most of the use of
Copy 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)
The coordinates of the src_im image are started from the src_x,src_y, the width is src_w, and the height is part of the src_h copy to the Dst_im image in the location of Dst_x and dst_y. The two images will be based on the PCT to determine the degree of consolidation, the value range from 0 to 100. When pct = 0 o'clock, in fact nothing is done, when 100 for the palette image this function and imagecopy () exactly the same, it is true color image to achieve alpha transparency.
Watermark Demo Map:
I need to get the watermark to the real center of the picture and see the thinkphp code. Found that the author is incredibly written dead, I can only make a change
/** * Add watermark to Picture * @static public * @param string $source the original filename * @param string $water watermark Picture * @param string $ $savename after adding a watermark Picture name * @param string $postion The specific location of the watermark Leftbottom rightbottom lefttop Righttop Center < New > * @param string $alpha watermark Lightness * @return void/static public function water ($source, $water, $savename =null, $postion = "center", $alpha =80) {//check whether the file
Presence 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 the 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 blending mode imagealphablending ($wImage, true) of the image; Image position, default to right $POSARR = lower right corner = $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 you do not give the save file name, 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
}
}
More interested in thinkphp related content readers can view the site topics: "thinkphp Introductory Course", "thinkphp Template Operation Skills Summary", "thinkphp Common Methods Summary", "Smarty Template Introductory Course" and "PHP template technology Summary."
I hope this article will help you with the PHP program design based on thinkphp framework.