PHP图像操作类

2023-03-20 0 334

PHP图像操作的一个类,包括给图像添加文字水印、图像水印和压缩图片。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
<?php 
  
class Image { 
  
    private $info
    private $type
    private $iamge
  
  
    /**
    * 打开图片,写入内存
    *
    **/
    public function __construct($src)  
    
        $this->info = getimagesize($src); 
        $this->type = image_type_to_extension($this->info[2],false); 
        $fun = "imagecreatefrom".$this->type; 
        $this->image = $fun($src); 
    
  
    //缩略图 
    public function thumb($width, $height
    
        $image_thumb = imagecreatetruecolor($width, $height); 
        imagecopyresampled($image_thumb, $this->image, 0, 0, 0, 0, $width, $height, $this->info[0], $this->info[1]); 
        imagedestroy($this->image); 
        $this->image = $image_thumb
    
  
    //文字水印 
    public function fontMark($content, $fontUrl, $size, $color, $locate=array('x'=>0,'y'=>0), $angle=0) 
    
        $color = imagecolorallocatealpha($this->image, $color[0], $color[1], $color[2], $color[3]); 
        imagettftext($this->image, $size, $angle, $locate['x'], $locate['y'], $color, $fontUrl, $content); 
    
  
    //图片水印 
    public function imageMark($src,$locate,$alpha
    
        $info2 = getimagesize($src); 
        $type2 = image_type_to_extension($info2[2],false); 
        $fun2 = "imagecreatefrom".$type2
        $water = $fun2($src); 
        imagecopymerge($this->image, $water, $locate['x'], $locate['y'], 0, 0, $info2[0], $info2[1], $alpha); 
        imagedestroy($water); 
    
  
    //在浏览器中显示 
    public function show() 
    
        header("Content-type:".$this->info['mime']); 
        $fun = "image".$this->type; 
        $fun($this->image); 
    
  
    //保存为文件 
    public function save($newname
    
        $fun = "image".$this->type; 
        $fun($this->image, $newname.'.'.$this->type); 
    
  
    public function __destruct() 
    
        imagedestroy($this->image); 
    
}

1. 本站所有资源来源于用户上传和网络,因此不包含技术服务请大家谅解!如有侵权请邮件联系客服!

2. 本站不保证所提供下载的资源的准确性、安全性和完整性,资源仅供下载学习之用!如有链接无法下载、失效或广告,请联系客服处理,有奖励!

3. 您必须在下载后的24个小时之内,从您的电脑中彻底删除上述内容资源!如用于商业或者非法用途,与本站无关,一切后果请用户自负!

4. 如果您也有好的资源或教程,您可以投稿发布,成功分享后有猫币奖励和额外收入!

5. 本站资源售价只是赞助,收取费用仅维持本站的日常运营所需!

ER0学院 php 代码片段 PHP图像操作类 https://www.er0xy.com/2758.html

常见问题

相关文章

发表评论
1 条评论
2023年 5月 5日 上午9:29 回复

Thanks for sharing. I read many of your blog posts, cool, your blog is very good.

  • 0 +

    访问总数

  • 0 +

    会员总数

  • 0 +

    文章总数

  • 0 +

    今日发布

  • 0 +

    本周发布

  • 0 +

    运行天数

你的前景,远超我们想象