头像

PHP图片压缩

2018-04-17 09:33:35 浏览()   来源:http://www.phpdaima.com//jsfx-61.html   评论 ( 0 )   

    /*打开图片*/  
    $src = "bg.jpg";  
    $info = getimagesize($src);  
    $type = image_type_to_extension($info[2],false);  
    $fun = "imagecreatefrom".$type;  
    $image = $fun($src);  
      
    /*操作图片*/  
    //1.内存中建立一个300,200真色彩图片  
    $image_thumb = imagecreatetruecolor(300,200);  
    //2.核心步骤,将原图复制到真色彩图片上  
    imagecopyresampled($image_thumb, $image, 0, 0, 0, 0, 300, 200, $info[0], $info[1]);  
    //3.销毁原始图片  
    imagedestroy($image);  
      
    /*输出图片*/  
    //浏览器  
    header("Content-type:".$info['mime']);  
    $fun = "image".$type;  
    $fun($image_thumb);  
    //保存图片  
    $fun($image_thumb,'bg_tb.'.$type);  
    /*销毁图片*/  
    imagedestroy($image_thumb);


标签: php
广告不存在
评论0

后面还有条评论,点击查看>>

温馨提示:为规范评论内容,垃圾评论一律封号...