PHP读取图片内容并在浏览器显示


PHP #图片2014-04-21 08:56

代码如下:

<?php

class imgdata{  
            public $imgsrc;  
            public $imgdata;  
            public $imgform;  
            public function getdir($source){  
                    $this->imgsrc  = $source;  
            }  
            public function img2data(){  
                    $this->_imgfrom($this->imgsrc);  
                    return $this->imgdata=fread(fopen($this->imgsrc,'rb'),filesize($this->imgsrc));          
            }  
            public function data2img(){  
                    header("content-type:$this->imgform");  
                    echo $this->imgdata;  
                    //echo $this->imgform;  
                    //imagecreatefromstring($this->imgdata);  
            }  
            public function _imgfrom($imgsrc){  
                    $info=getimagesize($imgsrc);  
                    //var_dump($info);  
                    return $this->imgform = $info['mime'];  
            }   
    }  

//调用示例 
    $n = new imgdata;  
    $n -> getdir("http://yige.org/static/images/icon/php.jpg");  
    $n -> img2data();  
    $n -> data2img(); 


相关文章

粤ICP备11097351号-1