Analysis on the location of thinkphp and watermark

Source: Internet
Author: User
Tags save file
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

In this paper, the method of thinkphp water seal and setting watermark location is described. Share to everyone for your reference, as follows:

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

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 }}

The above is the whole content of this article, I hope that everyone's learning has helped, more relevant content please pay attention to topic.alibabacloud.com!

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.