テキスト透かしと画像透かしをサポート
透かしのランダムまたは固定位置をサポート (9 マスのグリッド)
透かしの透明度設定 (画像とテキストの透かしの両方をサポート)
テキスト透かしのフォント、色、サイズの設定
画像 ウォーターマークの背景は透明です
コードをコピーします コードは次のとおりです:
/**
* 透かしクラスを追加し、テキストと画像の透かしの透明度設定、透かし画像の透明な背景をサポートします。
* 日付: 2011-09-27
* 著者: www.jb51.net
* 使用法:
* $obj = new WaterMask($imgFileName) //オブジェクトをインスタンス化します
* $obj->$waterType = 1; //タイプ: 0 はテキストの透かし、1 は画像の透かし
* $obj->$transparent = 45; //透かしの透明度
* $obj-> ; $waterStr = 'www.jb51.net'; //ウォーターマークのテキスト
* $obj->$fontSize = 16; //テキストのフォントサイズ
* $obj->$fontColor = array(255 , 0255); //ウォーターマークのテキストの色 (RGB)
* $obj->$fontFile = = 'AHGBold.ttf'; // フォント ファイル
* $obj->output();出力ウォーターマーク画像ファイルは入力画像ファイルに上書きされます
*/
class WaterMask{
public $waterType = 1; //ウォーターマークのタイプ: 0 はテキストのウォーターマーク、1 は画像のウォーターマーク
public $pos = 0; //ウォーターマークの位置
public $transparent = 45; //ウォーターマークの透明度
public $waterStr = 'www.jb51.net'; >public $fontSize = 16; //テキストのフォント サイズ
public $fontColor = array(255,0,255); //ウォーターマークのテキストの色 (RGB)
public $fontFile = 'AHGBold.ttf'; File
public $waterImg = 'logo.png'; //透かし画像
private $srcImg = '' //透かしを入れる必要がある画像
private $im = '; ' ; //画像ハンドル
private $water_im = '' //ウォーターマーク画像ハンドル
private $srcImg_info = '';
private $str_w = ''; //ウォーターマークのテキストの幅
private $str_h = ''; //ウォーターマークのテキストの高さ
private $x = ''; //ウォーターマークのX座標
y = ''; //ウォーターマーク y 座標
function __construct($img) { //デストラクター
$this->srcImg = file_exists($img) ? .$img.'" ソース ファイルが存在しません!');
}
private function imginfo() { //透かしを入れる必要がある画像の情報を取得し、画像を読み込みます。
$this->srcImg_info = getimagesize($this->srcImg);
switch ($this->srcImg_info[2]) {
ケース 3:
$this-> im = imagecreatefrompng($this->srcImg);
break 1;
ケース 2:
$this->im = imagecreatefromjpeg($this->srcImg);
ケース 1:
$this->im = imagecreatefromgif($this->srcImg);
デフォルト:
die('元の画像('.$this) ->srcImg.') 形式が正しくありません。PNG、JPEG、GIF のみをサポートします ');
}
}
private function Waterimginfo() { //ウォーターマーク画像情報を取得し、画像を読み込みます。 。
$this->waterImg_info = getimagesize($this->waterImg);
switch ($this->waterImg_info[2]) {
ケース 3:
$this-> Water_im = imagecreatefrompng($this->waterImg);
break 1;
ケース 2:
$this->water_im = imagecreatefromjpeg($this->waterImg);
ケース 1:
$this->water_im = imagecreatefromgif($this->waterImg);
break 1;
デフォルト:
die('watermark image('.$this) ->srcImg.') 形式が間違っており、PNG、JPEG、GIF のみをサポートしています。');
}
}
private function Waterpos() { //水印位置算法
switch ($this->pos) {
case 0: //随机位置
$this ->x = rand(0,$this->srcImg_info[0]-$this->waterImg_info[0]);
$this->y = rand(0,$this->srcImg_info[1]-$this->waterImg_info[1]);
休憩 1;
ケース 1: //上左
$this->x = 0;
$this->y = 0;
休憩 1;
ケース 2: // 上中 $this->x = ($this->srcImg_info[0]-$this->waterImg_info[0])/2;
$this->y = 0;
休憩 1;
ケース 3: //上右
$this->x = $this->srcImg_info[0]-$this->waterImg_info[0];
$this->y = 0;
休憩 1;
ケース 4: //中左
$this->x = 0;
$this->y = ($this->srcImg_info[1]-$this->waterImg_info[1])/2;
休憩 1;
ケース 5: //中中
$this->x = ($this->srcImg_info[0]-$this->waterImg_info[0])/2;
$this->y = ($this->srcImg_info[1]-$this->waterImg_info[1])/2;
休憩 1;
ケース 6: //中右
$this->x = $this->srcImg_info[0]-$this->waterImg_info[0];
$this->y = ($this->srcImg_info[1]-$this->waterImg_info[1])/2;
休憩 1;
ケース 7: //下左
$this->x = 0;
$this->y = $this->srcImg_info[1]-$this->waterImg_info[1];
休憩 1;
ケース 8: //下中
$this->x = ($this->srcImg_info[0]-$this->waterImg_info[0])/2;
$this->y = $this->srcImg_info[1]-$this->waterImg_info[1];
休憩 1;
デフォルト: //下右
$this->x = $this->srcImg_info[0]-$this->waterImg_info[0];
$this->y = $this->srcImg_info[1]-$this->waterImg_info[1];
休憩 1;
}
}
プライベート関数 Waterimg() {
if ($this->srcImg_info[0] gt;waterImg_info[0] || $this-> srcImg_info[1] waterImg_info[1]){
die('水印比原图大!');
}
$this->waterpos();
$cut = imagecreatetruecolor($this->waterImg_info[0],$this->waterImg_info[1]);
imagecopy($cut,$this->im,0,0,$this->x,$this->y,$this->waterImg_info[0],$this->waterImg_info[ 1]);
$pct = $this->透明;
imagecopy($cut,$this->water_im,0,0,0,0,$this->waterImg_info[0],$this->waterImg_info[1]);
imagecopymerge($this->im,$cut,$this->x,$this->y,0,0,$this->waterImg_info[0],$this->waterImg_info[ 1],$pct);
}
プライベート関数 Waterstr() {
$rect = imagettfbbox($this->fontSize,0,$this->fontFile,$this->waterStr);
$w = abs($rect[2]-$rect[6]);
$h = abs($rect[3]-$rect[7]);
$fontHeight = $this->fontSize;
$this->water_im = imagecreatetruecolor($w, $h);
imagealphablending($this->water_im,false);
imagesavealpha($this->water_im,true);
$white_alpha = imagecolorallocatealpha($this->water_im,255,255,255,127);
imagefill($this->water_im,0,0,$white_alpha);
$color = imagecolorallocate($this->water_im,$this->fontColor[0],$this->fontColor[1],$this->fontColor[2]);
imagettftext($this->water_im,$this->fontSize,0,0,$this->fontSize,$color,$this->fontFile,$this->waterStr);
$this->waterImg_info = array(0=>$w,1=>$h);
$this->waterimg();
}
関数出力() {
$this->imginfo();
if ($this->waterType == 0) {
$this->waterstr();
}else {
$this->waterimginfo();
$this->waterimg();
}
switch ($this->srcImg_info[2]) {
ケース 3:
imagepng($this->im,$this->srcImg);
休憩 1;
ケース 2:
imagejpeg($this->im,$this->srcImg);
休憩 1;
ケース 1:
imagegif($this->im,$this->srcImg);
休憩 1;
デフォルト:
die('追加水印失败!');
休憩;
}
imagedestroy($this->im);
imagedestroy($this->water_im);
}
}
?>

ホットAIツール

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

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

Undress AI Tool
脱衣画像を無料で

Clothoff.io
AI衣類リムーバー

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

人気の記事

ホットツール

SAP NetWeaver Server Adapter for Eclipse
Eclipse を SAP NetWeaver アプリケーション サーバーと統合します。

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

SecLists
SecLists は、セキュリティ テスターの究極の相棒です。これは、セキュリティ評価中に頻繁に使用されるさまざまな種類のリストを 1 か所にまとめたものです。 SecLists は、セキュリティ テスターが必要とする可能性のあるすべてのリストを便利に提供することで、セキュリティ テストをより効率的かつ生産的にするのに役立ちます。リストの種類には、ユーザー名、パスワード、URL、ファジング ペイロード、機密データ パターン、Web シェルなどが含まれます。テスターはこのリポジトリを新しいテスト マシンにプルするだけで、必要なあらゆる種類のリストにアクセスできるようになります。

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

Safe Exam Browser
Safe Exam Browser は、オンライン試験を安全に受験するための安全なブラウザ環境です。このソフトウェアは、あらゆるコンピュータを安全なワークステーションに変えます。あらゆるユーティリティへのアクセスを制御し、学生が無許可のリソースを使用するのを防ぎます。
