1. <?php
2. /**
3. * 生成缩略图函数(支持图片格式:gif、jpeg、png和bmp)
4. * @author ruxing.li
5. * @param string $src 源图片路径
6. * @param int $width 缩略图宽度(只指定高度时进行等比缩放)
7. * @param int $width 缩略图高度(只指定宽度时进行等比缩放)
8. * @param string $filename 保存路径(不指定时直接输出到浏览器)
9. * @return bool
10. */
11. function mkThumbnail($src, $width = null, $height = null, $filename = null) {
12. if (!isset($width) && !isset($height))
13. return false;
14. if (isset($width) && $width <= 0)
15. return false;
16. if (isset($height) && $height <= 0)
17. return false;
18.
19. $size = getimagesize($src);
20. if (!$size)
21. return false;
22.
23. $src_w, $src_h, $src_type) = $size;
24. $src_mime = $size['mime'];
25. switch($src_type) {
26. case 1 :
27. $img_type = 'gif';
28. break;
29. case 2 :
30. $img_type = 'jpeg';
31. break;
32. case 3 :
33. $img_type = 'png';
34. break;
35. case 15 :
36. $img_type = 'wbmp';
37. break;
38. default :
39. return false;
40. }
41.
42. if (!isset($width))
43. $width = $src_w * ($height / $src_h);
44. if (!isset($height))
45. $height = $src_h * ($width / $src_w);
46.
47. $imagecreatefunc = 'imagecreatefrom' . $img_type;
48. $src_img = $imagecreatefunc($src);
49. $dest_img = imagecreatetruecolor($width, $height);
50. $dest_img, $src_img, 0, 0, 0, 0, $width, $height, $src_w, $src_h);
51.
52. $imagefunc = 'image' . $img_type;
53. if ($filename) {
54. $imagefunc($dest_img, $filename);
55. else {
56. 'Content-Type: ' . $src_mime);
57. $imagefunc($dest_img);
58. }
59. $src_img);
60. $dest_img);
61. return true;
62. }
63.
64. $result = mkThumbnail('./IMG_3324.JPG', 147, 147);
PHP 生成图片缩略图函数
转载
提问和评论都可以,用心的回复会被更多人看到
评论
发布评论
相关文章
-
Python的extend插入的字符串
茕茕孑立 沆瀣一气 踽踽独行 醍醐灌顶 绵绵瓜瓞 奉为圭臬 龙行龘龘 犄角旮旯 娉婷袅娜 涕泗滂沱 呶呶不休 不稂不莠 这首《生僻字》,考验的是“语文”硬实力。倘若实力不够,其实可以拿Python来凑,毕竟库多!今天就来说一个有意思的pypinyin库,名字很直白,是python版的拼音库,用来将汉字转为拼音。先来看下代码运行效果,比较喜欢将
Python的extend插入的字符串 Python pypinyin 汉字转拼音 txt处理