Home> php教程> PHP源码> body text

php 压缩图片方法

PHP中文网
Release: 2016-05-23 16:37:12
Original
1869 people have browsed it


/*打开图片*/ $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);
Copy after login

Related labels:
source:php.cn
Statement of this Website
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
Popular Recommendations
    Latest Downloads
    More>
    Web Effects
    Website Source Code
    Website Materials
    Front End Template
    About us Disclaimer Sitemap
    php.cn:Public welfare online PHP training,Help PHP learners grow quickly!