1、让水印文字铺满图片:
大致效果:
代码:
$imWidth ? $imWidth : $imHeight; $fintSize = (int)($picRangeLimit / 50); if ($fintSize < 5) { $fintSize = 5; } $textColor = imagecolorallocatealpha($imgRes, 0, 0, 0, 100); $charCount = mb_strlen($markText, 'UTF-8'); $stepLengthX = $fintSize * 4; $stepLengthY = (int)($fintSize * $charCount * 1.2); $numX = (int)($imWidth / $stepLengthX) + 1; $numY = (int)($imHeight / $stepLengthY) + 1; $pointLeft = 0; $pointBottom = $stepLengthY; for ($inY = 0; $inY < $numY; $inY ++) { $pointLeft = 0; for ($inX = 1; $inX < $numX; $inX ++) { imagettftext($imgRes, $fintSize, 45, $pointLeft, $pointBottom, $textColor, $fontFile, $markText); $pointLeft += $stepLengthX; } $pointBottom += $stepLengthY; } header('content-type:' . $mime); $imgrespfunc = 'image' . $ext; $imgrespfunc($imgRes); imagedestroy($imgRes);}$imageDir = "pic.jpg";$markText = "水印内容";appendSpreadTextMark($imageDir, $markText);
2、简单验证码效果:
代码: