PHP平鋪水印

2021-08-09 11:35:55 字數 1157 閱讀 2442

$bigimgpath = "logo.png"; //原圖

$logo = "logo2.png"; //水印

$im = imagecreatefromstring(file_get_contents($bigimgpath));

//獲取水印源

$watermark = imagecreatefromstring(file_get_contents($logo));

//獲取圖、水印 寬高型別

list($bgwidth, $bghight, $bgtype) = getimagesize($bigimgpath);

list($logowidth, $logohight, $logotype) = getimagesize($logo);

//定義平鋪資料

$x_length = $bgwidth - 10; //x軸總長度

$y_length = $bghight - 10; //y軸總長度

//建立透明畫布 偽白色

$opacity=20;

$w = imagesx($watermark);

$h = imagesy($watermark);

$cut = imagecreatetruecolor($w,$h);

$white = imagecolorallocatealpha($cut, 255,255,255,0);

imagefill( $cut, 0, 0, $white );

//整合水印

imagecopy($cut, $watermark, 0, 0, 0, 0, $w, $h);

//迴圈平鋪水印

for ($x = 0; $x < $x_length; $x)

$x += $logowidth;

}header("content-type:image/png");

imagejpeg($im);

die;

示例水印

示例效果圖

php 文字水印

給加文字水印的方法 dst path dst imagecreatefromstring file get contents dst path imagecreatefromstring 從字串中的影象流新建乙個影象,返回乙個影象標示符,其表達了從給定字串得來的影象 影象格式將自動監測,只要php支...

PHP 水印處理

1.開啟伺服器或網路中存在的gif,jpeg,png,wbmp格式影象 imagecreatefromjpeg imagecreatefrompng imagecreatefromgif imagecreatefrombwmp header content type image jpeg color...

PHP 新增水印

require config.inc.php if isset post send cur time date y m d h i s tmp name img tmp name 求出上傳的名稱字尾 ext name strtolower substr name,strrpos name,strle...