我是靠谱客的博主 威武小伙,这篇文章主要介绍帝国cms根据标题生成图片的函数,现在分享给大家,希望可以做个参考。

编辑/e/class/userfun.php,增加以下函数(字体文件的路径一定要对)

function Reimg($classid,$id,$width='450',$height='300',$bg='原始背景图片地址',$path='temp/img/hd-'){
        global $dbtbpre,$empire,$class_r,$public_r;
        $tbname = $class_r[$classid]['tbname'];
        $r=$empire->fetch1("select * from {$dbtbpre}ecms_$tbname where id='$id' limit 1");
        $mycr=GetPathname($class_r[$r[classid]][classpath]);//栏目目录
        $classpath=$mycr[0];//获取栏目目录
        $path = $path.$classpath.$r[id].'.png';//保存的图片名称
        $file = ECMS_PATH.$path;//图片的绝对地址
        if(!file_exists($file)){//判断图片是否存在
            $font = "SourceHanSansCN-Bold.otf";//字体
            $im=imagecreatefrompng($bg);//背景图片
            $color=imagecolorallocate($im, 0, 0, 255);//设置字体颜色
            $fontBox = imagettfbbox(55, 0, $font ,$r['title']);//获取文字所需的尺寸大小
            $width = ceil(($width - $fontBox[2]) / 2) + 20;//计算文字所需宽度  居中   后面加的数字表示偏移多少
            $height = ceil(($height - $fontBox[1] - $fontBox[7]) / 2) - 35;//计算文字所需高度 居中 后面加的数字表示偏移多少
        imagettftext($im, 48, 0, $width, $height, $color, $font, $r['title']); //生成图片
        imagepng($im,$file); //保存图片
        imagedestroy($im);//释放内存
        }
        return $public_r['newsurl'].$path;//返回数据
}

模版中调用方式

$titlepic = Reimg($r['classid'],$r['id']);
$listtemp='<a href="[!--titleurl--]"><img alt="[!--oldtitle--]" src="'.$titlepic.'" width="158" /></a></dt>';

注意:

若是想在后台直接生成图片,需要在titlepic字段中添加后台执行函数。

最后

以上就是威武小伙最近收集整理的关于帝国cms根据标题生成图片的函数的全部内容,更多相关帝国cms根据标题生成图片内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(130)

评论列表共有 0 条评论

立即
投稿
返回
顶部