免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 1568 | 回复: 1
打印 上一主题 下一主题

php制作缩略图图片 [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2011-12-20 22:42 |只看该作者 |倒序浏览

php制作缩略图图片










Php代码
  1. 1.<?php  
  2. 2.if (! isset ( $_POST ["submit"] )) {  
  3. 3.    echo "<?xml version=\"1.0\" encoding=\"UTF-8\"";  
  4. 4.} else {  
  5. 5.    if (isset ( $_FILES ["file"] ) || $_POST ["file"] != "") {  
  6. 6.        function resizeimage($file, $rate = .5) {  
  7. 7.            $size = getimagesize ( $file );  
  8. 8.            switch ($size [2]) {  
  9. 9.                case 1 :  
  10. 10.                    $img = imagecreatefromgif ( $file );  
  11. 11.                    break;  
  12. 12.                case 2 :  
  13. 13.                    $img = imagecreatefromjpeg ( $file );  
  14. 14.                    break;  
  15. 15.                case 3 :  
  16. 16.                    $img = imagecreatefrompng ( $file );  
  17. 17.                    break;  
  18. 18.            }  
  19. 19.            $srcw = imagesx ( $img );  
  20. 20.            $srch = imagesy ( $img );  
  21. 21.            $detw = floor ( $srcw * $rate );  
  22. 22.            $deth = floor ( $srch * $rate );  
  23. 23.            $im = imagecreatetruecolor ( $detw, $deth );  
  24. 24.            $black = imagecolorallocate ( $im, 255, 255, 255 );  
  25. 25.            imagefilledrectangle ( $im, 0, 0, $detw, $deth, $black );  
  26. 26.            imagecopyresized ( $im, $img, 0, 0, 0, 0, $detw, $deth, $srcw, $srch );  
  27. 27.            header ( 'Content-type:image/png' );  
  28. 28.            imagepng ( $im );  
  29. 29.            imagedestroy ( $im );  
  30. 30.            imagedestroy ( $img );  
  31. 31.        }  
  32. 32.        resizeimage ( $_FILES ["file"] ["tmp_name"] );  
  33. 33.    }  
  34. 34.}  
  35. 35.?>  
  36. 36.  
  37. 37.<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">  
  38. 38.<html xmlns="http://www.w3.org/1999/xhtml">  
  39. 39.<head>  
  40. 40.<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />  
  41. 41.<title>Insert title here</title>  
  42. 42.<style type="text/css">  
  43. 43.td {  
  44. 44.    margin: 0;  
  45. 45.}  
  46. 46.</style>  
  47. 47.<script type="text/javascript">  
  48. 48.function submit(){  
  49. 49.    obj=document.form1.submit();  
  50. 50.    return obj;  
  51. 51.}  
  52. 52.</script>  
  53. 53.</head>  
  54. 54.<body>  
  55. 55.<form name="form1" method="post" enctype="multipart/form-data"  
  56. 56.    action="<?php  
  57. 57.    echo $_SERVER ["PHP_SELF"]?>">  
  58. 58.<table cellpadding="0" cellspacing="0" border="0"  
  59. 59.    bordercolordark="#ffffff" bordercolorlight="#0000ff">  
  60. 60.    <tr>  
  61. 61.        <td><label>FileUpload : </label></td>  
  62. 62.        <td><input type="file" name="file"></input></td>  
  63. 63.        <td><input type="submit" name="submit" value="Submit"></input></td>  
  64. 64.    </tr>  
  65. 65.</table>  
  66. 66.</form>  
  67. 67.</body>  
  68. 68.</html>  
复制代码

论坛徽章:
0
2 [报告]
发表于 2011-12-21 21:53 |只看该作者
学习鸟 谢谢分享
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP