Home >php教程 >PHP源码 >php 压缩图片方法

php 压缩图片方法

PHP中文网
PHP中文网Original
2016-05-23 16:37:121942browse


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

                   

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn