/** * 文字水印的效果 * @param int $id * @return string */ function doWaterText($id) { $rows = getProImgsById($id); foreach ($rows as $row) { $filename = "../image_800/" . $row['albumPath']; waterText($filename); } $mes = "操作成功"; return $mes; }
/** * 文字水印的效果 * @param int $id * @return string */ function doWaterText($id) { $rows = getProImgsById($id); if ($rows) { foreach ($rows as $row) { $filename = "../image_800/" . $row['albumPath']; waterText($filename); /* waterText() --image.func.php 文字水印*/ } //$mes="操作成功!"; alertMes("添加文字水印成功!", "listProImages.php"); } else { //$mes="操作失败!"; alertMes("添加文字水印失败!", "listProImages.php"); } return $mes; }
$x = $width - $fontSize * $textLength - 20; $y = $height - 20; } else { $x = 20; $y = $fontSize + 20; } } echo "x=" . $x . ", y=" . $y . "<br>"; // 添加文字水印 imagettftext($image, $fontSize, 0, $x, $y, $color, $fontfile, $text); // 创建存放水印图片的文件夹 if (!file_exists("water")) { mkdir("water", 0777, true); } // 输出水印图片 imagejpeg($image, "water/" . substr($filename, 8)); // 销毁画布资源 imagedestroy($image); $msg = "文字水印添加成功"; return $msg; } // 计算中文字符串长度 function utf8_strlen($string = null) { // 将字符串分解为单元 preg_match_all("/./us", $string, $match); // 返回单元个数 return count($match[0]); } $msg = waterText("uploads/fbb.jpg", "laurel.com", "center"); echo $msg;
<?php $filename = "../images/logo.jpg"; waterText($filename); function waterText($filename, $text = "imooc.com", $fontfile = "MSYH.TTF") { $fileInfo = getimagesize($filename); $mime = $fileInfo['mime']; $createFun = str_replace("/", "createfrom", $mime); $outFun = str_replace("/", null, $mime); $image = $createFun($filename); $color = imagecolorallocatealpha($image, 255, 0, 0, 50); $fontfile = "../fonts/{$fontfile}"; imagettftext($image, 14, 0, 0, 14, $color, $fontfile, $text); header("content-type:" . $mime); $outFun($image, $filename); imagedestroy($image); }