当前位置:网站首页>PHP API to obtain QR code and combine to generate pictures
PHP API to obtain QR code and combine to generate pictures
2022-06-30 08:18:00 【BlizzardWu】
public function test()
{
$template = ROOT_PATH . "public/uploads/back.png";
$x = "70";
$y = "30";
$code = [" Shangqin building "," Every two years ","112233"];
$qrcode = $this->create_qrcode($mac,$type);
$qrcode_url = ROOT_PATH . "public/uploads/".$v['mac']."_qrcode.png";
$curl = new Curl();
$curl->download($qrcode, $qrcode_url);
$filename = $addr."_".$name."_".$mac;
$pic = $this->getActivityImg($template, $qrcode_url, $x, $y, $code, time(), $filename);
$pic = "/public" .explode("public",$pic)[1];
return $pic;
}
/** * api Generate qr code ( Test use ) * @param string $mac equipment MAC * @param string $type equipment TYPE */
public function create_qrcode($mac,$type)
{
$ip = empty($ip) ? $_SERVER['HTTP_HOST'] : $ip;
$port = empty($port) ? $_SERVER['SERVER_PORT'] : $port;
$mac = empty($mac) ? "112233445566" : $mac;
$type = empty($type) ? "0A" : $type;
$data = ["ip"=>$ip,"port"=>$port,"mac"=>$mac,"type"=>$type];
$data = json_encode($data);
$http = (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] && $_SERVER['HTTPS'] != 'off') ? 'https' : 'http';
//$url=urlencode("{$http}://{$ip}:{$port}/?m=Index&c=index&a=index_qu&mac={$mac}&type={$type}");
// $url=urlencode("{$http}://{$_SERVER['HTTP_HOST']}:{$_SERVER['SERVER_PORT']}/?ip={$ip}&port={$port}&mac={$mac}&type={$type}");
$url=urlencode("{
$data}");
$qrcode = 'https://api.qrserver.com/v1/create-qr-code/?size=180x180&data=' . $url;
return $qrcode;
}
/** * Combine QR codes to generate pictures * * @param [type] $template Background map * @param [type] $qr_url QR code address * @param [type] $x x Axis coordinates * @param [type] $y y Axis coordinates * @param [type] $code Picture caption * @param [type] $jointime Creation time * @param [type] $mac mac * @return void */
private function getActivityImg($template, $qr_url, $x, $y, $code, $jointime, $filename) {
$time = date("Ym", $jointime);
// Create folder
// $dir = iconv("UTF-8", "GBK", ROOT_PATH."public/uploads/" . $time . "");
$dir = iconv("UTF-8", "GBK", ROOT_PATH."public/uploads/");
if (!file_exists($dir)) {
mkdir($dir, 0777, true);
}
// Synthetic band logo The two-dimensional code picture of Template image --------------start
$path_1 = $template;
$path_2 = $qr_url;
$image_1 = imagecreatefrompng($path_1);
$image_2 = imagecreatefrompng($path_2);
// $image_2 = imagecreatefromstring(file_get_contents($path_2));
$image_3 = imageCreatetruecolor(imagesx($image_1), imagesy($image_1));
$color = imagecolorallocate($image_3, 0, 0, 0);
// Add words to the picture
$font_file = ROOT_PATH . "public/static/fonts/simkai.ttf"; // The font file
$font_color_1 = ImageColorAllocate($image_1, 100, 100, 100);
imagettftext($image_1, 20, 0, 50, 300, $font_color_1, $font_file, " Location :" . $code[0]); // Add text
imagettftext($image_1, 20, 0, 50, 350, $font_color_1, $font_file, " name :" . $code[1]);
imagettftext($image_1, 20, 0, 50, 400, $font_color_1, $font_file, "MAC :" . $code[2]);
imageline($image_1, 100, 100, 100, 100, $font_color_1);
// Add words to the picture end
imagefill($image_3, 0, 0, $color);
imageColorTransparent($image_3, $color);
imagecopyresampled($image_3, $image_1, 0, 0, 0, 0, imagesx($image_1), imagesy($image_1), imagesx($image_1), imagesy($image_1));
imagecopymerge($image_3, $image_2, $x, $y, 0, 0, imagesx($image_2), imagesy($image_2), 100);
// Synthetic band logo The two-dimensional code picture of Template image --------------end
// Output to local folder
$source = ROOT_PATH.'public/uploads/' . $filename . '.png'; // Original picture
$EchoPath = ROOT_PATH.'public/uploads/'. $filename .'.jpg'; // Compressed picture
imagepng($image_3, $source);
$this->handlePic($source);
imagedestroy($image_3);
unlink($source);
unlink($path_2);
// Return generated path
return $EchoPath;
}
/** * Picture compression * @param $srcPathName */
public function handlePic($srcPathName)
{
$srcFile = $srcPathName;
$srcFileExt = strtolower(trim(substr(strrchr($srcFile, '.'), 1)));
if ($srcFileExt == 'png') {
$dstFile = str_replace('.png', '.jpg', $srcPathName);
$photoSize = GetImageSize($srcFile);
$pw = $photoSize[0];
$ph = $photoSize[1];
$dstImage = ImageCreateTrueColor($pw, $ph);
imagecolorallocate($dstImage, 255, 255, 255);
// Read the picture
$srcImage = ImageCreateFromPNG($srcFile);
// Collage picture
imagecopyresampled($dstImage, $srcImage, 0, 0, 0, 0, $pw, $ph, $pw, $ph);
imagejpeg($dstImage, $dstFile, 70);
imagedestroy($srcImage);
}
}
边栏推荐
- Want to change careers, but don't know what to do? This article is written for you who are confused
- Deep learning -- recurrent neural network
- QT event cycle
- JS中的this指向
- 【NVMe2.0b 14-5】Firmware Download/Commit command
- mysql无法连接内网的数据库
- [flower carving experience] 14 line blank board pingpong library test external sensor module (one)
- Cesium learning notes (V) custom geometry and appearance
- 【NVMe2.0b 14-4】Directive Send/Receive command
- 【NVMe2.0b 14-3】Doorbell Buffer Config command、Device Self-test command
猜你喜欢

Applet uses QR code plug-in

Cesium learning notes (V) custom geometry and appearance

安科瑞高等学校校园建筑节能监管系统建设

【Tensorflow-gpu】window11下深度学习环境搭建

vulfocus入门靶机

【NVMe2.0b 14-1】Abort、Asynchronous Event Request、Capacity Management command

Deep learning - embedding matrix and learning word embedding andword2vec

【NVMe2.0b 14-5】Firmware Download/Commit command

Hit the industry directly | the flying propeller launched the industry's first model selection tool

Is it difficult to jump job ByteDance? With these skills, you can easily pass
随机推荐
亚马逊测评术语有哪些?
Halcon12+vs2013 C # configuration
Environment configuration of ROS Aubo manipulator
Pycharm Dlib library installation
Introduction to opencv (II): image color space conversion and image saving
Using typera+picgo to realize automatic uploading of markdown document pictures
跳槽字节跳动很难嘛?掌握这些技巧,你也能轻松通过
Wsl2 using GPU for deep learning
全栈最全性能测试理论-总结
Cesium learning notes (V) custom geometry and appearance
Transformer architecture understanding
Swagger use
Redis design and Implementation (VIII) | transaction
Is it difficult to jump job ByteDance? With these skills, you can easily pass
[nvme2.0b 14-7] set features (Part 1)
Want to ask, how to choose securities companies for stock speculation? Is it safe to open an account online?
Miracle Mu server rental selection is real and easy to use, stable and intrusion proof
涂鸦Wi-Fi&BLE SoC开发幻彩灯带
【Tensorflow-gpu】window11下深度学习环境搭建
Getordefault method of map class