<?php
function attach_text_logo($imgFilePath, $textLogo) {
$hh = 16;
if(mb_strlen($textLogo,'utf-8')>$hh){
$newtextLogo = mb_substr($textLogo,0,$hh,'utf-8') . "\n" . mb_substr($textLogo,$hh,$hh,'utf-8');
}else{
$newtextLogo = $textLogo;
}
//创建图片的实例
$im = imagecreatefromstring(file_get_contents($imgFilePath));
list($width, $height, $type, $attr) = getimagesize($imgFilePath);
// 水印字体颜色
$textColor = imagecolorallocate($im, 0x00, 0x00, 0x00);
// 水印字体大小
$textSize = 18;
// 下载地址(放到本地):https://github.com/JotJunior/PHP-Boleto-ZF2/blob/master/public/assets/fonts/arial.ttf
$fontFile = './msyhbd.ttf';
$fontBox = imagettfbbox($textSize, 0, $fontFile, $newtextLogo);//获取文字所需的尺寸大小
// 居中算法
$fwidth = ceil(($width - $fontBox[2]) / 2);
$fheight = ceil(($height - $fontBox[1] - $fontBox[7]) / 2);
// 添加文字水印
imagefttext($im, $textSize, 0, $fwidth, $fheight, $textColor, $fontFile, $newtextLogo);
// imagefttext($im, $textSize, 0, 30, 110, $textColor, $fontFile, $newtextLogo);
switch($type) {
case 1:
imagegif($im);
break;
case 2:
imagejpeg($im);
break;
case 3:
imagepng($im);
break;
case 6:
imagewbmp($im);
break;
}
imagedestroy($im);
}
$txt = $_GET['txt'];
//$txt = iconv('gbk','utf-8',$txt);
if($txt){
header('Content-Type: image/jpg');
$bgimg = './bgimg/back.jpg';
attach_text_logo($bgimg, $txt);
}
没有合适的资源?快使用搜索试试~ 我知道了~
PHP根据文章标题生成缩略图,并居中展示
共17个文件
jpg:14个
php:2个
ttf:1个
2 下载量 129 浏览量
2023-06-28
12:14:16
上传
评论
收藏 9.37MB ZIP 举报
温馨提示
PHP根据文章标题生成缩略图,并居中展示
资源推荐
资源详情
资源评论
收起资源包目录
autoimg.zip (17个子文件)
autoimg
img.php 2KB
img-2.php 1KB
msyhbd.ttf 13.93MB
bgimg
2.jpg 34KB
10.jpg 35KB
13.jpg 39KB
6.jpg 18KB
back.jpg 11KB
1.jpg 14KB
12.jpg 39KB
5.jpg 33KB
8.jpg 26KB
11.jpg 38KB
3.jpg 16KB
7.jpg 38KB
9.jpg 43KB
4.jpg 39KB
共 17 条
- 1
资源评论
是宽宽呀
- 粉丝: 648
- 资源: 6
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功