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
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.
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, and I can only make a modification
/**
* Add a watermark to a picture
* @static Public
* @param string $source The original file name
* @param string $water watermark Picture
* @param string $ $savename The name of the picture after the watermark is added
* @param the exact location of the string $postion watermark leftbottom rightbottom lefttop righttop Center < add >
* @param string $alpha The transparency of the watermark
* @return void
*/
static public Function water ($source, $water, $savename =null, $postion = "center", $alpha =80) {
Check to see if a 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 smaller than the watermark picture, no picture is generated
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); New
To generate a mixed image
Imagecopymerge ($sImage, $wImage, $POSARR [0], $POSARR [1], 0, 0, $wInfo [' width '], $wInfo [' height '], $alpha);
Output image
$ImageFun = ' Image '. $sInfo [' type '];
If no save file name is 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
}
}
It seems to be on the ~