当前位置:网站首页>PHP poster QR code synthesis
PHP poster QR code synthesis
2022-07-28 23:58:00 【Small cap I】
Combined parameter method :
/**
* [user_qrcode Parameter combination ]
* @param [type] $bgImg [ Background map ]
* @param [type] $codeImg [ QR code ]
* @param string $name [ name ]
* @param string $remask [ remarks ]
* @param string $content [ describe ]
* @param integer $key [ Generate a QR code name to represent ]
* @return [type] [description]
*/
public function user_qrcode($bgImg,$codeImg,$name=" I'm little Hongmao ",$remask=" Invite you to join XXX Surprise when buying ",$content=" Long press to identify or scan QR code to enter ",$key=0){
$config = array(
'text'=>array(
array(
'text'=>$name,
'left'=>250,
'top'=>815,
'fontPath'=>'/public/upload/ttf/simhei.ttf', // Font files need to be added to download and import
'fontSize'=>22, // Font size
'fontColor'=>'0,0,0', // The font color
'angle'=>0,
'text-aligin' => 'left'
),
array(
'text'=>$remask,
'left'=>250,
'top'=>860,
'fontPath'=>'/public/upload/ttf/simhei.ttf', // Font files need to be added to download and import
'fontSize'=>18, // Font size
'fontColor'=>'143,143,143', // The font color
'angle'=>0,
'text-aligin' => 'left'
),
array(
'text'=>'—— '.$content.' ——',
'left'=>0,
'right'=>0,
'top'=>970,
'fontPath'=>'/public/upload/ttf/simhei.ttf', // Font files need to be added to download and import
'fontSize'=>16, // Font size
'fontColor'=>'169,169,169', // The font color
'angle'=>0,
'text-aligin' => 'center' // The font is centered , Only center Effective , Nothing else
)
),
'image'=>array(
array(
'url'=>$codeImg, // Image resource path
'stream'=>0,
'left'=>50,
'top'=>740,
'right'=>0,
'bottom'=>0,
'width'=>180,
'height'=>180,
'opacity'=>100
),
),
'background'=>$bgImg,
);
$filename = "/public/upload/share_code/".time().rand(0000,9999).$num.".png";
return $this->createPoster($config,$filename);
}Poster synthesis method
/**
* Generate posters
* @param array Parameters , Including pictures and words
* @param string $filename Generate poster file name , If this parameter is not passed, no file will be generated , Direct output picture
* @return [type] [description]
*/
public function createPoster($config=array(),$filename=""){
// If there's anything wrong with reading the newspaper , You can note this first header
if(empty($filename)) header("content-type: image/png");
$imageDefault = array(
'left'=>0,
'top'=>0,
'right'=>0,
'bottom'=>0,
'width'=>100,
'height'=>100,
'opacity'=>100
);
$textDefault = array(
'text'=>'',
'left'=>0,
'top'=>0,
'fontSize'=>32, // Font size
'fontColor'=>'255,255,255', // The font color
'angle'=>0,
);
$background = $config['background'];// The bottom background of the poster
// Background method
$backgroundInfo = getimagesize($background);
$backgroundFun = 'imagecreatefrom'.image_type_to_extension($backgroundInfo[2], false);
$background = $backgroundFun($background);
$backgroundWidth = imagesx($background); // Background width
$backgroundHeight = imagesy($background) + 300; // Background height , Add... Here 300 Height , Bottom white area
$imageRes = imageCreatetruecolor($backgroundWidth,$backgroundHeight);
$color = imagecolorallocate($imageRes, 255, 255, 255);
imagefill($imageRes, 0, 0, $color);
// imageColorTransparent($imageRes, $color); // The color is transparent
imagecopyresampled($imageRes,$background,0,0,0,0,imagesx($background),imagesy($background),imagesx($background),imagesy($background));
// Processed pictures
if(!empty($config['image'])){
foreach ($config['image'] as $key => $val) {
$val = array_merge($imageDefault,$val);
$info = getimagesize($val['url']);
$function = 'imagecreatefrom'.image_type_to_extension($info[2], false);
if($val['stream']){ // If it is a string image stream
$info = getimagesizefromstring($val['url']);
$function = 'imagecreatefromstring';
}
$res = $function($val['url']);
$resWidth = $info[0];
$resHeight = $info[1];
// Create Sketchpad , Zoom the picture to the specified size
$canvas=imagecreatetruecolor($val['width'], $val['height']);
imagefill($canvas, 0, 0, $color);
// The key function , Parameters ( Target resources , Source , The starting coordinate of the target resource x,y, The starting coordinate of the source resource x,y, The width and height of the target resource w,h, The width and height of the source resource w,h)
imagecopyresampled($canvas, $res, 0, 0, 0, 0, $val['width'], $val['height'],$resWidth,$resHeight);
$val['left'] = $val['left']<0?$backgroundWidth- abs($val['left']) - $val['width']:$val['left'];
$val['top'] = $val['top']<0?$backgroundHeight- abs($val['top']) - $val['height']:$val['top'];
// Place image
imagecopymerge($imageRes,$canvas, $val['left'],$val['top'],$val['right'],$val['bottom'],$val['width'],$val['height'],$val['opacity']);// Left , On , Right , Next , Width , Height , transparency
}
}
// Working with text
if(!empty($config['text'])){
foreach ($config['text'] as $key => $val) {
$val = array_merge($textDefault,$val);
list($R,$G,$B) = explode(',', $val['fontColor']);
$fontColor = imagecolorallocate($imageRes, $R, $G, $B);
if($val['text-aligin'] == 'center'){
$fontBox = imagettfbbox($val['fontSize'], 0, $val['fontPath'], $val['text']);// Get the required size of the text
// Center vertically and horizontally
//imagettftext($imageRes, $val['fontSize'], $val['angle'], ceil(($backgroundWidth - $fontBox[2]) / 2), ceil(($backgroundHeight - $fontBox[1] - $fontBox[7]) / 2), $fontColor, $val['fontPath'], $val['text']);
// Horizontal center
imagettftext($imageRes, $val['fontSize'], $val['angle'], ceil(($backgroundWidth - $fontBox[2]) / 2), $val['top'], $fontColor, $val['fontPath'], $val['text']);
}else{
$val['left'] = $val['left']<0?$backgroundWidth- abs($val['left']):$val['left'];
$val['top'] = $val['top']<0?$backgroundHeight- abs($val['top']):$val['top'];
imagettftext($imageRes,$val['fontSize'],$val['angle'],$val['left'],$val['top'],$fontColor,$val['fontPath'],$val['text']);
}
}
}
// Generate pictures
if(!empty($filename)){
$res = imagepng($imageRes,ROOT_PATH.$filename); // Save to local
imagedestroy($imageRes);
if(!$res) return false;
return $filename;
}else{
imagepng ($imageRes); // Show... On the browser
imagedestroy($imageRes);
}
}design sketch :

边栏推荐
- 1-7 解决类中方法的this指向问题
- 多传感器融合定位(二)——基于地图的定位
- Leetcode64. 最小路径和
- 控件 圆角描边 MaterialShapeDrawable
- 简述分组密码的加密分组链接模式的工作原理及其特点(密码学移位密码加密解密)
- Working principle of fastdfs (technical principle)
- Inspur clusterenginev4.0 remote command execution vulnerability cve-2020-21224
- Multisensor fusion positioning (III) -- inertial technology
- Jincang database kingbasees client Programming Interface Guide - ODBC feature support constraints
- VMware VCSA 7.0 Install
猜你喜欢

PHP 海报二维码合成

Jincang database kingbasees client programming interface guide ODBC (2. Overview)

Deep analysis of integrated learning xgboost

Worthington丨Worthington胰蛋白酶化学性质及相关研究

Is the declarative code of compose so concise?

AUTOCAD——Excel表格导入CAD、CAD合并两兄弟

DoIP测试开发实践

迅为IMX6开发板QT系统创建AP热点基于RTL8723-交叉编译iptables

Hyperparametric optimization (grid search and Bayesian Optimization)

ISO 13400(DoIP)标准解读
随机推荐
基因组 DNA 分离丨Worthington核糖核酸酶A
Js判断数据类型的4种⽅式
SAP oracle 复制新实例后数据库远程连接报错 ora-01031
PowerCLi VMware vCenter 通过自建的PXE Server一键批量部署常规New-VM
Leetcode59. 螺旋矩阵 II
PMP考试倒计时,速看3A通关锦囊!
2022-07-28:以下go语言代码输出什么?A:AA;B:AB;C:BA;D:BB。 package main import ( “fmt“ ) func
以JSP为视图解析器搭建SSM项目
VS2005透过SourceOffSite访问VSS2005的设置方法「建议收藏」
Jincang database kingbasees client programming interface guide ODBC (5. Development process)
Xss.haozi.me range details
Multi sensor fusion positioning (II) -- map based positioning
解决:Direct local .aar file dependencies are not supported when building an AAR.
数据中台的那些“经验与陷阱”
Leetcode64. 最小路径和
GhostNets on Heterogeneous Devices via Cheap Operations
Leetcode62. 不同路径
AUTOCAD——Excel表格导入CAD、CAD合并两兄弟
PowerCL 批量创建及管理虚拟交换机
VMware VCSA 7.0 Install