搜尋
首頁後端開發php教程php圖片水印類,php為圖片添加水印函數程式碼

}

?>;
  1. /*

  2. * 功能:php圖片水印(水印支援圖片或文字)
  3. * 參數:
  4. * $groundimage 背景圖片,即需要加浮水印的圖片,暫只支援gif,jpg,png格式;
  5. * $waterPos 水印位置,有10種狀態,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 最好不要同時使用,選其中一個即可,優先使用$waterImage。
  16. * 當$waterImage有效時,參數$waterString、$stringFont、$stringColor皆不生效。
  17. * 加浮水印後的圖片的檔案名稱和 $groundImage 一樣。
  18. * 作者:longware @ 2004-11-3 14:15:13
  19. */
  20. function imageWaterMark($groundImage,$waterPos=0,$waterImage=”",$waterText=”",$waterText=”",$ textFont=5,$textColor=”#FF0000″)
  21. {
  22. $isWaterImage = FALSE;
  23. $formatMsg = 「暫不支援此檔案格式,請用圖片處理軟體將圖片轉換為GIF、JPG 、PNG格式。”;
  24. //讀取水印檔案
  25. if(!emptyempty($waterImage) && file_exists($waterImage))
  26. {
  27. $isWaterImage = TRUE;
  28. $water_info = getsize($water_info 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; case 3:$water_im = imagecreatefrompng($waterImage);break;
  35. default:die($formatMsg);
  36. }
  37. }
  38. //讀取背景圖片
  39. if(!emptyempty( $groundImage) && file_exists($groundImage))
  40. {
  41. $ground_info = getimagesize($groundImage);
  42. $ground_w = $ground_info[0];//取得背景圖片的寬度
  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);;
  50. breakdefault:die($formatMsg); >}
  51. }
  52. else
  53. {
  54. die(”需要浮水印的圖片不存在! ”);
  55. }
  56. //水印位置
  57. if($isWaterImage)//圖片水印
  58. {
  59. $w = $water_w;
  60. $h = $water_h;
  61. $label = “圖片的”;
  62. }
  63. else//文字浮水印
  64. {
  65. $temp = imagettfbbox(ceil($textFont*5),0,”./cour.ttf” ,$waterText);//取得使用TrueType 字型的文字的範圍
  66. $w = $temp[2] - $temp[6];
  67. $h = $temp[3] - $temp[7] ;
  68. unset($temp);
  69. $label = “文字區域”;
  70. }
  71. if( ($ground_w {
  72. echo 「需要加浮水印的圖片的長度或寬度比水印」.$label.」還小,無法產生浮水印! 」;
  73. return;
  74. }
  75. switch($waterPos)
  76. {
  77. case 0://隨機
  78. $posX = rand(0,($ground_w - $w)) ;
  79. $posY = rand(0,($ground_h - $h));
  80. break;
  81. case 1://1為頂端居左
  82. $posX = 0;
  83. $posY = 0;
  84. break;
  85. case 2://2為頂端居中
  86. $posX = ($ground_w - $w) / 2;
  87. $posY = 0;
  88. break;
  89. case 3://3為頂端居右
  90. $posX = $ground_w - $w;
  91. $posY = 0;
  92. break;
  93. case 4://4為中部居左
  94. $posX = 0;
  95. $posY = ($ground_h - $h) / 2;
  96. break;
  97. case 5://5為中部居中
  98. $posX = ($ground_w - $w) / 2;
  99. $posY = ($ground_h - $h) / 2;
  100. break;
  101. case 6://6為中部居右
  102. $posX = $ground_w - $ w;
  103. $posY = ($ground_h - $h) / 2;
  104. break;
  105. case 7://7為底端居左
  106. $posX = 0;
  107. $posY = $ground_h - $h;
  108. break;
  109. case 8://8為底端居中
  110. $posX = ($ground_w - $w) / 2;
  111. $posY = $ground_h - $ h;
  112. break;
  113. case 9://9為底端居右邊
  114. $posX = $ground_w - $w;
  115. $posY = $ground_h - $h;
  116. break;
  117. default://隨機
  118. $posX = rand(0,($ground_w - $w));
  119. $posY = rand(0,($ground_h - $h));
  120. break ;
  121. }
  122. //設定影像的混色模式
  123. imagealphablending($ground_im, true);
  124. if($isWaterImage)//圖片浮水印
  125. {
  126. imagecopy($ground_imagecopy($ground_imagecopy($ground_imagecopy($ground_imagecopy($ground_imagecopy($ground_imagecopy($ground_imagecopy($ground_imagecopy) , $water_im, $posX, $posY, 0, 0, $water_w,$water_h);//拷貝水印到目標檔案
  127. }
  128. else//文字浮水印
  129. {
  130. if( ! emptyempty($textColor) && (strlen($textColor)==7) )
  131. {
  132. $R = hexdec(substr($textColor,1,2));
  133. $G = hexdec(substr( $textColor,3,2));
  134. $B = hexdec(substr($textColor,5));
  135. }
  136. else
  137. {
  138. die(」水印文字顏色格式不正確!」);
  139. }
  140. imagestring ( $ground_im, $textFont, $posX, $posY, $waterText, imagecolorallocate($ground_im, $R, $G, $B));
  141. }
  142. }
  143. }
  144. }
  145. }
  146. }
  147. }
  148. }
  149. }
  150. }
  151. }
  152. //產生浮水印後的圖片
  153. @unlink($groundImage);
  154. switch($ground_info[2])//取得背景圖片的格式
  155. {
  156. case 1:imagegif($ground_im, $groundImage);break;
  157. 案例2:imagejpeg($ground_im,$groundImage);break;
  158. 案例3:imagepng($ground_im,$groundImage);break;
  159. 預設:die($errorMsg) ;
  160. }
  161. //釋放記憶體
  162. if(isset($water_info)) unset($water_info);
  163. if(isset($water_im)) imagedestroy($water_im);
  164. 未設定($ground_info);
  165. imagedestroy($ground_im);
  166. }
  167. //- bbs.it-home.org
  168. $id=$_REQUEST['id'];
  169. $ num = count($_FILES['userfile']['name']);
  170. print_r($_FILES['userfile']);
  171. print_r($_FILES['使用者檔案']['名稱'] );
  172. 回顯$num;
  173. 回顯「
    」;
  174. if(isset($id)){
  175. for($i=0;$iif(isset($_FILES) && !emptyempty($_FILES[' userfile']) && $_FILES['userfile']['size']>0)
  176. {
  177. $uploadfile = “./”.time().”_”.$_FILES['userfile' ][姓名][$i];
  178. 回顯“
    ”;
  179. echo $uploadfile;
  180. if (copy($_FILES['userfile']['tmp_name'][$i], $uploadfile))
  181. {
  182. echo “確定
    ”;
  183. //文字浮水印
  184. //imageWaterMark($uploadfile,5,”",”HTTP://www.lvye.info”,5,”#cccccc“);
  185. //圖片浮水印
  186. $waterImage=”logo_ok1.gif” ;//浮水印圖片路徑
  187. imageWaterMark($uploadfile,9,$waterImage);
  188. echo “php圖片水印類,php為圖片添加水印函數程式碼“;
  189. }
  190. else
  191. {
  192. echo “失敗
    ”;
  193. }
  194. }
  195. }
  196. }
? >
; for($a=0;$a echo “檔案: ;
”;
複製程式碼

陳述
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn
PHP電子郵件:分步發送指南PHP電子郵件:分步發送指南May 09, 2025 am 12:14 AM

phpisusedforsendendemailsduetoitsignegrationwithservermailservicesand andexternalsmtpproviders,自動化intifications andMarketingCampaigns.1)設置設置yourphpenvenvironnvironnvironmentwithaweberswithawebserverserververandphp,確保themailfunctionisenabled.2)useabasicscruct

如何通過PHP發送電子郵件:示例和代碼如何通過PHP發送電子郵件:示例和代碼May 09, 2025 am 12:13 AM

發送電子郵件的最佳方法是使用PHPMailer庫。 1)使用mail()函數簡單但不可靠,可能導致郵件進入垃圾郵件或無法送達。 2)PHPMailer提供更好的控制和可靠性,支持HTML郵件、附件和SMTP認證。 3)確保正確配置SMTP設置並使用加密(如STARTTLS或SSL/TLS)以增強安全性。 4)對於大量郵件,考慮使用郵件隊列系統來優化性能。

高級PHP電子郵件:自定義標題和功能高級PHP電子郵件:自定義標題和功能May 09, 2025 am 12:13 AM

CustomHeadersheadersandAdvancedFeaturesInphpeMailenHanceFunctionalityAndreliability.1)CustomHeadersheadersheadersaddmetadatatatatataatafortrackingandCategorization.2)htmlemailsallowformattingandttinganditive.3)attachmentscanmentscanmentscanbesmentscanbestmentscanbesentscanbesentingslibrarieslibrarieslibrariesliblarikelikephpmailer.4)smtppapapairatienticationaltication enterticationallimpr

使用PHP和SMTP發送電子郵件的指南使用PHP和SMTP發送電子郵件的指南May 09, 2025 am 12:06 AM

使用PHP和SMTP發送郵件可以通過PHPMailer庫實現。 1)安裝並配置PHPMailer,2)設置SMTP服務器細節,3)定義郵件內容,4)發送郵件並處理錯誤。使用此方法可以確保郵件的可靠性和安全性。

使用PHP發送電子郵件的最佳方法是什麼?使用PHP發送電子郵件的最佳方法是什麼?May 08, 2025 am 12:21 AM

ThebestapproachforsendingemailsinPHPisusingthePHPMailerlibraryduetoitsreliability,featurerichness,andeaseofuse.PHPMailersupportsSMTP,providesdetailederrorhandling,allowssendingHTMLandplaintextemails,supportsattachments,andenhancessecurity.Foroptimalu

PHP中依賴注入的最佳實踐PHP中依賴注入的最佳實踐May 08, 2025 am 12:21 AM

使用依賴注入(DI)的原因是它促進了代碼的松耦合、可測試性和可維護性。 1)使用構造函數注入依賴,2)避免使用服務定位器,3)利用依賴注入容器管理依賴,4)通過注入依賴提高測試性,5)避免過度注入依賴,6)考慮DI對性能的影響。

PHP性能調整技巧和技巧PHP性能調整技巧和技巧May 08, 2025 am 12:20 AM

phpperformancetuningiscialbecapeitenhancesspeedandeffice,whatevitalforwebapplications.1)cachingwithapcureduccureducesdatabaseloadprovesrovessetimes.2)優化

PHP電子郵件安全性:發送電子郵件的最佳實踐PHP電子郵件安全性:發送電子郵件的最佳實踐May 08, 2025 am 12:16 AM

ThebestpracticesforsendingemailssecurelyinPHPinclude:1)UsingsecureconfigurationswithSMTPandSTARTTLSencryption,2)Validatingandsanitizinginputstopreventinjectionattacks,3)EncryptingsensitivedatawithinemailsusingOpenSSL,4)Properlyhandlingemailheaderstoa

See all articles

熱AI工具

Undresser.AI Undress

Undresser.AI Undress

人工智慧驅動的應用程序,用於創建逼真的裸體照片

AI Clothes Remover

AI Clothes Remover

用於從照片中去除衣服的線上人工智慧工具。

Undress AI Tool

Undress AI Tool

免費脫衣圖片

Clothoff.io

Clothoff.io

AI脫衣器

Video Face Swap

Video Face Swap

使用我們完全免費的人工智慧換臉工具,輕鬆在任何影片中換臉!

熱工具

EditPlus 中文破解版

EditPlus 中文破解版

體積小,語法高亮,不支援程式碼提示功能

Safe Exam Browser

Safe Exam Browser

Safe Exam Browser是一個安全的瀏覽器環境,安全地進行線上考試。該軟體將任何電腦變成一個安全的工作站。它控制對任何實用工具的訪問,並防止學生使用未經授權的資源。

WebStorm Mac版

WebStorm Mac版

好用的JavaScript開發工具

mPDF

mPDF

mPDF是一個PHP庫,可以從UTF-8編碼的HTML產生PDF檔案。原作者Ian Back編寫mPDF以從他的網站上「即時」輸出PDF文件,並處理不同的語言。與原始腳本如HTML2FPDF相比,它的速度較慢,並且在使用Unicode字體時產生的檔案較大,但支援CSS樣式等,並進行了大量增強。支援幾乎所有語言,包括RTL(阿拉伯語和希伯來語)和CJK(中日韓)。支援嵌套的區塊級元素(如P、DIV),

Dreamweaver CS6

Dreamweaver CS6

視覺化網頁開發工具