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