首页 > 开发 > PHP > 正文

php 方便水印和缩略图的图形类

2024-05-04 22:11:18
字体:
来源:转载
供稿:网友
代码如下:
<?php

/*
*@author    夜无眠    27262681@qq.com
*copyright    http://www.gowake.cn
*/

class img {
    function __construct($arg = null) {
        $args = func_get_args();
        if($arg == null) {
            return null;
        }
        $this->im = call_user_func_array(array($this,'create'),$args);
    }

    function __call($func,$arg) {
        if(function_exists('image'.$func)) {
            $funcstr = 'image'.$func;
        }elseif (function_exists($func)){
            $funcstr = $func;
        }else {
            error("没有这个类方法或函数");
        }
        return call_user_func_array($funcstr,$arg);
    }

    /*
    *创建图像
    *@param string/int 图片文件路径或者宽度
    *@param int 高度,可省略
    *@param string 6位16进制整数
    */
    function create($arg = null) {
        $args = func_get_args();
        if(is_file($args[0])) {
            $this->file = $args[0];
            $size = getimagesize($this->file) or error('图片类型错误');
            $this->size = $this->size ? $this->size : $size;
            $type = image_type_to_extension($size[2],false);
            $this->type = $this->type ? $this->type : $type;
            $createfunc = 'imagecreatefrom'.$type;
            $im = $createfunc($this->file);
        }elseif((int)$args[0]>0 and (int)$args[1]>0) {
            $im = imagecreatetruecolor((int)$args[0],(int)$args[1]) or error("对不起,参数错误!");
发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表