thinkphp water Printing and watermark location Method _php Example

Source: Internet
Author: User
Tags add watermark to picture php template save file smarty template

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.

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.