簡介
因工作需要製作各種邀請海報,分享海報,生成簽到日曆海報等等。
為了方便封裝了一個 composer 包,主要是用來完成,製作海報,合成圖片,圖片加水印,合成二維碼,生成二維碼等工作。
有興趣的小夥伴可以使用這個,確實挺方便的!
使用文件
文件放在開源倉庫:使用文件
示例
# 使用也非常方便 有 靜態呼叫 和 例項化呼叫 兩種方式可供選擇
use Kkokk\Poster\PosterManager;
use Kkokk\Poster\Exception\Exception;
# 靜態呼叫
$addImage = "https://ss3.bdstatic.com/70cFv8Sh_Q1YnxGkpoWK1HF6hhy/it/u=2854425629,4097927492&fm=26&gp=0.jpg";
$result = PosterManager::Poster('poster/poster_user') //生成海報,這裡寫儲存路徑和檔名,可以指定圖片字尾。預設png
->buildIm(638,826,[255,255,255,127],false)
->buildImage('https://test.acyapi.51acy.com/wechat/poster/top_bg.png')
->buildImage('https://test.acyapi.51acy.com/wechat/poster/half_circle.png',254,321)
->buildImage($addImage,253,326,0,0,131,131,false,'circle')
->buildImage('https://test.acyapi.51acy.com/wechat/poster/fengexian.png',0,655)
->buildText('蘇 軾','center',477,16,[51, 51, 51,1])
->buildText('明月幾時有,把酒問青天。不知天上宮闕,今夕是何年。','center',515,14,[53, 53, 53, 1])
->buildText('我欲乘風歸去,又恐瓊樓玉宇,高處不勝寒。','center',535,14,[53, 153, 153, 1])
->buildText('起舞弄清影,何似在人間。轉朱閣,低綺戶,照無眠。','center',555,14,[53, 153, 153, 1])
->buildText('不應有恨,何事長向別時圓?','center',575,14,[53, 153, 153, 1])
->buildText('人有悲歡離合,月有陰晴圓缺,此事古難全。','center',595,14,[53, 153, 153, 1])
->buildText('但願人長久,千里共嬋娟。','center',615,14,[53, 153, 153, 1])
->buildText('長按識別',497,720,15,[53, 153, 153, 1])
->buildText('檢視他的更多作品',413,757,15,[53, 153, 153, 1])
->buildQr('http://www.520yummy.com',37,692,0,0,0,0,4,1)
->getPoster();
# 支援批量合成
$buildImageManyArr = []; // 多個圖片
$buildTextManyArr = []; // 多個文字
$buildQrManyArr = []; // 多個二維碼
$result = PosterManager::Poster('poster/poster_user')
->buildIm(638,826,[255,255,255,127],false)
->buildImageMany($buildImageManyArr)
->buildTextMany($buildImageManyArr)
->buildQrMany($buildQrManyArr)
->getPoster();
# 圖片加水印
# 給圖片新增水印
$setImage = "https://ss3.bdstatic.com/70cFv8Sh_Q1YnxGkpoWK1HF6hhy/it/u=2854425629,4097927492&fm=26&gp=0.jpg";
$result = PosterManager::Poster() //給指定圖片新增水印,這裡為空就好
->buildImDst(__DIR__.'/test.jpeg')
->buildImage($setImage,'-20%','-20%',0,0,0,0,false)
->setPoster();
# 例項化呼叫
$addImage = "https://ss3.bdstatic.com/70cFv8Sh_Q1YnxGkpoWK1HF6hhy/it/u=2854425629,4097927492&fm=26&gp=0.jpg";
$PosterManager = new PosterManager('poster/poster_user'); //生成海報,這裡寫儲存路徑和檔名,可以指定圖片字尾。預設png
$result = $PosterManager->buildIm(638,826,255,255,255,1]27,false)
->buildIm(638,826,[255,255,255,127],false)
->buildImage('https://test.acyapi.51acy.com/wechat/poster/top_bg.png')
->buildImage('https://test.acyapi.51acy.com/wechat/poster/half_circle.png',254,321)
->buildImage($addImage,253,326,0,0,131,131,false,'circle')
->buildImage('https://test.acyapi.51acy.com/wechat/poster/fengexian.png',0,655)
->buildText('蘇 軾','center',477,16,[51, 51, 51,1])
->buildText('明月幾時有,把酒問青天。不知天上宮闕,今夕是何年。','center',515,14,[53, 53, 53, 1])
->buildText('我欲乘風歸去,又恐瓊樓玉宇,高處不勝寒。','center',535,14,[53, 153, 153, 1])
->buildText('起舞弄清影,何似在人間。轉朱閣,低綺戶,照無眠。','center',555,14,[53, 153, 153, 1])
->buildText('不應有恨,何事長向別時圓?','center',575,14,[53, 153, 153, 1])
->buildText('人有悲歡離合,月有陰晴圓缺,此事古難全。','center',595,14,[53, 153, 153, 1])
->buildText('但願人長久,千里共嬋娟。','center',615,14,[53, 153, 153, 1])
->buildText('長按識別',497,720,15,[53, 153, 153, 1])
->buildText('檢視他的更多作品',413,757,15,[53, 153, 153, 1])
->buildQr('http://www.520yummy.com',37,692,0,0,0,0,4,1)
->getPoster();
呼叫結果示例
本作品採用《CC 協議》,轉載必須註明作者和本文連結