PHP は画像透かしとテキスト透かしコードを追加します PHP は、テキストと画像の透かしの透明度設定と透かし画像の透明な背景をサポートする透かしコードを追加します。私が開発した CMS セットで使用する必要があるため、インターネット上の人々は常にこのクラスの使用方法を気に入っていただけると幸いです。
001
002クラスウォーターマスク{
003 public $waterType = 1; //ウォーターマークの種類: 0はテキストウォーターマーク、1は画像ウォーターマーク
004 public $pos = 0 //ウォーターマークの位置
;005 public $transparent = 45 //透かしの透明度
;006 public $waterStr = 'www.codefans.net' //ウォーターマークテキスト
;007 public $fontSize = 16; //テキストのフォントサイズ
;008 public $fontColor = array(255,0,255) //透かしの文字色(RGB)
;009 public $fontFile = 'AHGBold.ttf';//フォントファイル
010 public $waterImg = 'logo.png';//ウォーターマーク画像
011 private $srcImg = '';//透かしを入れる必要がある画像
012 private $im = '';//画像ハンドル
013 private $water_im = '';//ウォーターマーク画像ハンドル
014 private $srcImg_info = '';//画像情報
015 private $waterImg_info = '';//ウォーターマーク画像情報
016 private $str_w = '';//透かしの文字幅
017 private $str_h = '' //ウォーターマークの文字の高さ
;018 private $x = '';//ウォーターマークX座標
019 private $y = '';//ウォーターマークy座標
020 function __construct($img) {
021 $this->srcImg = file_exists($img) $img : die('"'.$img.'" 申し訳ありませんが、ウォーターマーク ファイルは存在しません!');
022 }
023 private function imginfo() {//ウォーターマーク画像情報を取得して読み込みます。
024 $this->srcImg_info = getimagesize($this->srcImg);
025 switch ($this->srcImg_info[2]) {
026 ケース3:
027 $this->im = imagecreatefrompng($this->srcImg);
028休憩1;
029 ケース2:
030 $this->im = imagecreatefromjpeg($this->srcImg);
031休憩1;
032 ケース1:
033 $this->im = imagecreatefromgif($this->srcImg);
034休憩1;
035デフォルト:
036 die('ウォーターマーク画像('.$this->srcImg.') ウォーターマーク画像の形式が正しくありません。PNG、JPEG、またはGIF形式の画像を選択してください。');
037 }
038 }
039 private function Waterimginfo() {//ウォーターマーク画像を取得して読み込みます。
040 $this->waterImg_info = getimagesize($this->waterImg);
041 switch ($this->waterImg_info[2]) {
042 ケース3:
043 $this->water_im = imagecreatefrompng($this->waterImg);
044休憩1;
045 ケース2:
046 $this->water_im = imagecreatefromjpeg($this->waterImg);
047休憩1;
048 ケース1:
049 $this->water_im = imagecreatefromgif($this->waterImg);
050休憩1;
051デフォルト:
052 die('ウォーターマーク画像('.$this->srcImg.')の形式が正しくありません。PNG、JPEG、GIFのみがサポートされています。');
053 }
054 }
055 private function Waterpos() {//ウォーターマーク位置アルゴリズム
056 switch ($this->pos) {
057 case 0: //ランダムな場所
058 $this->x = rand(0,$this->srcImg_info[0]-$this->waterImg_info[0]);
059 $this->y = rand(0,$this->srcImg_info[1]-$this->waterImg_info[1]);
060休憩1;
061 case 1: //左上
062 $this->x = 0;
063 $this->y = 0;
064休憩1;
065 case 2: //上中
066 $this->x = ($this->srcImg_info[0]-$this->waterImg_info[0])/2;
067 $this->y = 0;
068休憩1;
069 case 3: //右上
070 $this->x = $this->srcImg_info[0]-$this->waterImg_info[0];
071 $this->y = 0;
072休憩1;
073 case 4: //中央左
074 $this->x = 0;
075 $this->y = ($this->srcImg_info[1]-$this->waterImg_info[1])/2;
076休憩1;
077 case 5: //中中
078 $this->x = ($this->srcImg_info[0]-$this->waterImg_info[0])/2;
079 $this->y = ($this->srcImg_info[1]-$this->waterImg_info[1])/2;
080休憩1;
081 case 6: //中央右
082 $this->x = $this->srcImg_info[0]-$this->waterImg_info[0];
083 $this->y = ($this->srcImg_info[1]-$this->waterImg_info[1])/2;
084休憩1;
085 case 7: //左下
086 $this->x = 0;
087 $this->y = $this->srcImg_info[1]-$this->waterImg_info[1];
088休憩1;
089 case 8: //下中
090 $this->x = ($this->srcImg_info[0]-$this->waterImg_info[0])/2;
091 $this->y = $this->srcImg_info[1]-$this->waterImg_info[1];
092休憩1;
093 デフォルト: //下右
094 $this->x = $this->srcImg_info[0]-$this->waterImg_info[0];
095 $this->y = $this->srcImg_info[1]-$this->waterImg_info[1];
096休憩1;
097 }
098 }
099 private function Waterimg() {
100 if ($this->srcImg_info[0] waterImg_info[0] || $this->srcImg_info[1] waterImg_info[1]){
101 die('水印比原图大!');
102 }
103 $this->waterpos();
104 $cut = imagecreatetruecolor($this->waterImg_info[0],$this->waterImg_info[1]);
105 imagecopy($cut,$this->im,0,0,$this->x,$this->y,$this->waterImg_info[0],$this->waterImg_info[1 ]);
106 $pct = $this->transparent;
107 imagecopy($cut,$this->water_im,0,0,0,0,$this->waterImg_info[0],$this->waterImg_info[1]);
108 imagecopymerge($this->im,$cut,$this->x,$this->y,0,0,$this->waterImg_info[0],$this->waterImg_info[1 ],$pct);
109 }
110プライベート関数waterstr(){
111 $rect = imagettfbbox($this->fontSize,0,$this->fontFile,$this->waterStr);
112 $w = abs($rect[2]-$rect[6]);
113 $h = abs($rect[3]-$rect[7]);
114 $fontHeight = $this->fontSize;
115 $this->water_im = imagecreatetruecolor($w, $h);
116 imagealphablending($this->water_im,false);
117 枚の画像avealpha($this->water_im,true);
118 $white_alpha = imagecolorallocatealpha($this->water_im,255,255,255,127);
119 imagefill($this->water_im,0,0,$white_alpha);
120 $color = imagecolorallocate($this->water_im,$this->fontColor[0],$this->fontColor[1],$this->fontColor[2]);
121 imagettftext($this->water_im,$this->fontSize,0,0,$this->fontSize,$color,$this->fontFile,$this->waterStr);
122 $this->waterImg_info = array(0=>$w,1=>$h);
123 $this->waterimg();
124 }
125関数output() {
126 $this->imginfo();
127 if ($this->waterType == 0) {
128 $this->waterstr();
129 }else {
130 $this->waterimginfo();
131 $this->waterimg();
132 }
133 switch ($this->srcImg_info[2]) {
134 事例3:
135 imagepng($this->im,$this->srcImg);
136休憩1;
137 事例2:
138 imagejpeg($this->im,$this->srcImg);
139休憩1;
140件1:
141 imagegif($this->im,$this->srcImg);
142休憩1;
143 デフォルト:
144 die('原因不明:水印添加失败!');
145休憩;
146 }
147 imagedestroy($this->im);
148 imagedestroy($this->water_im);
149 }
150}
151?>
PHP生成水印类用法:
ソースプリントを表示?01
02$obj = new WaterMask($imgFileName);
03$obj->$waterType = 1;//水印種類:0は文字水印、1は絵片水印
04$obj->$transparent = 45;//水印透明度
05$obj->$waterStr = 'www.codefans.net';//水印文字
06$obj->$fontSize = 16;//文字大小
07$obj->$fontColor = array(255,0,255);//水印文字颜色(RGB值)
08$obj->$fontFile = = 'AHGBold.ttf'; //文字名
09$obj->output(); //出水印图片
10?>

thesecrettokeepingaphp-poweredwebsterunningsmootlyunderheavyloadinvolvesseveralkeystrategies:1)emform opcodecoduceSciptionexecutiontime、2)aatabasequerycachingwithiThing withiThistolessendavasoload、

コードをより明確かつ維持しやすくするため、依存関係が関心(DI)に注意する必要があります。 1)DIは、クラスを切り離すことにより、よりモジュール化されます。2)テストとコードの柔軟性の利便性を向上させ、3)DIコンテナを使用して複雑な依存関係を管理しますが、パフォーマンスの影響と円形の依存関係に注意してください。

はい、最適化されたAphPossibleandessention.1)CachingingusapCutoredatedAtabaseload.2)最適化、効率的なQueries、およびConnectionPooling.3)EnhcodeCodewithBultinctions、Avoididingglobalbariables、およびUsingopcodeching

keyStrategIestsoSificlyvoostphpappliceperformanceare:1)useopcodecachinglikeToreexecutiontime、2)最適化abaseの相互作用とプロペラインデックス、3)3)構成

aphpDependencyInjectionContaineriSATOULTAINATINAGECLASSDEPTINCIES、強化測定性、テスト可能性、および維持可能性。

SELECT DEPENTENCINGINOFCENT(DI)大規模なアプリケーションの場合、ServicElocatorは小さなプロジェクトまたはプロトタイプに適しています。 1)DIは、コンストラクターインジェクションを通じてコードのテスト可能性とモジュール性を改善します。 2)ServiceLocatorは、センター登録を通じてサービスを取得します。これは便利ですが、コードカップリングの増加につながる可能性があります。

phpapplicationscanbeoptimizedforspeedandEfficiencyby:1)enabingopcacheinphp.ini、2)PreparedStatementswithpordatabasequeriesを使用して、3)LoopswithArray_filterandarray_mapfordataprocessing、4)の構成ngincasaSearverseproxy、5)

PHPemailvalidationinvolvesthreesteps:1)Formatvalidationusingregularexpressionstochecktheemailformat;2)DNSvalidationtoensurethedomainhasavalidMXrecord;3)SMTPvalidation,themostthoroughmethod,whichchecksifthemailboxexistsbyconnectingtotheSMTPserver.Impl


ホットAIツール

Undresser.AI Undress
リアルなヌード写真を作成する AI 搭載アプリ

AI Clothes Remover
写真から衣服を削除するオンライン AI ツール。

Undress AI Tool
脱衣画像を無料で

Clothoff.io
AI衣類リムーバー

Video Face Swap
完全無料の AI 顔交換ツールを使用して、あらゆるビデオの顔を簡単に交換できます。

人気の記事

ホットツール

ZendStudio 13.5.1 Mac
強力な PHP 統合開発環境

メモ帳++7.3.1
使いやすく無料のコードエディター

VSCode Windows 64 ビットのダウンロード
Microsoft によって発売された無料で強力な IDE エディター

SublimeText3 Linux 新バージョン
SublimeText3 Linux 最新バージョン

SublimeText3 英語版
推奨: Win バージョン、コードプロンプトをサポート!
