国产av日韩一区二区三区精品,成人性爱视频在线观看,国产,欧美,日韩,一区,www.成色av久久成人,2222eeee成人天堂

首頁 后端開發(fā) php教程 php圖片水印類,php為圖片添加水印函數(shù)代碼

php圖片水印類,php為圖片添加水印函數(shù)代碼

Jul 25, 2016 am 08:51 AM

  1. /*

  2. * 功能:php圖片水印 (水印支持圖片或文字)
  3. * 參數(shù):
  4. * $groundimage 背景圖片,即需要加水印的圖片,暫只支持gif,jpg,png格式;
  5. * $waterPos 水印位置,有10種狀態(tài),0為隨機位置;
  6. * 1為頂端居左,2為頂端居中,3為頂端居右;
  7. * 4為中部居左,5為中部居中,6為中部居右;
  8. * 7為底端居左,8為底端居中,9為底端居右;
  9. * $waterImage 圖片水印,即作為水印的圖片,暫只支持GIF,JPG,PNG格式;
  10. * $waterText 文字水印,即把文字作為為水印,支持ASCII碼,不支持中文;
  11. * $textFont 文字大小,值為1、2、3、4或5,默認為5;
  12. * $textColor 文字顏色,值為十六進制顏色值,默認為#FF0000(紅色);
  13. *
  14. * 注意:Support GD 2.0,Support FreeType、GIF Read、GIF Create、JPG 、PNG
  15. * $waterImage 和 $waterText 最好不要同時使用,選其中之一即可,優(yōu)先使用 $waterImage。
  16. * 當$waterImage有效時,參數(shù)$waterString、$stringFont、$stringColor均不生效。
  17. * 加水印后的圖片的文件名和 $groundImage 一樣。
  18. * 作者:longware @ 2004-11-3 14:15:13
  19. */
  20. function imageWaterMark($groundImage,$waterPos=0,$waterImage=”",$waterText=”",$textFont=5,$textColor=”#FF0000″)
  21. {
  22. $isWaterImage = FALSE;
  23. $formatMsg = “暫不支持該文件格式,請用圖片處理軟件將圖片轉(zhuǎn)換為GIF、JPG、PNG格式?!?
  24. //讀取水印文件
  25. if(!emptyempty($waterImage) && file_exists($waterImage))
  26. {
  27. $isWaterImage = TRUE;
  28. $water_info = getimagesize($waterImage);
  29. $water_w = $water_info[0];//取得水印圖片的寬
  30. $water_h = $water_info[1];//取得水印圖片的高
  31. switch($water_info[2])//取得水印圖片的格式
  32. {
  33. case 1:$water_im = imagecreatefromgif($waterImage);break;
  34. case 2:$water_im = imagecreatefromjpeg($waterImage);break;
  35. case 3:$water_im = imagecreatefrompng($waterImage);break;
  36. default:die($formatMsg);
  37. }
  38. }
  39. //讀取背景圖片
  40. if(!emptyempty($groundImage) && file_exists($groundImage))
  41. {
  42. $ground_info = getimagesize($groundImage);
  43. $ground_w = $ground_info[0];//取得背景圖片的寬
  44. $ground_h = $ground_info[1];//取得背景圖片的高
  45. switch($ground_info[2])//取得背景圖片的格式
  46. {
  47. case 1:$ground_im = imagecreatefromgif($groundImage);break;
  48. case 2:$ground_im = imagecreatefromjpeg($groundImage);break;
  49. case 3:$ground_im = imagecreatefrompng($groundImage);break;
  50. default:die($formatMsg);
  51. }
  52. }
  53. else
  54. {
  55. die(”需要加水印的圖片不存在!”);
  56. }
  57. //水印位置
  58. if($isWaterImage)//圖片水印
  59. {
  60. $w = $water_w;
  61. $h = $water_h;
  62. $label = “圖片的”;
  63. }
  64. else//文字水印
  65. {
  66. $temp = imagettfbbox(ceil($textFont*5),0,”./cour.ttf”,$waterText);//取得使用 TrueType 字體的文本的范圍
  67. $w = $temp[2] - $temp[6];
  68. $h = $temp[3] - $temp[7];
  69. unset($temp);
  70. $label = “文字區(qū)域”;
  71. }
  72. if( ($ground_w {
  73. echo “需要加水印的圖片的長度或?qū)挾缺人 ?$label.”還小,無法生成水?。 ?
  74. return;
  75. }
  76. switch($waterPos)
  77. {
  78. case 0://隨機
  79. $posX = rand(0,($ground_w - $w));
  80. $posY = rand(0,($ground_h - $h));
  81. break;
  82. case 1://1為頂端居左
  83. $posX = 0;
  84. $posY = 0;
  85. break;
  86. case 2://2為頂端居中
  87. $posX = ($ground_w - $w) / 2;
  88. $posY = 0;
  89. break;
  90. case 3://3為頂端居右
  91. $posX = $ground_w - $w;
  92. $posY = 0;
  93. break;
  94. case 4://4為中部居左
  95. $posX = 0;
  96. $posY = ($ground_h - $h) / 2;
  97. break;
  98. case 5://5為中部居中
  99. $posX = ($ground_w - $w) / 2;
  100. $posY = ($ground_h - $h) / 2;
  101. break;
  102. case 6://6為中部居右
  103. $posX = $ground_w - $w;
  104. $posY = ($ground_h - $h) / 2;
  105. break;
  106. case 7://7為底端居左
  107. $posX = 0;
  108. $posY = $ground_h - $h;
  109. break;
  110. case 8://8為底端居中
  111. $posX = ($ground_w - $w) / 2;
  112. $posY = $ground_h - $h;
  113. break;
  114. case 9://9為底端居右
  115. $posX = $ground_w - $w;
  116. $posY = $ground_h - $h;
  117. break;
  118. default://隨機
  119. $posX = rand(0,($ground_w - $w));
  120. $posY = rand(0,($ground_h - $h));
  121. break;
  122. }
  123. //設(shè)定圖像的混色模式
  124. imagealphablending($ground_im, true);
  125. if($isWaterImage)//圖片水印
  126. {
  127. imagecopy($ground_im, $water_im, $posX, $posY, 0, 0, $water_w,$water_h);//拷貝水印到目標文件
  128. }
  129. else//文字水印
  130. {
  131. if( !emptyempty($textColor) && (strlen($textColor)==7) )
  132. {
  133. $R = hexdec(substr($textColor,1,2));
  134. $G = hexdec(substr($textColor,3,2));
  135. $B = hexdec(substr($textColor,5));
  136. }
  137. else
  138. {
  139. die(”水印文字顏色格式不正確!”);
  140. }
  141. imagestring ( $ground_im, $textFont, $posX, $posY, $waterText, imagecolorallocate($ground_im, $R, $G, $B));
  142. }
  143. //生成水印后的圖片
  144. @unlink($groundImage);
  145. switch($ground_info[2])//取得背景圖片的格式
  146. {
  147. case 1:imagegif($ground_im,$groundImage);break;
  148. case 2:imagejpeg($ground_im,$groundImage);break;
  149. case 3:imagepng($ground_im,$groundImage);break;
  150. default:die($errorMsg);
  151. }
  152. //釋放內(nèi)存
  153. if(isset($water_info)) unset($water_info);
  154. if(isset($water_im)) imagedestroy($water_im);
  155. unset($ground_info);
  156. imagedestroy($ground_im);
  157. }
  158. //- bbs.it-home.org
  159. $id=$_REQUEST['id'];
  160. $num = count($_FILES['userfile']['name']);
  161. print_r($_FILES['userfile']);
  162. print_r($_FILES['userfile']['name']);
  163. echo $num;
  164. echo “
    ”;
  165. if(isset($id)){
  166. for($i=0;$iif(isset($_FILES) && !emptyempty($_FILES['userfile']) && $_FILES['userfile']['size']>0)
  167. {
  168. $uploadfile = “./”.time().”_”.$_FILES['userfile'][name][$i];
  169. echo “
    ”;
  170. echo $uploadfile;
  171. if (copy($_FILES['userfile']['tmp_name'][$i], $uploadfile))
  172. {
  173. echo “OK
    ”;
  174. //文字水印
  175. //imageWaterMark($uploadfile,5,”",”HTTP://www.lvye.info”,5,”#cccccc“);
  176. //圖片水印
  177. $waterImage=”logo_ok1.gif”;//水印圖片路徑
  178. imageWaterMark($uploadfile,9,$waterImage);
  179. echo “php圖片水印類,php為圖片添加水印函數(shù)代碼 ”;
  180. }
  181. else
  182. {
  183. echo “Fail
    ”;
  184. }
  185. }
  186. }
  187. }
  188. ?>
  189. for($a=0;$a echo “文件:
    ”;
  190. }

  191. ?>
復(fù)制代碼


本站聲明
本文內(nèi)容由網(wǎng)友自發(fā)貢獻,版權(quán)歸原作者所有,本站不承擔相應(yīng)法律責任。如您發(fā)現(xiàn)有涉嫌抄襲侵權(quán)的內(nèi)容,請聯(lián)系admin@php.cn

熱AI工具

Undress AI Tool

Undress AI Tool

免費脫衣服圖片

Undresser.AI Undress

Undresser.AI Undress

人工智能驅(qū)動的應(yīng)用程序,用于創(chuàng)建逼真的裸體照片

AI Clothes Remover

AI Clothes Remover

用于從照片中去除衣服的在線人工智能工具。

Clothoff.io

Clothoff.io

AI脫衣機

Video Face Swap

Video Face Swap

使用我們完全免費的人工智能換臉工具輕松在任何視頻中換臉!

熱工具

記事本++7.3.1

記事本++7.3.1

好用且免費的代碼編輯器

SublimeText3漢化版

SublimeText3漢化版

中文版,非常好用

禪工作室 13.0.1

禪工作室 13.0.1

功能強大的PHP集成開發(fā)環(huán)境

Dreamweaver CS6

Dreamweaver CS6

視覺化網(wǎng)頁開發(fā)工具

SublimeText3 Mac版

SublimeText3 Mac版

神級代碼編輯軟件(SublimeText3)

如何在PHP中實施身份驗證和授權(quán)? 如何在PHP中實施身份驗證和授權(quán)? Jun 20, 2025 am 01:03 AM

tosecurelyhandleauthenticationandationallizationInphp,lofterTheSesteps:1.AlwaysHashPasswordSwithPassword_hash()andverifyusingspasspassword_verify(),usepreparedStatatementStopreventsqlineptions,andStoreSeruserDatain usseruserDatain $ _sessiveferterlogin.2.implementrole-2.imaccessccsccccccccccccccccccccccccc.

如何在PHP中安全地處理文件上傳? 如何在PHP中安全地處理文件上傳? Jun 19, 2025 am 01:05 AM

要安全處理PHP中的文件上傳,核心在于驗證文件類型、重命名文件并限制權(quán)限。1.使用finfo_file()檢查真實MIME類型,僅允許特定類型如image/jpeg;2.用uniqid()生成隨機文件名,存儲至非Web根目錄;3.通過php.ini和HTML表單限制文件大小,設(shè)置目錄權(quán)限為0755;4.使用ClamAV掃描惡意軟件,增強安全性。這些步驟有效防止安全漏洞,確保文件上傳過程安全可靠。

PHP中==(松散比較)和===(嚴格的比較)之間有什么區(qū)別? PHP中==(松散比較)和===(嚴格的比較)之間有什么區(qū)別? Jun 19, 2025 am 01:07 AM

在PHP中,==與===的主要區(qū)別在于類型檢查的嚴格程度。==在比較前會進行類型轉(zhuǎn)換,例如5=="5"返回true,而===要求值和類型都相同才會返回true,例如5==="5"返回false。使用場景上,===更安全應(yīng)優(yōu)先使用,==僅在需要類型轉(zhuǎn)換時使用。

如何在PHP( - , *, /,%)中執(zhí)行算術(shù)操作? 如何在PHP( - , *, /,%)中執(zhí)行算術(shù)操作? Jun 19, 2025 pm 05:13 PM

PHP中使用基本數(shù)學運算的方法如下:1.加法用 號,支持整數(shù)和浮點數(shù),也可用于變量,字符串數(shù)字會自動轉(zhuǎn)換但不推薦依賴;2.減法用-號,變量同理,類型轉(zhuǎn)換同樣適用;3.乘法用*號,適用于數(shù)字及類似字符串;4.除法用/號,需避免除以零,并注意結(jié)果可能是浮點數(shù);5.取模用%號,可用于判斷奇偶數(shù),處理負數(shù)時余數(shù)符號與被除數(shù)一致。正確使用這些運算符的關(guān)鍵在于確保數(shù)據(jù)類型清晰并處理好邊界情況。

如何與PHP的NOSQL數(shù)據(jù)庫(例如MongoDB,Redis)進行交互? 如何與PHP的NOSQL數(shù)據(jù)庫(例如MongoDB,Redis)進行交互? Jun 19, 2025 am 01:07 AM

是的,PHP可以通過特定擴展或庫與MongoDB和Redis等NoSQL數(shù)據(jù)庫交互。首先,使用MongoDBPHP驅(qū)動(通過PECL或Composer安裝)創(chuàng)建客戶端實例并操作數(shù)據(jù)庫及集合,支持插入、查詢、聚合等操作;其次,使用Predis庫或phpredis擴展連接Redis,執(zhí)行鍵值設(shè)置與獲取,推薦phpredis用于高性能場景,Predis則便于快速部署;兩者均適用于生產(chǎn)環(huán)境且文檔完善。

我如何了解最新的PHP開發(fā)和最佳實踐? 我如何了解最新的PHP開發(fā)和最佳實踐? Jun 23, 2025 am 12:56 AM

TostaycurrentwithPHPdevelopmentsandbestpractices,followkeynewssourceslikePHP.netandPHPWeekly,engagewithcommunitiesonforumsandconferences,keeptoolingupdatedandgraduallyadoptnewfeatures,andreadorcontributetoopensourceprojects.First,followreliablesource

什么是PHP,為什么它用于Web開發(fā)? 什么是PHP,為什么它用于Web開發(fā)? Jun 23, 2025 am 12:55 AM

PHPbecamepopularforwebdevelopmentduetoitseaseoflearning,seamlessintegrationwithHTML,widespreadhostingsupport,andalargeecosystemincludingframeworkslikeLaravelandCMSplatformslikeWordPress.Itexcelsinhandlingformsubmissions,managingusersessions,interacti

如何設(shè)置PHP時區(qū)? 如何設(shè)置PHP時區(qū)? Jun 25, 2025 am 01:00 AM

tosetTherightTimeZoneInphp,restate_default_timezone_set()functionAtthestArtofyourscriptWithavalIdidentIdentifiersuchas'america/new_york'.1.usedate_default_default_timezone_set_set()

See all articles