最近在弄图片处理, 看网上在线生成的四色二维码挺有趣的。 本身弄了一个。git
总体思路:github
composer
的qrcode包生成一个黑白二维码。imagecolorat
获取当前像素的颜色imagesetpixel
填充彩色点/**
* 获取当前所在像素点的位置
* $x, $y 是当前像素位置,
* $block 是二维码有多少个色块,好比 4 个, 9个
*/
function getLocationIndex($x, $y, $block)
{
$x_index = (int) floor($x / ($img_width / $block));
$y_index = (int) floor($y / ($img_height / $block));
// 接下来的这个 $index 就是当前像素点算出来处于第几个色块
$index = $x_index + (2 * $y_index);
return $index;
}复制代码
效果图: bash
而后我进行了封装,代码也放到了Github
上面, 支持composer
安装,又须要的朋友能够看一下。顺便来个star
最后祝你们每一天都是快乐*\(^_^)/*
github地址:github.com/WaitMoonMan…composer