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.