PHP 画像透かしクラス、PHP は画像に透かし関数コードを追加します

WBOY
リリース: 2016-07-25 08:51:52
オリジナル
842 人が閲覧しました
  1. /*

  2. * 関数: php 画像透かし (透かしは画像またはテキストをサポートします)
  3. * パラメーター:
  4. * $groundimage 背景画像、つまり、必要な画像一時的に透かしを入れる gif、jpg、png 形式のみをサポートします
  5. * $waterPos 透かしの位置、10 個の状態があります、0 はランダムな位置です
  6. * 1 は左上、2 は上中央、3 は右上です。 4 は左中央、5 は中央中央、6 は右中央を意味します
  7. * 7 は左下を意味します、8 は中央下を意味します、9 は右下を意味します
  8. * $waterImage 画像の透かし、つまり現在透かしとして使用されている画像です。 GIF、JPG、PNG 形式のみをサポートします。
  9. * $waterText テキスト透かし、つまりテキストが透かしとして使用されます。ASCII コードをサポートしますが、中国語はサポートされません。
  10. * $textFont テキスト サイズ、値は 1、2、3 です。 、4 または 5、デフォルトは 5 です ;
  11. * $textColor テキストの色、値は 16 進数の色の値、デフォルトは #FF0000 (赤);
  12. *
  13. * 注: GD 2.0 をサポート、FreeType、GIF 読み取りをサポート、 GIF Create、JPG、PNG
  14. * $ WaterImage と $waterText を同時に使用しないことをお勧めします。どちらかを選択し、最初に $waterImage を使用します。
  15. * $waterImage が有効な場合、パラメータ $waterString、$stringFont、および $stringColor は無効になります。
  16. * 透かし入り画像のファイル名は$groundImageと同じです。
  17. * 著者:longware @ 2004-11-3 14:15:13
  18. */
  19. function imageWaterMark($groundImage,$waterPos=0,$waterImage=””,$waterText=””,$textFont=5,$textColor =”#FF0000″)
  20. {
  21. $isWaterImage = FALSE;
  22. $formatMsg = 「このファイル形式はまだサポートされていません。画像を GIF、JPG、または PNG 形式に変換してください。”;
  23. //ウォーターマークファイルを読み込む
  24. if(!emptyempty($waterImage) && file_exists($waterImage))
  25. {
  26. $water_info = getimagesize($waterImage);
  27. $water_w = $water_info[ 0 ];//ウォーターマーク画像の幅を取得
  28. $water_h = $water_info[1];//ウォーターマーク画像の高さを取得
  29. switch($water_info[2])//ウォーターマーク画像の形式を取得
  30. {
  31. ケース 1:$water_im = imagecreatefromgif($waterImage);break;
  32. case 2:$water_im = imagecreatefromjpeg($waterImage);break;
  33. case 3:$water_im = imagecreatefrompng($waterImage);break; $formatMsg);
  34. }
  35. }
  36. //背景画像を読み込みます
  37. if(!emptyempty($groundImage) && file_exists($groundImage))
  38. {
  39. $ground_info = getimagesize($groundImage);
  40. $ground_w = $ground_info[ 0];// 背景画像の幅を取得
  41. $ground_h = $ground_info[1];// 背景画像の高さを取得
  42. switch($ground_info[2])// 背景画像の形式を取得
  43. {
  44. case 1:$ground_im = imagecreatefromgif($ groundImage);break;
  45. case 2:$ground_im = imagecreatefromjpeg($groundImage);break;
  46. case 3:$ground_im = imagecreatefrompng($groundImage);break; ($formatMsg);
  47. }
  48. }
  49. else
  50. {
  51. die("透かしを入れる必要がある画像が存在しません!")
  52. }
  53. //透かしの位置
  54. if($isWaterImage)//画像の透かし
  55. {
  56. $w = $water_w;
  57. $h = $water_h;
  58. $label = "画像"; }
  59. else//テキスト透かし
  60. {
  61. $temp = imagettfbbox(ceil($textFont*5),0,". /cour.ttf",$waterText);//TrueType フォントを使用してテキストの範囲を取得
  62. $w = $temp[2] - $temp[6];
  63. $h = $temp[3] - $temp[7] ;
  64. unset($temp);
  65. $label = "テキストエリア"; }
  66. if( ($ground_w<$w) || ($ground_h<$h) )
  67. {
  68. echo "ウォーターマークを付ける必要がある画像はウォーターマーク「.$label」より長いです。小さいため、ウォーターマークを生成できません。 ”;
  69. return
  70. }
  71. switch($waterPos)
  72. {
  73. case 0://random
  74. $posX = rand(0,($ground_h); - $h));
  75. break;
  76. case 1://1 は左上を意味します
  77. $posY = 0;
  78. case 2://2 は上中央を意味します
  79. $posX = ($
  80. $posY = 0;
  81. $posY = 0;
  82. $posY = 0; ://4 は中央左を意味します
  83. $posX = 0;
  84. $posY = ($ground_h - $h) / 2;
  85. case 5://5 は中央中央を意味します
  86. $posX = ($ground_w - $w) ) / 2;
  87. $posY = ($ground_h - $h) / 2;
  88. case 6://6 は中央の右です
  89. $posX = $ground_w - $w; $h) / 2;
  90. case 7://7 は左下
  91. $posY = $ground_h - $h;
  92. case 8://8 は下中央
  93. $ posX = ($ground_w - $w) / 2;
  94. $posY = $ground_h - $h;
  95. case 9://9 は右下です
  96. $posX = $ground_w - $w; ground_h - $h;
  97. default://random
  98. $posX = rand(0,($ground_h - $h) ; posY, 0 , 0, $water_w,$water_h);//ウォーターマークを対象ファイルにコピー
  99. }
  100. else//テキストウォーターマーク
  101. {
  102. if( !emptyempty($textColor) && (strlen($textColor)==7) )
  103. {
  104. $R = hexdec(substr($textColor,1,2));
  105. $G = hexdec(substr($textColor,3,2)); }
  106. else
  107. {
  108. die("透かしのテキストの色の形式が正しくありません。”);
  109. }
  110. imagestring ($ground_im, $textFont, $posX, $posY, $waterText, imagecolorallocate($ground_im, $R, $G, $B));
  111. }
  112. // 水印後の写真を生成
  113. @unlink($groundImage);
  114. switch($ground_info[2])// 背景画像取得の格式
  115. {
  116. case 1:imagegif($ground_im,$groundImage);break;
  117. ケース 2:imagejpeg($ground_im,$groundImage);break;
  118. ケース 3:imagepng($ground_im,$groundImage);break;
  119. デフォルト:die($errorMsg);
  120. }
  121. //释放内存在
  122. if(isset($water_info)) unset($water_info);
  123. if(isset($water_im)) imagedestroy($water_im);
  124. unset($ground_info);
  125. imagedestroy($ground_im);
  126. }
  127. //- bbs.it-home.org
  128. $id=$_REQUEST['id'];
  129. $num = count($_FILES['ユーザーファイル']['名前']);
  130. print_r($_FILES['ユーザーファイル']);
  131. print_r($_FILES['ユーザーファイル']['名前']);
  132. $num をエコーし​​ます。
  133. エコー「
    」;
  134. if(isset($id)){
  135. for($i=0;$i<$id;$i++){
  136. if(isset($_FILES) && !emptyempty($_FILES['userfile']) && $ _FILES['userfile']['size']>0)
  137. {
  138. $uploadfile = “./”.time().”_”.$_FILES['userfile'][name][$i];

  139. 」をエコーし​​ます。
  140. $uploadfile をエコー;
  141. if (copy($_FILES['userfile']['tmp_name'][$i], $uploadfile))
  142. {
  143. echo “OK
    ”;
  144. //文字水印
  145. //imageWaterMark($uploadfile,5,”",”HTTP://www.lvye.info”,5,”#cccccc”);
  146. //图片水印
  147. $waterImage=”logo_ok1. gif”;//水印图片路径
  148. imageWaterMark($uploadfile,9,$waterImage);
  149. echo “”;
  150. }
  151. else
  152. {
  153. echo “失敗
    ”;
  154. }
  155. }
  156. }
  157. }
  158. ?>
  159. for($a=0;$a<$id;$a++){
  160. echo “文件:
    ” ;

  161. }

  162. ?>
复制代


ソース:php.cn
このウェブサイトの声明
この記事の内容はネチズンが自主的に寄稿したものであり、著作権は原著者に帰属します。このサイトは、それに相当する法的責任を負いません。盗作または侵害の疑いのあるコンテンツを見つけた場合は、admin@php.cn までご連絡ください。
人気のチュートリアル
詳細>
最新のダウンロード
詳細>
ウェブエフェクト
公式サイト
サイト素材
フロントエンドテンプレート
私たちについて 免責事項 Sitemap
PHP中国語ウェブサイト:福祉オンライン PHP トレーニング,PHP 学習者の迅速な成長を支援します!