天天看点

PHP微缩图片

代码:

1. <?php
2. header('Content-Type:image/png');
3. 
4. $pic_name = __DIR__.'\\src\\images\\png\\demo.png';
5. //获取到原图的长高
6. list($width,$height) =getimagesize($pic_name);
7. $_width=$width*0.5;
8. $_height=$height*0.5;
9. //创建新图像
10. $im=imagecreatetruecolor($_width, $_height);
11. //载入原图
12. $im_post=imagecreatefrompng($pic_name);
13. 
14. imagecopyresampled($im, $im_post, 0, 0, 0, 0, $_width, $_height, $width, $height);
15. imagepng($im);
16. imagedestroy ($im);
17. imagedestroy ($im_post);
18. 
19. ?>      
上一篇: 源码