PHP code example of zmxy / lattice
1. Go to this page and download the library: Download zmxy/lattice library . Choose the download type require .
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
zmxy / lattice example snippets
use Lattice\LatticePck\Lattice;
$width = 296;
$height = 128;
$lattice = new Lattice();
$lattice->createBlankImage($width, $height);
use Lattice\LatticePck\LatticeImg;
LatticeImg::Rectangle($lattice, 50, 50, [50, 50], 0, 1);
use Lattice\LatticePck\LatticeImg;
$order = "http://weixin.qq.com/r/BRy0rI7EoNPfrcrP90kX";
LatticeImg::QrCode($lattice, $order, [0, 12, 'center'], "public/", 0);
use Lattice\LatticePck\LatticeOutput;
$latticeOutput = (new LatticeOutput($lattice));
echo $latticeOutput->getHTML();
use Lattice\LatticePck\Lattice;
use Lattice\LatticePck\LatticeImg;
use Lattice\LatticePck\LatticeOutput;
$width = 296;
$height = 128;
$lattice = new Lattice();
$latticeOutput = (new LatticeOutput($lattice));
$lattice->createBlankImage($width, $height);
// 坐标
$x = 6;
$y = 6;
$lattice->text('LatticePHP-使用PHP生成点阵图', [$x, $y, 'top-center']);
// LatticeImg::Rectangle($lattice, 50, 50, [50, 50], 0, 1);
$order = "http://weixin.qq.com/r/BRy0rI7EoNPfrcrP90kX";
LatticeImg::QrCode($lattice, $order, [0, 12, 'center'], "public/", 0);
echo $latticeOutput->getHTML();
use Lattice\LatticePck\Lattice;
$width = 296;
$height = 128;
$lattice = new Lattice();
$lattice->createBlankImage($width, $height);
/**
* 创建空白图片
* @param int $width
* @param int $height
* @param int $color 填充颜色 0.白 1.黑
*/
use Lattice\LatticePck\Lattice;
$fontDraw = Lattice::getFontDraw();
$fontDraw->setFont('./font/st16_16', 16, 8);
/**
* 设置字体大小
* @param stirng $fontFileName 字体文件路径
* @param int $font_v 中文宽度
* @param int $font_e 英文宽度
* @return void
*/
$lattice->colorReflection($textArr);
/**
* 颜色反转
* @param array $textArr 点阵数组
* @return void
*/
[$x, $y, 'top-center']
use Lattice\LatticePck\Lattice;
$lattice = new Lattice();
$lattice->text('LatticePHP-使用PHP生成点阵图', [$x, $y, 'top-center']);
use Lattice\LatticePck\LatticeImg;
LatticeImg::point($lattice, [0, 12]);
/**
* 创建点
* @param Lattice $lattice Lattice对象
* @param array $xy XY坐标偏移指令
* @param int $color 点颜色 1.黑 0.白 默认为1
* @return void
*/
use Lattice\LatticePck\LatticeImg;
LatticeImg::Line($lattice, [[1, 1], [8, 8]]);
/**
* 创建线
* @param Lattice $lattice Lattice对象
* @param array $xy XY坐标[[1, 1], [8, 8]] 不支持偏移指令
* @param int $color 线条颜色 1.黑 0.白 默认为1
* @return void
*/
use Lattice\LatticePck\LatticeImg;
LatticeImg::Rectangle($lattice, $width, $height, [$x, $y]);
/**
* 创建矩形
* @param Lattice $lattice Lattice对象
* @param int $width 宽度
* @param int $height 高度
* @param array $xy XY坐标偏移
* @param int $fillColor 填充颜色 0.白 1.黑
* @param int $borderSize 边框大小
* @param int $borderColor 边框颜色
* @return void
*/
use Lattice\LatticePck\LatticeImg;
$lattice->insertImg($lattice, $filePath, [$x, $y]);
/**
* 插入图片(只能是黑白)
* @param Lattice $lattice 点阵类
* @param string $filePath 图片的文件路径
* @param array $xy 坐标偏移
* @param int $mode 模式 0.只读白色,其余为黑 1. 只读黑色,其余为白 2. 黑白都读,其余为灰(用2表示),默认模式为1
* @return void
* @throws Exception
*/
use Lattice\LatticePck\LatticeImg;
$order = "112233";
LatticeImg::BarCode($lattice, $order, [$x, $y, 'top-center']);
/**
* Barcode生成条纹码
* @param Lattice $lattice 点阵类
* @param string $text 内容字符串
* @param array $xy xy坐标
* @param string $barcodeType 条码格式 默认 BarcodeType::Code128
* @param int $thickness 高度厚度 默认18
* @param int $thick 厚度比例 默认1
* @param int $fillColor 条纹码颜色 默认1
* @param bool $delete 是否自动将生成的图片删除 默认true
* @param string $filePath 文件路径 默认 public/images/ (结尾记得带/)
* @param string $fileName 文件名 默认时间戳+随机数
* @return void
*/
use Lattice\LatticePck\LatticeImg;
$order = "http://weixin.qq.com/r/BRy0rI7EoNPfrcrP90kX";
LatticeImg::QrCode($lattice, $order, [$x, $y, 'center']);
/**
* Barcode生成二维码
* @param Lattice $lattice 点阵类
* @param string $text 字符串
* @param array $xy xy坐标
* @param int $size 尺寸 默认100
* @param bool $delete 是否自动将生成的图片删除 默认true
* @param string $filePath 生成二维码的文件路径 默认 public/images/ (结尾记得带/)
* @param string $fileName 生成二维码的文件名 默认时间戳+随机数
* @return void
* @throws Exception
*/
use Lattice\LatticePck\Lattice;
use Lattice\LatticePck\LatticeOutput;
$width = 296;
$height = 128;
$lattice = new Lattice();
$latticeOutput = (new LatticeOutput($lattice));
$lattice->createBlankImage($width, $height);
$order = "http://weixin.qq.com/r/BRy0rI7EoNPfrcrP90kX";
LatticeImg::QrCode($lattice, $order, [0, 12, 'center']);
echo $latticeOutput->getHTML();
echo '<pre>';
print_r($latticeOutput->getImageArray());
echo $latticeOutput->toHexa();
/**
* 将二进制数据转换16进制数串的函数(并反转)
* @param array $olbImage 点阵数组 默认整张画布
* @param bool $strrev 是否反转图片(将图片倒置并且竖直)
* @return string $_32hexa
*/
$lattice->interception();
$address = "我是一个很长的地址,要被换行哦噢噢噢噢噢噢噢噢哦哦哦哦哦哦哦哦哦哦哦哦";
$addressArray = LatticeFont::strWrap($address, 48, 2);
/**
* 字符串换行分割
* @param string $str 要被换行分割的字符串
* @param int $length 一行的长度, 英文长度 默认12
* @param int $hans_length 一个汉字等于多少个英文的宽度(GBK编码是2,UTF-8编码是3) 默认2
* @param string $append 尾部追加的字符串 默认为空
* @return array 字符串分割后的数组
*/
use Lattice\Utils\CString;
CString::MergeBetween('AAAAA', 'BBBBB');
/**
* 以类似ABABAB模式的方式合并两个字符串结果。
* @param string $str1 String A
* @param string $str2 String B
* @return string Merged string
*/
/**
* 写入文字
* @param string $text 文字
* @param array $xy xy坐标与偏移指令
* @param int $color 字体颜色 1.黑色 0.白色
* @param int $spacing 字间距
* @param int $font_bold 1 加粗 0 不加粗
* @param int $heightSpacing 1 去除上下空白 0 不去除
* @param int $getType 1 获取点阵数组
* @return array
*/