thinkphp Framework for image cropping, zooming, and watermarking method

Source: Internet
Author: User
This article mainly introduced the thinkphp frame realizes the image clipping, the scale, the watermark method, combined with the example form gives the thinkphp for the picture to cut, the scale and adds the watermark the custom function, has the certain reference value, needs the friend can refer to the next

In this paper, the method of image clipping, zooming and watermarking is described in the thinkphp framework. Share to everyone for your reference, as follows:

thinkphp image processing function, need text watermark font, can be in Windows Control Panel > Large icon (upper right corner) > font to find the desired font

/*** cropping, zooming, and watermarking of images * @param string $path path * @param int $width width/width of clipping, or width of the picture when $height value is, otherwise the width or height of the limit * @param i NT $height [OPTIONAL] clipped height * @param boolean $water [optional] watermark * @param int $word [OPTIONAL] watermark text */function zoom_image ($path, $width  = A, $height = null, $water = null, $word = ' water ') {$image = new \think\image ();  $image->open ($path);  $imgWidth = $image->width ();  $imgHeight = $image->height ();    Limit size if ($width and! $height) {$maxSize = $width; If the width or height is greater than the specified size if ($imgWidth > $maxSize or $imgHeight > $maxSize) {$size = Image_min_width ($imgWidth, $imgHei      Ght, $maxSize);      $image->thumb ($size [' width '], $size [' height '];      $do = true;    $dowater = true;    }//Crop fixed size}else if ($width and $height) {$size = Image_min_width ($imgWidth, $imgHeight, $width);    $image->thumb ($size [' width '], $size [' height '])->crop ($width, $height);    $do = true;  $dowater = true; if ($dowater and $water and $word) {$image->text ($word, './puBlic/images/arial.ttf ', A, ' #dddddd ', \think\image::image_water_southeast,-10);  }//Do not save if ($do) {$image->save ($path); }}

The above is the whole content of this article, I hope that everyone's study has helped.


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.