免费注册 查看新帖 |

Chinaunix

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

php给图片添加水印 [复制链接]

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

php给图片添加水印










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

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

本版积分规则 发表回复

  

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

清除 Cookies - ChinaUnix - Archiver - WAP - TOP