8 Star 86 Fork 31

初夏 / php 图片海报生成类

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
index.php 3.52 KB
一键复制 编辑 原始数据 按行查看 历史
初夏 提交于 2020-08-01 15:08 . update index.php.
<?php
include './inc/phpQrcode.class.php';
include './inc/poster.class.php';
//辅助类函数,转换单位
function changeFileSize($size, $dec = 2) {
$a = array('Byte', 'KB', 'MB', 'GB', 'TB', 'PB');
$pos = 0;
while ($size >= 1024) {
$size /= 1024;
$pos++;
}
return round($size, $dec) . ' ' . $a[$pos];
}
//二维码生成内容
$code = 'https://www.baidu.com/';
//生成二维码图片
$qrCodeData = QRcode::pngData($code, 13);
$config = array(
'bg_url' => './img/timg.png',//背景图片路径
'text' => array(
array(
'text' => '初夏',//文本内容
'left' => 312, //左侧字体开始的位置
'top' => 676, //字体的下边框
'fontSize' => 16, //字号
'fontColor' => '255,0,0', //字体颜色
'angle' => 0,
),
array(
'text' => '你不运动,地球也会动',
'left' => 310,
'top' => 720,
'width' => 400,
'fontSize' => 16, //字号
'fontColor' => '0,0,80', //字体颜色
'angle' => 0,
),
array(
'text' => '好嗨哟~',
'left' => 507,
'top' => 760,
'width' => 400,
'fontSize' => 25, //字号
'fontColor' => '0,175,80', //字体颜色
'angle' => -50,
),
array(
'text' => '做梦吧你,哈哈',
'left' => 460,
'top' => 650,
'width' => 400,
'fontSize' => 30, //字号
'fontColor' => '0,0,80', //字体颜色
'angle' => 20,
),
),
'image' => array(
array(
'name' => 'jobs', //图片名称,用于出错时定位
'url' => './img/02.jpg',
'stream' => 0, //图片资源是否是字符串图像流
'left' => 202,
'top' => 639,
'right' => 0,
'bottom' => 0,
'width' => 100,
'height' => 100,
'radius' => 50,
'opacity' => 100
),
array(
'name' => '水印', //图片名称,用于出错时定位
'url' => './img/03.png',
'stream' => 0,
'left' => 507,
'top' => 590,
'right' => 0,
'bottom' => 0,
'width' => 108,
'height' => 108,
'radius' => 0,
'opacity' => 100
),
array(
'name' => '二维码', //图片名称,用于出错时定位
'url' => '',
'stream' => $qrCodeData,
'left' => 273,
'top' => 844,
'right' => 0,
'bottom' => 0,
'width' => 184,
'height' => 184,
'radius' => 0,
'opacity' => 100
),
array(
'name' => '苹果', //图片名称,用于出错时定位
'url' => './img/01.jpg',
'stream' => 0,
'left' => 335,
'top' => 910,
'right' => 0,
'bottom' => 0,
'width' => 50,
'height' => 50,
'radius' => 0,
'opacity' => 100
),
)
);
//设置海报背景图
poster::setConfig($config);
//设置保存路径
$res = poster::make();
//是否要清理缓存资源
poster::clear();
if (!$res) {
echo '生成失败:', poster::getErrMessage();
} else {
header("content-type:image/png");
echo $res;
}
//echo '消耗内存:', changeFileSize(memory_get_usage());
PHP
1
https://gitee.com/chuxia1024/php_poster_generation_class.git
git@gitee.com:chuxia1024/php_poster_generation_class.git
chuxia1024
php_poster_generation_class
php 图片海报生成类
master

搜索帮助