麻烦请问一下为什么会报错Call to undefined function imagecopyresmpled()

来源:5-1 封装成类—压缩图片

了吾欲前行

2016-04-04 21:26

<?php
    class Image{
        /*
        内存中的图片
        */
        private $image;

        /*
        图片基本信息
        */
        private $info;

        /*
        打开一张图片,读取到内存中
        */
        public function __construct($src){
            $info=getimagesize($src);
            $this->info=array(
                'width'=>$info[0],
                'height'=>$info[1],
                'type'=>image_type_to_extension($info['2'],false),
                'mime'=>$info['mime']
        );
            $fun="imagecreatefrom{$this->info['type']}";
            $this->image=$fun($src);
        }
    
        /*
        操作图片(压缩)
        */
        public function thumb($width,$height){
            $image_thumb=imagecreatetruecolor($width,$height);
            imagecopyresmpled($image_thumb,$this->image,0,0,0,0,$width,$height,$this->info['width'],$this->info['heigt']);
            imagedestroy($this->image);
            $this->image=$image_thumb;
        }

        /*
        在浏览器中输出图片
        */
        public function show(){
            header("Content-type:".$this->info['mime']);
            $funs="image{$this->info['type']}";
            $funs($this->image);
        }
        /*
        把图片保存到硬盘中
        */

        public function save($newname){
            $funs="image{$this->info['type']}";
            $funs($this->image,$newname.'.'.$this->info['type']);
        }

        /*
        销毁图片
        */
        public function __destruct(){
            imagedestroy($this->image);
        }
}
?>


写回答 关注

2回答

  • GrayZXH
    2016-07-27 13:49:50

    单词拼写错了 第33行 imagecopyresmpled该换成imagecopyresampled

  • lwp0fy
    2016-04-05 15:27:59

    imagecopyresampled()

GD库实现图片水印与缩略图

带你快速高效的完成图片处理工作,还可以加深对面向对象的理解

19006 学习 · 162 问题

查看课程

相似问题