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