浏览代码

Add qr code

Zhu Jinhui 7 年之前
父节点
当前提交
139c4505f2

+ 114 - 45
src/Library/Qr.php

@@ -3,58 +3,127 @@
  * 二维码工具
  * 提供读取和生成二维码方法
  */
+
 namespace Qii\Library;
 
 \Qii\Autoloader\Psr4::getInstance()
-	->setUseNamespaces([
-		['Zxing', true],
-		['QrCode', true],
-	])
-	->addNamespaces([
-		['Zxing', Qii_DIR . DS . 'Library'. DS .'QrReader'],
-		['QrCode', Qii_DIR . DS . 'Library'. DS .'QrCode'],
-	]);
+    ->setUseNamespaces([
+        ['Zxing', true],
+        ['QrCode', true],
+    ])
+    ->addNamespaces([
+        ['Zxing', Qii_DIR . DS . 'Library' . DS . 'QrReader'],
+        ['QrCode', Qii_DIR . DS . 'Library' . DS . 'QrCode'],
+    ]);
 use Zxing\QrReader;
 
-_require(__DIR__ . DS . 'QrReader'. DS . 'Common'. DS .'customFunctions.php');
-_require(__DIR__ . DS . 'QrReader'. DS . 'QrReader.php');
+_require(__DIR__ . DS . 'QrReader' . DS . 'Common' . DS . 'customFunctions.php');
+_require(__DIR__ . DS . 'QrReader' . DS . 'QrReader.php');
 
 
-_require(__DIR__ . DS . 'QrCode'. DS . 'QRconst.php');
-_require(__DIR__ . DS . 'QrCode'. DS . 'QREncode.php');
+_require(__DIR__ . DS . 'QrCode' . DS . 'QRconst.php');
+_require(__DIR__ . DS . 'QrCode' . DS . 'QREncode.php');
 
 class Qr
 {
-	public function __construct()
-	{
-		
-	}
-	/**
-	 * 读取二维码中的内容
-	 * @param string $image 图片地址
-	 * @return string 内容
-	 */
-	public function reader($image)
-	{
-		if(!file_exists($image))
-		{
-			throw new \Exception('Unknow image file', __LINE__);
-		}
-		$qrcode = new QrReader($image);
-		$text = $qrcode->text();
-		return $text;
-	}
-	/**
-	 * 生成二维码
-	 * @param string $txt 二维码文案
-	 * @param int $pointSize 图片尺寸
-	 * @param int $margin 图片边距
-	 * @param int $errorLevel 错误级别
-	 * @return null
-	 */
-	public function creater($txt, $pointSize = 8, $margin = 1, $errorLevel = 4)
-	{
-		if(!$txt) return;
-		return \QrCode\QRcode::png($txt, false, $errorLevel, $pointSize, $margin);
-	}
-}
+    use \QrCode\Traits\Fill;
+    public function __construct()
+    {
+
+    }
+
+    /**
+     * 读取二维码中的内容
+     * @param string $image 图片地址
+     * @return string 内容
+     */
+    public function reader($image)
+    {
+        if (!file_exists($image)) {
+            throw new \Exception('Unknow image file', __LINE__);
+        }
+        $qrcode = new QrReader($image);
+        $text = $qrcode->text();
+        return $text;
+    }
+
+    /**
+     * 生成二维码
+     * @param string $txt 二维码文案
+     * @param int $pointSize 图片尺寸
+     * @param int $margin 图片边距
+     * @param int $errorLevel 错误级别
+     * @return null
+     */
+    public function creator($txt, $pointSize = 8, $margin = 1, $errorLevel = 4)
+    {
+        if (!$txt) return;
+        return \QrCode\QRcode::png($txt, false, $errorLevel, $pointSize, $margin);
+    }
+
+    /**
+     * @param string $txt 需要生成的内容
+     * @param int $pointSize 每个点的大小
+     * @param int $margin 边距
+     * @param int $errorLevel 错误级别
+     * @param array $options 额外选型
+     */
+    public function creatorColor($txt, $pointSize = 8, $margin = 1, $errorLevel = 4, $options = array())
+    {
+        $defaults = array(
+            'width' => 240, //图片大小
+            'logo' => 'static/images/logo.png', //logo
+            'bg' => '',
+            'pointColor' => '#000000', //定点颜色
+            'inPointColor' => '#000000',//内定点
+            'frontColor' => '#000000',//前景色
+            'bgColor' => '#FFFFFF', //背景色
+            'contentColor' => '#000000', //内容颜色
+            'style' => 1,//直角 1, 液态 2 ,圆角 0
+        );
+        $options = array_merge($defaults, $options);
+
+        \QrCode\QRencode::factory($errorLevel, $pointSize, $margin);
+        $qrCls = new \QrCode\QRencode();
+        $data = $qrCls->encode($txt);
+
+        switch($options['style'])
+        {
+            case 2:
+                $handle = new \QrCode\Liquid($pointSize, $options);
+                break;
+            case 1:
+                $handle = new \QrCode\Rectangle($pointSize, $options);
+                break;
+            case 0:
+                $handle = new \QrCode\Edellipse($pointSize, $options);
+                break;
+        }
+        $img = $handle->handle($data);
+
+        //保存图片
+
+        $im = $this->resizeImage($img, $options['width'], $options['width']);
+
+
+        //增加logo
+        if (!empty($options['logo'])) {
+            $im = $this->imageAddLogo($im, $options['logo']);
+        }
+
+
+        //添加背景图
+        if (!empty($options['bg'])) {
+            $im = $this->imageAddBG($im, $options['bg']);
+        }
+        //保存图片
+        header('Content-type:image/png');
+        imagepng($im);
+    }
+
+    public function __call($method, $args)
+    {
+        $qrCls = new QRencode();
+        return call_user_func_array(array($qrCls, $method), $args);
+    }
+}

+ 509 - 0
src/Library/QrBackup.php

@@ -0,0 +1,509 @@
+<?php
+/**
+ * 二维码工具
+ * 提供读取和生成二维码方法
+ */
+
+namespace Qii\Library;
+
+\Qii\Autoloader\Psr4::getInstance()
+    ->setUseNamespaces([
+        ['Zxing', true],
+        ['QrCode', true],
+    ])
+    ->addNamespaces([
+        ['Zxing', Qii_DIR . DS . 'Library' . DS . 'QrReader'],
+        ['QrCode', Qii_DIR . DS . 'Library' . DS . 'QrCode'],
+    ]);
+use Zxing\QrReader;
+
+_require(__DIR__ . DS . 'QrReader' . DS . 'Common' . DS . 'customFunctions.php');
+_require(__DIR__ . DS . 'QrReader' . DS . 'QrReader.php');
+
+
+_require(__DIR__ . DS . 'QrCode' . DS . 'QRconst.php');
+_require(__DIR__ . DS . 'QrCode' . DS . 'QREncode.php');
+
+class Qr
+{
+    use \QrCode\traits\fill;
+    public function __construct()
+    {
+
+    }
+
+    /**
+     * 读取二维码中的内容
+     * @param string $image 图片地址
+     * @return string 内容
+     */
+    public function reader($image)
+    {
+        if (!file_exists($image)) {
+            throw new \Exception('Unknow image file', __LINE__);
+        }
+        $qrcode = new QrReader($image);
+        $text = $qrcode->text();
+        return $text;
+    }
+
+    /**
+     * 生成二维码
+     * @param string $txt 二维码文案
+     * @param int $pointSize 图片尺寸
+     * @param int $margin 图片边距
+     * @param int $errorLevel 错误级别
+     * @return null
+     */
+    public function creator($txt, $pointSize = 8, $margin = 1, $errorLevel = 4)
+    {
+        if (!$txt) return;
+        return \QrCode\QRcode::png($txt, false, $errorLevel, $pointSize, $margin);
+    }
+
+    /**
+     * @param string $txt 需要生成的内容
+     * @param int $pointSize 每个点的大小
+     * @param int $margin 边距
+     * @param int $errorLevel 错误级别
+     * @param array $options 额外选型
+     */
+    public function creatorColor($txt, $pointSize = 8, $margin = 1, $errorLevel = 4, $options = array())
+    {
+        $defaults = array(
+            'width' => 240, //图片大小
+            'logo' => 'static/images/logo.png', //logo
+            'bg' => '',
+            'pointColor' => '#CC0033', //定点颜色
+            'inPointColor' => '#000000',//内定点
+            'frontColor' => '#000000',//前景色
+            'bgColor' => '#FFFFFF', //背景色
+            'contentColor' => '#000000', //内容颜色
+            'style' => 1,
+        );
+        $options = array_merge($defaults, $options);
+
+        \QrCode\QRencode::factory($errorLevel, $pointSize, $margin);
+        $qrCls = new \QrCode\QRencode();
+        $data = $qrCls->encode($txt);
+
+
+        $pointColor = $this->hex2rgb($options['pointColor']);
+        $inPointColor = $this->hex2rgb($options['inPointColor']);
+        $frontColor = $this->hex2rgb($options['frontColor']);
+        $bgColor = $this->hex2rgb($options['bgColor']);
+        $contentColor = $this->hex2rgb($options['contentColor']);
+
+        $w = strlen($data[0]);
+        $h = count($data);
+
+        $imageSize = count($data) - 1;
+        $s = $pointSize;//每一块的大小
+
+
+        $img = ImageCreate($w * $pointSize, $h * $pointSize);
+
+        $bgColor = ImageColorAllocate($img, $bgColor['r'], $bgColor['g'], $bgColor['b']);//背景色
+        $pointColor = ImageColorAllocate($img, $pointColor['r'], $pointColor['g'], $pointColor['b']);//定点色
+        $inPointColor = ImageColorAllocate($img, $inPointColor['r'], $inPointColor['g'], $inPointColor['b']);//内定点
+        $frontColor = ImageColorAllocate($img, $frontColor['r'], $frontColor['g'], $frontColor['b']);//前景色
+        $contentColor = ImageColorAllocate($img, $contentColor['r'], $contentColor['g'], $contentColor['b']);//内容色
+
+        switch($options['style'])
+        {
+            case 1:
+                $img = $this->rectangle($data, $pointSize, $options);
+                header('Content-type:image/png');
+                imagepng($img);
+                break;
+        }
+        $y = 0;
+        foreach ($data as $row) {
+            $x = 0;
+            while ($x < $w) {
+                if (substr($row, $x, 1) == "1") {
+                    //返回字符串 string 由 start 和 length 参数指定的子字符串。
+                    //左上角定点
+                    if ($x < 7 && $y < 7) {
+                        //左上角定点的四个大角
+                        if ($x === 0 || $y === 0 || $x === 6 || $y === 6) {
+                            switch ($options['style']) {
+                                case 2:
+                                    //液态
+                                    if ($x === 0 && $y === 0) {
+                                        $this->roundedCorner($img, $x, $y, $s, $pointColor, true, false, false, false);
+                                    } else if ($x === 0 && $y === 6) {
+                                        $this->roundedCorner($img, $x, $y, $s, $pointColor, false, true, false, false);
+                                    } else if ($x === 6 && $y === 6) {
+                                        $this->roundedCorner($img, $x, $y, $s, $pointColor, false, false, true, false);
+                                    } else if ($x === 6 && $y === 0) {
+                                        $this->roundedCorner($img, $x, $y, $s, $pointColor, false, false, false, true);
+                                    } else {
+                                        imagefilledrectangle($img, $x * $pointSize, $y * $pointSize, ($x + 1) * $pointSize, ($y + 1) * $pointSize, $pointColor);
+                                    }
+                                    break;
+                                case 1:
+                                    //直角
+                                    imagefilledrectangle($img, $x * $pointSize, $y * $pointSize, ($x + 1) * $pointSize, ($y + 1) * $pointSize, $pointColor);
+                                    break;
+                                case 0:
+                                    //圆圈
+                                    imagefilledellipse($img, ($x * $pointSize) + ($pointSize / 2), ($y * $pointSize) + ($pointSize / 2), $pointSize, $pointSize, $pointColor);
+                                    break;
+                            }
+
+                        } else {
+                            switch ($options['style']) {
+                                case 2:
+                                    //液态
+                                    if ($x === 2 && $y === 2) {
+                                        $this->roundedCorner($img, $x, $y, $s, $inPointColor, true, false, false, false);
+                                    } else if ($x === 2 && $y === 4) {
+                                        $this->roundedCorner($img, $x, $y, $s, $inPointColor, false, true, false, false);
+                                    } else if ($x === 4 && $y === 4) {
+                                        $this->roundedCorner($img, $x, $y, $s, $inPointColor, false, false, true, false);
+                                    } else if ($x === 4 && $y === 2) {
+                                        $this->roundedCorner($img, $x, $y, $s, $inPointColor, false, false, false, true);
+                                    } else {
+                                        imagefilledrectangle($img, $x * $pointSize, $y * $pointSize, ($x + 1) * $pointSize, ($y + 1) * $pointSize, $inPointColor);
+                                    }
+                                    break;
+                                case 1:
+                                    //直角
+                                    imagefilledrectangle($img, $x * $pointSize, $y * $pointSize, ($x + 1) * $pointSize, ($y + 1) * $pointSize, $inPointColor);
+                                    break;
+                                case 0:
+                                    //圆圈
+                                    imagefilledellipse($img, ($x * $pointSize) + ($pointSize / 2), ($y * $pointSize) + ($pointSize / 2), $pointSize, $pointSize, $inPointColor);
+                                    break;
+                            }
+
+                        }
+
+                    } elseif ($x > $imageSize - 8 && $y < 7) { //右上角定点
+
+                        if ($x === $imageSize - 7 || $y === 0 || $x === $imageSize - 1 || $y === 6) {
+                            switch ($options['style']) {
+                                case 2:
+                                    //液态
+                                    if ($x === $imageSize - 7 && $y === 0) {
+                                        $this->roundedCorner($img, $x, $y, $s, $pointColor, true, false, false, false);
+                                    } else if ($x === $imageSize - 7 && $y === 6) {
+                                        $this->roundedCorner($img, $x, $y, $s, $pointColor, false, true, false, false);
+                                    } else if ($x === $imageSize - 1 && $y === 6) {
+                                        $this->roundedCorner($img, $x, $y, $s, $pointColor, false, false, true, false);
+                                    } else if ($x === $imageSize - 1 && $y === 0) {
+                                        $this->roundedCorner($img, $x, $y, $s, $pointColor, false, false, false, true);
+                                    } else {
+                                        imagefilledrectangle($img, $x * $pointSize, $y * $pointSize, ($x + 1) * $pointSize, ($y + 1) * $pointSize, $pointColor);
+                                    }
+                                    break;
+                                case 1:
+                                    //直角
+                                    imagefilledrectangle($img, $x * $pointSize, $y * $pointSize, ($x + 1) * $pointSize, ($y + 1) * $pointSize, $pointColor);
+                                    break;
+                                case 0:
+                                    //圆圈
+                                    imagefilledellipse($img, ($x * $pointSize) + ($pointSize / 2), ($y * $pointSize) + ($pointSize / 2), $pointSize, $pointSize, $pointColor);
+                                    break;
+                            }
+
+                        } else {
+                            switch ($options['style']) {
+                                case 2:
+                                    //液态
+                                    if ($x === $imageSize - 5 && $y === 2) {
+                                        $this->roundedCorner($img, $x, $y, $s, $inPointColor, true, false, false, false);
+                                    } else if ($x === $imageSize - 5 && $y === 4) {
+                                        $this->roundedCorner($img, $x, $y, $s, $inPointColor, false, true, false, false);
+                                    } else if ($x === $imageSize - 3 && $y === 4) {
+                                        $this->roundedCorner($img, $x, $y, $s, $inPointColor, false, false, true, false);
+                                    } else if ($x === $imageSize - 3 && $y === 2) {
+                                        $this->roundedCorner($img, $x, $y, $s, $inPointColor, false, false, false, true);
+                                    } else {
+                                        imagefilledrectangle($img, $x * $pointSize, $y * $pointSize, ($x + 1) * $pointSize, ($y + 1) * $pointSize, $inPointColor);
+                                    }
+                                    break;
+                                case 1:
+                                    //直角
+                                    imagefilledrectangle($img, $x * $pointSize, $y * $pointSize, ($x + 1) * $pointSize, ($y + 1) * $pointSize, $inPointColor);
+                                    break;
+                                case 0:
+                                    //圆圈
+                                    imagefilledellipse($img, ($x * $pointSize) + ($pointSize / 2), ($y * $pointSize) + ($pointSize / 2), $pointSize, $pointSize, $inPointColor);
+                                    break;
+                            }
+                        }
+
+                    } elseif ($y > count($data) - 9 && $x < 7) { //左下角定点
+                        if ($x === 0 || $y === $imageSize - 7 || $x === 6 || $y === $imageSize - 1) {
+                            switch ($options['style']) {
+                                case 2:
+                                    //液态
+                                    if ($x === 0 && $y === $imageSize - 7) {
+                                        $this->roundedCorner($img, $x, $y, $s, $pointColor, true, false, false, false);
+                                    } else if ($x === 0 && $y === $imageSize - 1) {
+                                        $this->roundedCorner($img, $x, $y, $s, $pointColor, false, true, false, false);
+                                    } else if ($x === 6 && $y === $imageSize - 1) {
+                                        $this->roundedCorner($img, $x, $y, $s, $pointColor, false, false, true, false);
+                                    } else if ($x === 6 && $y === $imageSize - 7) {
+                                        $this->roundedCorner($img, $x, $y, $s, $pointColor, false, false, false, true);
+                                    } else {
+                                        imagefilledrectangle($img, $x * $pointSize, $y * $pointSize, ($x + 1) * $pointSize, ($y + 1) * $pointSize, $pointColor);
+                                    }
+                                    break;
+                                case 1:
+                                    //直角
+                                    imagefilledrectangle($img, $x * $pointSize, $y * $pointSize, ($x + 1) * $pointSize, ($y + 1) * $pointSize, $pointColor);
+                                    break;
+                                case 0:
+                                    //圆圈
+                                    imagefilledellipse($img, ($x * $pointSize) + ($pointSize / 2), ($y * $pointSize) + ($pointSize / 2), $pointSize, $pointSize, $pointColor);
+                                    break;
+                            }
+
+
+                        } else {
+                            switch ($options['style']) {
+                                case 2:
+                                    //液态
+                                    if ($x === 2 && $y === $imageSize - 5) {
+                                        $this->roundedCorner($img, $x, $y, $s, $inPointColor, true, false, false, false);
+                                    } else if ($x === 2 && $y === $imageSize - 3) {
+                                        $this->roundedCorner($img, $x, $y, $s, $inPointColor, false, true, false, false);
+                                    } else if ($x === 4 && $y === $imageSize - 3) {
+                                        $this->roundedCorner($img, $x, $y, $s, $inPointColor, false, false, true, false);
+                                    } else if ($x === 4 && $y === $imageSize - 5) {
+                                        $this->roundedCorner($img, $x, $y, $s, $inPointColor, false, false, false, true);
+                                    } else {
+                                        imagefilledrectangle($img, $x * $pointSize, $y * $pointSize, ($x + 1) * $pointSize, ($y + 1) * $pointSize, $inPointColor);
+                                    }
+                                    break;
+                                case 1:
+                                    //直角
+                                    imagefilledrectangle($img, $x * $pointSize, $y * $pointSize, ($x + 1) * $pointSize, ($y + 1) * $pointSize, $inPointColor);
+                                    break;
+                                case 0:
+                                    //圆圈
+                                    imagefilledellipse($img, ($x * $pointSize) + ($pointSize / 2), ($y * $pointSize) + ($pointSize / 2), $pointSize, $pointSize, $inPointColor);
+                                    break;
+                            }
+
+                        }
+
+                    } else {
+                        //液态
+                        switch ($options['style']) {
+                            case 2:
+                                //上
+                                if ($y - 1 < 0) {
+                                    //靠边的块都属于0
+                                    $t = 0;
+                                } else {
+                                    $t = $data[$y - 1][$x];
+                                }
+                                //左上
+                                if ($x - 1 < 0 || $y - 1 < 0) {
+                                    $lt = 0;
+                                } else {
+                                    $lt = $data[$y - 1][$x - 1];
+                                }
+                                //左
+                                if ($x - 1 < 0) {
+                                    $l = 0;
+                                } else {
+                                    $l = $data[$y][$x - 1];
+                                }
+                                //左下
+                                if ($x - 1 < 0 || $y + 1 > $imageSize - 1) {
+                                    $lb = 0;
+                                } else {
+                                    $lb = $data[$y + 1][$x - 1];
+                                }
+                                //下
+                                if ($y + 1 > $imageSize - 1) {
+                                    $b = 0;
+                                } else {
+                                    $b = $data[$y + 1][$x];
+                                }
+                                //右下
+                                if ($x + 1 > $imageSize - 1 || $y + 1 > $imageSize - 1) {
+                                    $rb = 0;
+                                } else {
+                                    $rb = $data[$y + 1][$x + 1];
+                                }
+                                //右
+                                if ($x + 1 > $imageSize - 1) {
+                                    $r = 0;
+                                } else {
+                                    $r = $data[$y][$x + 1];
+                                }
+                                //右上
+                                if ($x + 1 > $imageSize - 1 || $y - 1 < 0) {
+                                    $rt = 0;
+                                } else {
+                                    $rt = $data[$y - 1][$x + 1];
+                                }
+
+                                //上+左+下+右=0 全圆
+                                if ($t == 0 && $l == 0 && $b == 0 && $r == 0) {
+                                    //全圆
+                                    imagefilledellipse($img, ($x * $s) + ($s / 2), ($y * $s) + ($s / 2), $s, $s, $frontColor);
+                                } elseif ($t == 0 && $l == 0 && $r == 0) {
+                                    //上半圆
+                                    $this->halfRounded($img, $x, $y, $s, $frontColor, true, false, false, false);
+                                } elseif ($t == 0 && $l == 0 && $b == 0) {
+                                    //左半圆
+                                    $this->halfRounded($img, $x, $y, $s, $frontColor, false, true, false, false);
+                                } elseif ($l == 0 && $b == 0 && $r == 0) {
+                                    //下半圆
+                                    $this->halfRounded($img, $x, $y, $s, $frontColor, false, false, true, false);
+                                } elseif ($t == 0 && $b == 0 && $r == 0) {
+                                    //右半圆
+                                    $this->halfRounded($img, $x, $y, $s, $frontColor, false, false, false, true);
+                                } elseif ($t == 0 && $l == 0) {
+                                    //左上角
+                                    $this->roundedCorner($img, $x, $y, $s, $frontColor, true, false, false, false);
+                                } elseif ($l == 0 && $b == 0) {
+                                    //左下角
+                                    $this->roundedCorner($img, $x, $y, $s, $frontColor, false, true, false, false);
+                                } elseif ($b == 0 && $r == 0) {
+                                    //右下角
+                                    $this->roundedCorner($img, $x, $y, $s, $frontColor, false, false, true, false);
+                                } elseif ($r == 0 && $t == 0) {
+                                    //右上角
+                                    $this->roundedCorner($img, $x, $y, $s, $frontColor, false, false, false, true);
+                                } else {
+                                    //直角
+                                    imagefilledrectangle($img, $x * $pointSize, $y * $pointSize, ($x + 1) * $pointSize, ($y + 1) * $pointSize, $frontColor);
+
+                                }
+                                break;
+
+                            case 1:
+                                //直角
+                                imagefilledrectangle($img, $x * $pointSize, $y * $pointSize, ($x + 1) * $pointSize, ($y + 1) * $pointSize, $frontColor);
+                                break;
+                            case 0:
+                                //圆圈
+                                imagefilledellipse($img, ($x * $pointSize) + ($pointSize / 2), ($y * $pointSize) + ($pointSize / 2), $pointSize, $pointSize, $frontColor);
+                                break;
+                        }
+                    }
+
+                } else {
+                    if ($x < 7 && $y < 7) {
+
+                    } elseif ($x > $imageSize - 8 && $y < 7) { //右上角定点
+
+                    } elseif ($y > count($data) - 9 && $x < 7) { //左下角定点
+
+                    } else {
+                        if ($options['style'] === 2) {
+                            //液态
+                            //为两个黑块之间的直角填充圆度
+                            //上
+                            if ($y - 1 < 0) {
+                                //靠边的块都属于0
+                                $t = 0;
+                            } else {
+                                $t = $data[$y - 1][$x];
+                            }
+                            //左上
+                            if ($x - 1 < 0 || $y - 1 < 0) {
+                                $lt = 0;
+                            } else {
+                                $lt = $data[$y - 1][$x - 1];
+                            }
+                            //左
+                            if ($x - 1 < 0) {
+                                $l = 0;
+                            } else {
+                                $l = $data[$y][$x - 1];
+                            }
+                            //左下
+                            if ($x - 1 < 0 || $y + 1 > $imageSize - 1) {
+                                $lb = 0;
+                            } else {
+                                $lb = $data[$y + 1][$x - 1];
+                            }
+                            //下
+                            if ($y + 1 > $imageSize - 1) {
+                                $b = 0;
+                            } else {
+                                $b = $data[$y + 1][$x];
+                            }
+                            //右下
+                            if ($x + 1 > $imageSize - 1 || $y + 1 > $imageSize - 1) {
+                                $rb = 0;
+                            } else {
+                                $rb = $data[$y + 1][$x + 1];
+                            }
+                            //右
+                            if ($x + 1 > $imageSize - 1) {
+                                $r = 0;
+                            } else {
+                                $r = $data[$y][$x + 1];
+                            }
+                            //右上
+                            if ($x + 1 > $imageSize - 1 || $y - 1 < 0) {
+                                $rt = 0;
+                            } else {
+                                $rt = $data[$y - 1][$x + 1];
+                            }
+                            $this->halfCorner($img, $x, $y, $s, $bgColor, $frontColor, $lt, $lb, $rb, $rt);
+                            /*
+                            if ($t == 1 && $lt == 1 && $l == 1) {
+                                //左上角
+                                $this->halfCorner($img, $x, $y, $s, $bgColor, $frontColor, true, false, false, false);
+                            }
+
+                            if ($l == 1 && $lb == 1 && $b == 1) {
+                                //左下角
+                                $this->halfCorner($img, $x, $y, $s, $bgColor, $frontColor, false, true, false, false);
+                            }
+                            if ($b == 1 && $rb == 1 && $r == 1) {
+                                //右下角
+                                $this->halfCorner($img, $x, $y, $s, $bgColor, $frontColor, false, false, true, false);
+                            }
+                            if ($r == 1 && $rt == 1 && $t == 1) {
+                                //右上角
+                                $this->halfCorner($img, $x, $y, $s, $bgColor, $frontColor, false, false, false, true);
+                            }
+                            */
+                        }
+
+                    }
+
+                }
+                $x++;
+            }
+            $y++;
+        }
+        //保存图片
+
+        $im = $this->resizeImage($img, $options['width'], $options['width']);
+
+
+        //增加logo
+        if (!empty($options['logo'])) {
+            $im = $this->imageAddLogo($im, $options['logo']);
+        }
+
+
+        //添加背景图
+        if (!empty($options['bg'])) {
+            $im = $this->imageAddBG($im, $options['bg']);
+        }
+        //保存图片
+        header('Content-type:image/png');
+        imagepng($im);
+    }
+
+
+    public function __call($method, $args)
+    {
+        $qrCls = new QRencode();
+        return call_user_func_array(array($qrCls, $method), $args);
+    }
+}

+ 92 - 0
src/Library/QrCode/Edellipse.php

@@ -0,0 +1,92 @@
+<?php
+namespace QrCode;
+
+class Edellipse
+{
+    use Traits\Fill;
+    public $defaults = array(
+        'pointColor' => '#000000', //定点颜色
+        'inPointColor' => '#000000',//内定点
+        'frontColor' => '#000000',//前景色
+        'bgColor' => '#FFFFFF', //背景色
+        'contentColor' => '#000000', //内容颜色
+        'style' => 0,
+    );
+
+    public $pointSize = 3;
+
+    public $options;
+
+    public function __construct($pointSize, $options)
+    {
+        $this->pointSize = $pointSize;
+        $this->options = array_merge($this->defaults, $options);
+        return $this;
+    }
+
+    public function handle($data)
+    {
+
+        $pointColor = $this->hex2rgb($this->options['pointColor']);
+        $inPointColor = $this->hex2rgb($this->options['inPointColor']);
+        $frontColor = $this->hex2rgb($this->options['frontColor']);
+        $bgColor = $this->hex2rgb($this->options['bgColor']);
+        $contentColor = $this->hex2rgb($this->options['contentColor']);
+
+        $w = strlen($data[0]);
+        $h = count($data);
+
+        $imageSize = count($data) - 1;
+        $s = $this->pointSize;//每一块的大小
+
+
+        $img = ImageCreate($w * $this->pointSize, $h * $this->pointSize);
+
+        $bgColor = ImageColorAllocate($img, $bgColor['r'], $bgColor['g'], $bgColor['b']);//背景色
+        $pointColor = ImageColorAllocate($img, $pointColor['r'], $pointColor['g'], $pointColor['b']);//定点色
+        $inPointColor = ImageColorAllocate($img, $inPointColor['r'], $inPointColor['g'], $inPointColor['b']);//内定点
+        $frontColor = ImageColorAllocate($img, $frontColor['r'], $frontColor['g'], $frontColor['b']);//前景色
+        $contentColor = ImageColorAllocate($img, $contentColor['r'], $contentColor['g'], $contentColor['b']);//内容色
+
+        imagefill($img, 0, 0, $bgColor);
+        $y = 0;
+        foreach ($data as $row) {
+            $x = 0;
+            while ($x < $w) {
+                if (substr($row, $x, 1) == "1") {
+                    //返回字符串 string 由 start 和 length 参数指定的子字符串。
+                    //左上角定点
+                    if ($x < 7 && $y < 7) {
+                        //左上角定点的四个大角
+                        if ($x === 0 || $y === 0 || $x === 6 || $y === 6) {
+                            imagefilledellipse($img, ($x * $this->pointSize) + ($this->pointSize / 2), ($y * $this->pointSize) + ($this->pointSize / 2), $this->pointSize, $this->pointSize, $pointColor);
+                        } else {
+                            imagefilledellipse($img, ($x * $this->pointSize) + ($this->pointSize / 2), ($y * $this->pointSize) + ($this->pointSize / 2), $this->pointSize, $this->pointSize, $inPointColor);
+                        }
+
+                    } elseif ($x > $imageSize - 8 && $y < 7) { //右上角定点
+                        if ($x === $imageSize - 7 || $y === 0 || $x === $imageSize - 1 || $y === 6) {
+                            imagefilledellipse($img, ($x * $this->pointSize) + ($this->pointSize / 2), ($y * $this->pointSize) + ($this->pointSize / 2), $this->pointSize, $this->pointSize, $pointColor);
+                        } else {
+                            imagefilledellipse($img, ($x * $this->pointSize) + ($this->pointSize / 2), ($y * $this->pointSize) + ($this->pointSize / 2), $this->pointSize, $this->pointSize, $inPointColor);
+                        }
+
+                    } elseif ($y > count($data) - 9 && $x < 7) { //左下角定点
+                        if ($x === 0 || $y === $imageSize - 7 || $x === 6 || $y === $imageSize - 1) {
+                            imagefilledellipse($img, ($x * $this->pointSize) + ($this->pointSize / 2), ($y * $this->pointSize) + ($this->pointSize / 2), $this->pointSize, $this->pointSize, $pointColor);
+                        } else {
+                            //圆圈
+                            imagefilledellipse($img, ($x * $this->pointSize) + ($this->pointSize / 2), ($y * $this->pointSize) + ($this->pointSize / 2), $this->pointSize, $this->pointSize, $inPointColor);
+                        }
+                    } else {
+                        imagefilledellipse($img, ($x * $this->pointSize) + ($this->pointSize / 2), ($y * $this->pointSize) + ($this->pointSize / 2), $this->pointSize, $this->pointSize, $frontColor);
+                    }
+
+                }
+                $x++;
+            }
+            $y++;
+        }
+        return $img;
+    }
+}

+ 326 - 0
src/Library/QrCode/Liquid.php

@@ -0,0 +1,326 @@
+<?php
+
+namespace QrCode;
+
+class Liquid
+{
+    use Traits\Fill;
+    public $defaults = array(
+        'pointColor' => '#000000', //定点颜色
+        'inPointColor' => '#000000',//内定点
+        'frontColor' => '#000000',//前景色
+        'bgColor' => '#FFFFFF', //背景色
+        'contentColor' => '#000000', //内容颜色
+        'style' => 2,
+    );
+
+    public $pointSize = 3;
+
+    public $options;
+
+    public function __construct($pointSize, $options)
+    {
+        $this->pointSize = $pointSize;
+        $this->options = array_merge($this->defaults, $options);
+        return $this;
+    }
+
+
+    public function handle($data)
+    {
+
+        $pointColor = $this->hex2rgb($this->options['pointColor']);
+        $inPointColor = $this->hex2rgb($this->options['inPointColor']);
+        $frontColor = $this->hex2rgb($this->options['frontColor']);
+        $bgColor = $this->hex2rgb($this->options['bgColor']);
+        $contentColor = $this->hex2rgb($this->options['contentColor']);
+
+        $w = strlen($data[0]);
+        $h = count($data);
+
+        $imageSize = count($data) - 1;
+        $s = $this->pointSize;//每一块的大小
+
+
+        $img = ImageCreate($w * $this->pointSize, $h * $this->pointSize);
+
+        $bgColor = ImageColorAllocate($img, $bgColor['r'], $bgColor['g'], $bgColor['b']);//背景色
+        $pointColor = ImageColorAllocate($img, $pointColor['r'], $pointColor['g'], $pointColor['b']);//定点色
+        $inPointColor = ImageColorAllocate($img, $inPointColor['r'], $inPointColor['g'], $inPointColor['b']);//内定点
+        $frontColor = ImageColorAllocate($img, $frontColor['r'], $frontColor['g'], $frontColor['b']);//前景色
+        $contentColor = ImageColorAllocate($img, $contentColor['r'], $contentColor['g'], $contentColor['b']);//内容色
+
+        imagefill($img, 0, 0, $bgColor);
+        $y = 0;
+        foreach ($data as $row) {
+            $x = 0;
+            while ($x < $w) {
+                if (substr($row, $x, 1) == "1") {
+                    //返回字符串 string 由 start 和 length 参数指定的子字符串。
+                    //左上角定点
+                    if ($x < 7 && $y < 7) {
+                        //左上角定点的四个大角
+                        if ($x === 0 || $y === 0 || $x === 6 || $y === 6) {
+                            //液态
+                            if ($x === 0 && $y === 0) {
+                                $this->roundedCorner($img, $x, $y, $s, $pointColor, true, false, false, false);
+                            } else if ($x === 0 && $y === 6) {
+                                $this->roundedCorner($img, $x, $y, $s, $pointColor, false, true, false, false);
+                            } else if ($x === 6 && $y === 6) {
+                                $this->roundedCorner($img, $x, $y, $s, $pointColor, false, false, true, false);
+                            } else if ($x === 6 && $y === 0) {
+                                $this->roundedCorner($img, $x, $y, $s, $pointColor, false, false, false, true);
+                            } else {
+                                imagefilledrectangle($img, $x * $this->pointSize, $y * $this->pointSize, ($x + 1) * $this->pointSize, ($y + 1) * $this->pointSize, $pointColor);
+                            }
+
+                        } else {
+                            //液态
+                            if ($x === 2 && $y === 2) {
+                                $this->roundedCorner($img, $x, $y, $s, $inPointColor, true, false, false, false);
+                            } else if ($x === 2 && $y === 4) {
+                                $this->roundedCorner($img, $x, $y, $s, $inPointColor, false, true, false, false);
+                            } else if ($x === 4 && $y === 4) {
+                                $this->roundedCorner($img, $x, $y, $s, $inPointColor, false, false, true, false);
+                            } else if ($x === 4 && $y === 2) {
+                                $this->roundedCorner($img, $x, $y, $s, $inPointColor, false, false, false, true);
+                            } else {
+                                imagefilledrectangle($img, $x * $this->pointSize, $y * $this->pointSize, ($x + 1) * $this->pointSize, ($y + 1) * $this->pointSize, $inPointColor);
+                            }
+                        }
+
+                    } elseif ($x > $imageSize - 8 && $y < 7) { //右上角定点
+
+                        if ($x === $imageSize - 7 || $y === 0 || $x === $imageSize - 1 || $y === 6) {
+                            //液态
+                            if ($x === $imageSize - 7 && $y === 0) {
+                                $this->roundedCorner($img, $x, $y, $s, $pointColor, true, false, false, false);
+                            } else if ($x === $imageSize - 7 && $y === 6) {
+                                $this->roundedCorner($img, $x, $y, $s, $pointColor, false, true, false, false);
+                            } else if ($x === $imageSize - 1 && $y === 6) {
+                                $this->roundedCorner($img, $x, $y, $s, $pointColor, false, false, true, false);
+                            } else if ($x === $imageSize - 1 && $y === 0) {
+                                $this->roundedCorner($img, $x, $y, $s, $pointColor, false, false, false, true);
+                            } else {
+                                imagefilledrectangle($img, $x * $this->pointSize, $y * $this->pointSize, ($x + 1) * $this->pointSize, ($y + 1) * $this->pointSize, $pointColor);
+                            }
+                        } else {
+                            //液态
+                            if ($x === $imageSize - 5 && $y === 2) {
+                                $this->roundedCorner($img, $x, $y, $s, $inPointColor, true, false, false, false);
+                            } else if ($x === $imageSize - 5 && $y === 4) {
+                                $this->roundedCorner($img, $x, $y, $s, $inPointColor, false, true, false, false);
+                            } else if ($x === $imageSize - 3 && $y === 4) {
+                                $this->roundedCorner($img, $x, $y, $s, $inPointColor, false, false, true, false);
+                            } else if ($x === $imageSize - 3 && $y === 2) {
+                                $this->roundedCorner($img, $x, $y, $s, $inPointColor, false, false, false, true);
+                            } else {
+                                imagefilledrectangle($img, $x * $this->pointSize, $y * $this->pointSize, ($x + 1) * $this->pointSize, ($y + 1) * $this->pointSize, $inPointColor);
+                            }
+                        }
+
+                    } elseif ($y > count($data) - 9 && $x < 7) { //左下角定点
+                        if ($x === 0 || $y === $imageSize - 7 || $x === 6 || $y === $imageSize - 1) {
+                            //液态
+                            if ($x === 0 && $y === $imageSize - 7) {
+                                $this->roundedCorner($img, $x, $y, $s, $pointColor, true, false, false, false);
+                            } else if ($x === 0 && $y === $imageSize - 1) {
+                                $this->roundedCorner($img, $x, $y, $s, $pointColor, false, true, false, false);
+                            } else if ($x === 6 && $y === $imageSize - 1) {
+                                $this->roundedCorner($img, $x, $y, $s, $pointColor, false, false, true, false);
+                            } else if ($x === 6 && $y === $imageSize - 7) {
+                                $this->roundedCorner($img, $x, $y, $s, $pointColor, false, false, false, true);
+                            } else {
+                                imagefilledrectangle($img, $x * $this->pointSize, $y * $this->pointSize, ($x + 1) * $this->pointSize, ($y + 1) * $this->pointSize, $pointColor);
+                            }
+
+
+                        } else {
+                            //液态
+                            if ($x === 2 && $y === $imageSize - 5) {
+                                $this->roundedCorner($img, $x, $y, $s, $inPointColor, true, false, false, false);
+                            } else if ($x === 2 && $y === $imageSize - 3) {
+                                $this->roundedCorner($img, $x, $y, $s, $inPointColor, false, true, false, false);
+                            } else if ($x === 4 && $y === $imageSize - 3) {
+                                $this->roundedCorner($img, $x, $y, $s, $inPointColor, false, false, true, false);
+                            } else if ($x === 4 && $y === $imageSize - 5) {
+                                $this->roundedCorner($img, $x, $y, $s, $inPointColor, false, false, false, true);
+                            } else {
+                                imagefilledrectangle($img, $x * $this->pointSize, $y * $this->pointSize, ($x + 1) * $this->pointSize, ($y + 1) * $this->pointSize, $inPointColor);
+                            }
+
+                        }
+
+                    } else {
+                        //上
+                        if ($y - 1 < 0) {
+                            //靠边的块都属于0
+                            $t = 0;
+                        } else {
+                            $t = $data[$y - 1][$x];
+                        }
+                        //左上
+                        if ($x - 1 < 0 || $y - 1 < 0) {
+                            $lt = 0;
+                        } else {
+                            $lt = $data[$y - 1][$x - 1];
+                        }
+                        //左
+                        if ($x - 1 < 0) {
+                            $l = 0;
+                        } else {
+                            $l = $data[$y][$x - 1];
+                        }
+                        //左下
+                        if ($x - 1 < 0 || $y + 1 > $imageSize - 1) {
+                            $lb = 0;
+                        } else {
+                            $lb = $data[$y + 1][$x - 1];
+                        }
+                        //下
+                        if ($y + 1 > $imageSize - 1) {
+                            $b = 0;
+                        } else {
+                            $b = $data[$y + 1][$x];
+                        }
+                        //右下
+                        if ($x + 1 > $imageSize - 1 || $y + 1 > $imageSize - 1) {
+                            $rb = 0;
+                        } else {
+                            $rb = $data[$y + 1][$x + 1];
+                        }
+                        //右
+                        if ($x + 1 > $imageSize - 1) {
+                            $r = 0;
+                        } else {
+                            $r = $data[$y][$x + 1];
+                        }
+                        //右上
+                        if ($x + 1 > $imageSize - 1 || $y - 1 < 0) {
+                            $rt = 0;
+                        } else {
+                            $rt = $data[$y - 1][$x + 1];
+                        }
+
+                        //上+左+下+右=0 全圆
+                        if ($t == 0 && $l == 0 && $b == 0 && $r == 0) {
+                            //全圆
+                            imagefilledellipse($img, ($x * $s) + ($s / 2), ($y * $s) + ($s / 2), $s, $s, $frontColor);
+                        } elseif ($t == 0 && $l == 0 && $r == 0) {
+                            //上半圆
+                            $this->halfRounded($img, $x, $y, $s, $frontColor, true, false, false, false);
+                        } elseif ($t == 0 && $l == 0 && $b == 0) {
+                            //左半圆
+                            $this->halfRounded($img, $x, $y, $s, $frontColor, false, true, false, false);
+                        } elseif ($l == 0 && $b == 0 && $r == 0) {
+                            //下半圆
+                            $this->halfRounded($img, $x, $y, $s, $frontColor, false, false, true, false);
+                        } elseif ($t == 0 && $b == 0 && $r == 0) {
+                            //右半圆
+                            $this->halfRounded($img, $x, $y, $s, $frontColor, false, false, false, true);
+                        } elseif ($t == 0 && $l == 0) {
+                            //左上角
+                            $this->roundedCorner($img, $x, $y, $s, $frontColor, true, false, false, false);
+                        } elseif ($l == 0 && $b == 0) {
+                            //左下角
+                            $this->roundedCorner($img, $x, $y, $s, $frontColor, false, true, false, false);
+                        } elseif ($b == 0 && $r == 0) {
+                            //右下角
+                            $this->roundedCorner($img, $x, $y, $s, $frontColor, false, false, true, false);
+                        } elseif ($r == 0 && $t == 0) {
+                            //右上角
+                            $this->roundedCorner($img, $x, $y, $s, $frontColor, false, false, false, true);
+                        } else {
+                            //直角
+                            imagefilledrectangle($img, $x * $this->pointSize, $y * $this->pointSize, ($x + 1) * $this->pointSize, ($y + 1) * $this->pointSize, $frontColor);
+
+                        }
+                    }
+
+                } else {
+                    if ($x < 7 && $y < 7) {
+
+                    } elseif ($x > $imageSize - 8 && $y < 7) { //右上角定点
+
+                    } elseif ($y > count($data) - 9 && $x < 7) { //左下角定点
+
+                    } else {
+                        //液态
+                        //为两个黑块之间的直角填充圆度
+                        //上
+                        if ($y - 1 < 0) {
+                            //靠边的块都属于0
+                            $t = 0;
+                        } else {
+                            $t = $data[$y - 1][$x];
+                        }
+                        //左上
+                        if ($x - 1 < 0 || $y - 1 < 0) {
+                            $lt = 0;
+                        } else {
+                            $lt = $data[$y - 1][$x - 1];
+                        }
+                        //左
+                        if ($x - 1 < 0) {
+                            $l = 0;
+                        } else {
+                            $l = $data[$y][$x - 1];
+                        }
+                        //左下
+                        if ($x - 1 < 0 || $y + 1 > $imageSize - 1) {
+                            $lb = 0;
+                        } else {
+                            $lb = $data[$y + 1][$x - 1];
+                        }
+                        //下
+                        if ($y + 1 > $imageSize - 1) {
+                            $b = 0;
+                        } else {
+                            $b = $data[$y + 1][$x];
+                        }
+                        //右下
+                        if ($x + 1 > $imageSize - 1 || $y + 1 > $imageSize - 1) {
+                            $rb = 0;
+                        } else {
+                            $rb = $data[$y + 1][$x + 1];
+                        }
+                        //右
+                        if ($x + 1 > $imageSize - 1) {
+                            $r = 0;
+                        } else {
+                            $r = $data[$y][$x + 1];
+                        }
+                        //右上
+                        if ($x + 1 > $imageSize - 1 || $y - 1 < 0) {
+                            $rt = 0;
+                        } else {
+                            $rt = $data[$y - 1][$x + 1];
+                        }
+
+                        if ($t == 1 && $lt == 1 && $l == 1) {
+                            //左上角
+                            $this->halfCorner($img, $x, $y, $s, $bgColor, $frontColor, true, false, false, false);
+                        }
+
+                        if ($l == 1 && $lb == 1 && $b == 1) {
+                            //左下角
+                            $this->halfCorner($img, $x, $y, $s, $bgColor, $frontColor, false, true, false, false);
+                        }
+                        if ($b == 1 && $rb == 1 && $r == 1) {
+                            //右下角
+                            $this->halfCorner($img, $x, $y, $s, $bgColor, $frontColor, false, false, true, false);
+                        }
+                        if ($r == 1 && $rt == 1 && $t == 1) {
+                            //右上角
+                            $this->halfCorner($img, $x, $y, $s, $bgColor, $frontColor, false, false, false, true);
+                        }
+                    }
+
+                }
+                $x++;
+            }
+            $y++;
+        }
+        return $img;
+    }
+}

+ 91 - 0
src/Library/QrCode/Rectangle.php

@@ -0,0 +1,91 @@
+<?php
+namespace QrCode;
+
+class Rectangle
+{
+    use Traits\Fill;
+    public $defaults = array(
+        'pointColor' => '#000000', //定点颜色
+        'inPointColor' => '#000000',//内定点
+        'frontColor' => '#000000',//前景色
+        'bgColor' => '#FFFFFF', //背景色
+        'contentColor' => '#000000', //内容颜色
+        'style' => 1,
+    );
+
+    public $pointSize = 3;
+
+    public $options;
+
+    public function __construct($pointSize, $options)
+    {
+        $this->pointSize = $pointSize;
+        $this->options = array_merge($this->defaults, $options);
+        return $this;
+    }
+
+    public function handle($data)
+    {
+        $pointColor = $this->hex2rgb($this->options['pointColor']);
+        $inPointColor = $this->hex2rgb($this->options['inPointColor']);
+        $frontColor = $this->hex2rgb($this->options['frontColor']);
+        $bgColor = $this->hex2rgb($this->options['bgColor']);
+        $contentColor = $this->hex2rgb($this->options['contentColor']);
+
+        $w = strlen($data[0]);
+        $h = count($data);
+
+        $imageSize = count($data) - 1;
+        $s = $this->pointSize;//每一块的大小
+
+
+        $img = ImageCreate($w * $this->pointSize, $h * $this->pointSize);
+
+        $bgColor = ImageColorAllocate($img, $bgColor['r'], $bgColor['g'], $bgColor['b']);//背景色
+        $pointColor = ImageColorAllocate($img, $pointColor['r'], $pointColor['g'], $pointColor['b']);//定点色
+        $inPointColor = ImageColorAllocate($img, $inPointColor['r'], $inPointColor['g'], $inPointColor['b']);//内定点
+        $frontColor = ImageColorAllocate($img, $frontColor['r'], $frontColor['g'], $frontColor['b']);//前景色
+        $contentColor = ImageColorAllocate($img, $contentColor['r'], $contentColor['g'], $contentColor['b']);//内容色
+        
+        $y = 0;
+        foreach ($data as $row) {
+            $x = 0;
+            while ($x < $w) {
+                if (substr($row, $x, 1) == "1") {
+                    //返回字符串 string 由 start 和 length 参数指定的子字符串。
+                    //左上角定点
+                    if ($x < 7 && $y < 7) {
+                        //左上角定点的四个大角
+                        if ($x === 0 || $y === 0 || $x === 6 || $y === 6) {
+                            imagefilledrectangle($img, $x * $this->pointSize, $y * $this->pointSize, ($x + 1) * $this->pointSize, ($y + 1) * $this->pointSize, $pointColor);
+                        } else {
+                            imagefilledrectangle($img, $x * $this->pointSize, $y * $this->pointSize, ($x + 1) * $this->pointSize, ($y + 1) * $this->pointSize, $inPointColor);
+                        }
+
+                    } elseif ($x > $imageSize - 8 && $y < 7) { //右上角定点
+
+                        if ($x === $imageSize - 7 || $y === 0 || $x === $imageSize - 1 || $y === 6) {
+                            imagefilledrectangle($img, $x * $this->pointSize, $y * $this->pointSize, ($x + 1) * $this->pointSize, ($y + 1) * $this->pointSize, $pointColor);
+                        } else {
+                            imagefilledrectangle($img, $x * $this->pointSize, $y * $this->pointSize, ($x + 1) * $this->pointSize, ($y + 1) * $this->pointSize, $inPointColor);
+                        }
+
+                    } elseif ($y > count($data) - 9 && $x < 7) { //左下角定点
+                        if ($x === 0 || $y === $imageSize - 7 || $x === 6 || $y === $imageSize - 1) {
+                            imagefilledrectangle($img, $x * $this->pointSize, $y * $this->pointSize, ($x + 1) * $this->pointSize, ($y + 1) * $this->pointSize, $pointColor);
+                        } else {
+                            imagefilledrectangle($img, $x * $this->pointSize, $y * $this->pointSize, ($x + 1) * $this->pointSize, ($y + 1) * $this->pointSize, $inPointColor);
+                        }
+
+                    } else {
+                        imagefilledrectangle($img, $x * $this->pointSize, $y * $this->pointSize, ($x + 1) * $this->pointSize, ($y + 1) * $this->pointSize, $frontColor);
+                    }
+                }
+                $x++;
+            }
+            $y++;
+        }
+        return $img;
+    }
+
+}

+ 100 - 0
src/Library/QrCode/RoundedCorner.php

@@ -0,0 +1,100 @@
+<?php
+/**
+ * 圆角
+ */
+namespace QrCode;
+
+class RoundedCorner
+{
+    private $_r;
+    private $_g;
+    private $_b;
+    private $_image_path;
+    private $_radius;
+
+    function __construct($image_path, $radius, $r = 255, $g = 0, $b = 0)
+    {
+        $this->_image_path = $image_path;
+        $this->_radius = $radius;
+        $this->_r = (int)$r;
+        $this->_g = (int)$g;
+        $this->_b = (int)$b;
+    }
+
+    private function _get_lt_rounder_corner()
+    {
+        $radius = $this->_radius;
+        //$radius=20;
+        $img = imagecreatetruecolor($radius, $radius);
+
+        $bgcolor = imagecolorallocate($img, $this->_r, $this->_g, $this->_b);
+        $fgcolor = imagecolorallocate($img, 0, 0, 0);
+        imagefill($img, 0, 0, $bgcolor);
+
+        imagefilledarc($img, $radius, $radius, $radius * 2, $radius * 2, 180, 270, $fgcolor, IMG_ARC_PIE);
+        //imagefilledarc在指定的 image 上画一椭圆弧且填充。
+
+        imagecolortransparent($img, $fgcolor);
+        //imagecolortransparent() 将 image 图像中的透明色设定为 color。
+        //image 是 imagecreatetruecolor() 返回的图像标识符,
+        //color 是 imagecolorallocate() 返回的颜色标识符。
+
+        //imagejpeg($img);
+        return $img;
+    }
+
+
+    public function round_it($srcImage, $lt = true, $lb = true, $rb = true, $rt = true)
+    {
+        // load the source image
+        if ($srcImage === false) {
+            die('对不起,图片加载失败');
+        }
+        $imageWidth = imagesx($srcImage);
+        $imageHeight = imagesy($srcImage);
+
+        // create a new image, with src_width, src_height, and fill it with transparent color
+        $image = imagecreatetruecolor($imageWidth, $imageHeight);
+        $transColor = imagecolorallocate($image, $this->_r, $this->_g, $this->_b);
+        imagefill($image, 0, 0, $transColor);
+
+        // then overwirte the source image to the new created image
+        imagecopymerge($image, $srcImage, 0, 0, 0, 0, $imageWidth, $imageHeight, 100);
+
+        // then just copy all the rounded corner images to the 4 corners
+        $radius = $this->_radius;
+        // lt
+        $ltCorner = $this->_get_lt_rounder_corner();
+
+        if ($lt) {
+            imagecopymerge($image, $ltCorner, 0, 0, 0, 0, $radius, $radius, 100);
+        }
+
+        // lb
+        $lb_corner = imagerotate($ltCorner, 90, $transColor);
+        //imagerotate将 srcIm 图像用给定的 angle 角度旋转。bgd_color 指定了旋转后没有覆盖到的部分的颜色。
+        //旋转的中心是图像的中心,旋转后的图像会按比例缩小以适合目标图像的大小——边缘不会被剪去。
+
+        if ($lb) {
+            imagecopymerge($image, $lb_corner, 0, $imageHeight - $radius, 0, 0, $radius, $radius, 100);
+        }
+
+        // rb
+        $rb_corner = imagerotate($ltCorner, 180, $transColor);
+        if ($rb) {
+            imagecopymerge($image, $rb_corner, $imageWidth - $radius, $imageHeight - $radius, 0, 0, $radius, $radius, 100);
+        }
+
+        // rt
+        $rtCorner = imagerotate($ltCorner, 270, $transColor);
+        if ($rt) {
+            imagecopymerge($image, $rtCorner, $imageWidth - $radius, 0, 0, 0, $radius, $radius, 100);
+        }
+
+        // set the transparency
+        imagecolortransparent($image, $transColor);
+
+        return $image;
+
+    }
+}

+ 600 - 0
src/Library/QrCode/test/qrcode.class.php

@@ -0,0 +1,600 @@
+<?php
+define ("QRCODE_DATA_PATH","./Data/qrcode_data");
+/*
+#
+# QRcode class library for PHP4/5  version 0.50beta12 (C)2002-2009,Y.Swetake
+#
+# This version supports QRcode model2 version 1-40.
+# Several functions are not supported.
+#
+*/
+
+class Qrcode{
+
+var $qrcode_error_correct;
+var $qrcode_version;
+
+var $qrcode_structureappend_n;
+var $qrcode_structureappend_m;
+var $qrcode_structureappend_parity;
+var $qrcode_structureappend_originaldata;
+
+public function __construct(){
+    $this->qrcode_error_correct="M";
+    $this->qrcode_version=0;
+
+    $this->qrcode_structureappend_n=0;
+    $this->qrcode_structureappend_m=0;
+    $this->qrcode_structureappend_parity="";
+    $this->qrcode_structureappend_originaldata="";
+}
+
+public function set_qrcode_version($z){
+    if ($z>=0 && $z<=40){
+        $this->qrcode_version=$z;
+    }
+}
+
+public function set_qrcode_error_correct($z){
+    $this->qrcode_error_correct=$z;
+}
+
+public function get_qrcode_version(){
+    return($this->qrcode_version);
+}
+
+public function set_structureappend($m,$n,$p){
+    if ($n>1 && $n<=16 && $m>0 && $m<=16 && $p>=0 && $p<=255){
+        $this->qrcode_structureappend_m=$m;
+        $this->qrcode_structureappend_n=$n;
+        $this->qrcode_structureappend_parity=$p;
+    }
+}
+
+public function cal_structureappend_parity($originaldata){
+    $originaldata_length=strlen($originaldata);
+    if ($originaldata_length>1){
+        $structureappend_parity=0;
+        $i=0;
+        while ($i<$originaldata_length){
+            $structureappend_parity=($structureappend_parity ^ ord(substr($originaldata,$i,1)));
+            $i++;
+        }
+    return($structureappend_parity);
+    }
+}
+
+
+public function cal_qrcode($qrcode_data_string){
+
+    $data_length=strlen($qrcode_data_string);
+    if ($data_length<=0) {
+        trigger_error("Data do not exist.",E_USER_ERROR);
+        exit;
+    }
+    $data_counter=0;
+    if ($this->qrcode_structureappend_n>1){
+
+        $data_value[0]=3;
+        $data_bits[0]=4;
+
+        $data_value[1]=$this->qrcode_structureappend_m-1;
+        $data_bits[1]=4;
+
+        $data_value[2]=$this->qrcode_structureappend_n-1;
+        $data_bits[2]=4;
+
+        $data_value[3]=$this->qrcode_structureappend_parity;
+        $data_bits[3]=8;
+
+        $data_counter=4;
+    }
+
+    $data_bits[$data_counter]=4;
+
+/*  --- determine encode mode */
+
+if (preg_match("/[^0-9]/",$qrcode_data_string)!=0){
+    if (preg_match("/[^0-9A-Z \$\*\%\+\.\/\:\-]/",$qrcode_data_string)!=0) {
+
+            /*  --- 8bit byte mode */
+
+            $codeword_num_plus=array(0,0,0,0,0,0,0,0,0,0,
+8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,
+8,8,8,8,8,8,8,8,8,8,8,8,8,8);
+
+            $data_value[$data_counter]=4;
+            $data_counter++;
+            $data_value[$data_counter]=$data_length;
+            $data_bits[$data_counter]=8;   /* #version 1-9 */
+            $codeword_num_counter_value=$data_counter;
+
+            $data_counter++;
+            $i=0;
+            while ($i<$data_length){
+                $data_value[$data_counter]=ord(substr($qrcode_data_string,$i,1));
+                $data_bits[$data_counter]=8;
+                $data_counter++;
+                $i++;
+            }
+        } else {
+
+    /* ---- alphanumeric mode */
+
+            $codeword_num_plus=array(0,0,0,0,0,0,0,0,0,0,
+2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,
+4,4,4,4,4,4,4,4,4,4,4,4,4,4);
+
+            $data_value[$data_counter]=2;
+            $data_counter++;
+            $data_value[$data_counter]=$data_length;
+            $data_bits[$data_counter]=9;  /* #version 1-9 */
+            $codeword_num_counter_value=$data_counter;
+
+            $alphanumeric_character_hash=array("0"=>0,"1"=>1,"2"=>2,"3"=>3,
+"4"=>4,"5"=>5,"6"=>6,"7"=>7,"8"=>8,"9"=>9,"A"=>10,"B"=>11,"C"=>12,"D"=>13,
+"E"=>14,"F"=>15,"G"=>16,"H"=>17,"I"=>18,"J"=>19,"K"=>20,"L"=>21,"M"=>22,
+"N"=>23,"O"=>24,"P"=>25,"Q"=>26,"R"=>27,"S"=>28,"T"=>29,"U"=>30,"V"=>31,
+"W"=>32,"X"=>33,"Y"=>34,"Z"=>35," "=>36,"$"=>37,"%"=>38,"*"=>39,
+"+"=>40,"-"=>41,"."=>42,"/"=>43,":"=>44);
+
+            $i=0;
+            $data_counter++;
+            while ($i<$data_length){
+                if (($i %2)==0){
+                    $data_value[$data_counter]=$alphanumeric_character_hash[substr($qrcode_data_string,$i,1)];
+                    $data_bits[$data_counter]=6;
+                } else {
+                    $data_value[$data_counter]=$data_value[$data_counter]*45+$alphanumeric_character_hash[substr($qrcode_data_string,$i,1)];
+                    $data_bits[$data_counter]=11;
+                    $data_counter++;
+                }
+                $i++;
+            }
+        }
+    } else {
+
+    /* ---- numeric mode */
+
+        $codeword_num_plus=array(0,0,0,0,0,0,0,0,0,0,
+2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,
+4,4,4,4,4,4,4,4,4,4,4,4,4,4);
+
+        $data_value[$data_counter]=1;
+        $data_counter++;
+        $data_value[$data_counter]=$data_length;
+        $data_bits[$data_counter]=10;   /* #version 1-9 */
+        $codeword_num_counter_value=$data_counter;
+
+        $i=0;
+        $data_counter++;
+        while ($i<$data_length){
+            if (($i % 3)==0){
+                $data_value[$data_counter]=substr($qrcode_data_string,$i,1);
+                $data_bits[$data_counter]=4;
+            } else {
+                $data_value[$data_counter]=$data_value[$data_counter]*10+substr($qrcode_data_string,$i,1);
+                if (($i % 3)==1){
+                    $data_bits[$data_counter]=7;
+                } else {
+                    $data_bits[$data_counter]=10;
+                    $data_counter++;
+                }
+            }
+            $i++;
+        }
+    }
+
+    if (@$data_bits[$data_counter]>0) {
+        $data_counter++;
+    }
+    $i=0;
+    $total_data_bits=0;
+    while($i<$data_counter){
+        $total_data_bits+=$data_bits[$i];
+        $i++;
+    }
+
+
+    $ecc_character_hash=array("L"=>"1",
+"l"=>"1",
+"M"=>"0",
+"m"=>"0",
+"Q"=>"3",
+"q"=>"3",
+"H"=>"2",
+"h"=>"2");
+
+    $ec=@$ecc_character_hash[$this->qrcode_error_correct]; 
+
+    if (!$ec){$ec=0;}
+
+    $max_data_bits_array=array(
+0,128,224,352,512,688,864,992,1232,1456,1728,
+2032,2320,2672,2920,3320,3624,4056,4504,5016,5352,
+5712,6256,6880,7312,8000,8496,9024,9544,10136,10984,
+11640,12328,13048,13800,14496,15312,15936,16816,17728,18672,
+
+152,272,440,640,864,1088,1248,1552,1856,2192,
+2592,2960,3424,3688,4184,4712,5176,5768,6360,6888,
+7456,8048,8752,9392,10208,10960,11744,12248,13048,13880,
+14744,15640,16568,17528,18448,19472,20528,21616,22496,23648,
+
+72,128,208,288,368,480,528,688,800,976,
+1120,1264,1440,1576,1784,2024,2264,2504,2728,3080,
+3248,3536,3712,4112,4304,4768,5024,5288,5608,5960,
+6344,6760,7208,7688,7888,8432,8768,9136,9776,10208,
+
+104,176,272,384,496,608,704,880,1056,1232,
+1440,1648,1952,2088,2360,2600,2936,3176,3560,3880,
+4096,4544,4912,5312,5744,6032,6464,6968,7288,7880,
+8264,8920,9368,9848,10288,10832,11408,12016,12656,13328
+);
+
+    if (!$this->qrcode_version){
+        /* #--- auto version select */
+        $i=1+40*$ec;
+        $j=$i+39;
+        $this->qrcode_version=1; 
+        while ($i<=$j){
+            if (($max_data_bits_array[$i])>=$total_data_bits+$codeword_num_plus[$this->qrcode_version]     ){
+                $max_data_bits=$max_data_bits_array[$i];
+                break;
+            }
+            $i++;
+            $this->qrcode_version++;
+        }
+    } else {
+        $max_data_bits=$max_data_bits_array[$this->qrcode_version+40*$ec];
+    }
+
+    $total_data_bits+=$codeword_num_plus[$this->qrcode_version];
+    $data_bits[$codeword_num_counter_value]+=$codeword_num_plus[$this->qrcode_version];
+
+    $max_codewords_array=array(0,26,44,70,100,134,172,196,242,
+292,346,404,466,532,581,655,733,815,901,991,1085,1156,
+1258,1364,1474,1588,1706,1828,1921,2051,2185,2323,2465,
+2611,2761,2876,3034,3196,3362,3532,3706);
+
+    $max_codewords=$max_codewords_array[$this->qrcode_version];
+    $max_modules_1side=17+($this->qrcode_version <<2);
+
+    $matrix_remain_bit=array(0,0,7,7,7,7,7,0,0,0,0,0,0,0,3,3,3,3,3,3,3,
+4,4,4,4,4,4,4,3,3,3,3,3,3,3,0,0,0,0,0,0);
+
+/* ---- read version ECC data file */
+
+    $byte_num=$matrix_remain_bit[$this->qrcode_version]+($max_codewords << 3);
+    $filename=QRCODE_DATA_PATH."/qrv".$this->qrcode_version."_".$ec.".dat";
+    
+    $fp1 = fopen ($filename, "rb");
+
+        $matx=fread($fp1,$byte_num);
+        $maty=fread($fp1,$byte_num);
+        $masks=fread($fp1,$byte_num);
+        $fi_x=fread($fp1,15);
+        $fi_y=fread($fp1,15);
+        $rs_ecc_codewords=ord(fread($fp1,1));
+        $rso=fread($fp1,128);
+    fclose($fp1);
+    
+   
+    $matrix_x_array=unpack("C*",$matx);
+    $matrix_y_array=unpack("C*",$maty);
+    $mask_array=unpack("C*",$masks);
+
+    $rs_block_order=unpack("C*",$rso);
+
+    $format_information_x2=unpack("C*",$fi_x);
+    $format_information_y2=unpack("C*",$fi_y);
+
+    $format_information_x1=array(0,1,2,3,4,5,7,8,8,8,8,8,8,8,8);
+    $format_information_y1=array(8,8,8,8,8,8,8,8,7,5,4,3,2,1,0);
+
+    $max_data_codewords=($max_data_bits >>3);
+
+    $filename = QRCODE_DATA_PATH."/rsc".$rs_ecc_codewords.".dat";
+    $fp0 = fopen ($filename, "rb");
+    $i=0;
+    while ($i<256) {
+        $rs_cal_table_array[$i]=fread ($fp0,$rs_ecc_codewords);
+        $i++;
+    }
+    fclose ($fp0);
+
+/* -- read frame data  -- */
+
+    $filename = QRCODE_DATA_PATH."/qrvfr".$this->qrcode_version.".dat";
+    $fp0 = fopen ($filename, "rb");
+        $frame_data = fread ($fp0, filesize ($filename));
+    fclose ($fp0);
+
+/*  --- set terminator */
+
+    if ($total_data_bits<=$max_data_bits-4){
+        $data_value[$data_counter]=0;
+        $data_bits[$data_counter]=4;
+    } else {
+        if ($total_data_bits<$max_data_bits){
+	    $data_value[$data_counter]=0;
+            $data_bits[$data_counter]=$max_data_bits-$total_data_bits;
+        } else {
+            if ($total_data_bits>$max_data_bits){
+	        trigger_error("Overflow error",E_USER_ERROR);
+	        exit;
+            }
+        }
+    }
+
+/* ----divide data by 8bit */
+
+$i=0;
+$codewords_counter=0;
+$codewords[0]=0;
+$remaining_bits=8;
+
+while ($i<=$data_counter) {
+    $buffer=@$data_value[$i];
+    $buffer_bits=@$data_bits[$i];
+
+    $flag=1;
+    while ($flag) {
+        if ($remaining_bits>$buffer_bits){  
+            $codewords[$codewords_counter]=((@$codewords[$codewords_counter]<<$buffer_bits) | $buffer);
+            $remaining_bits-=$buffer_bits;
+            $flag=0;
+        } else {
+            $buffer_bits-=$remaining_bits;
+            $codewords[$codewords_counter]=(($codewords[$codewords_counter] << $remaining_bits) | ($buffer >> $buffer_bits));
+
+            if ($buffer_bits==0) {
+                $flag=0;
+            } else {
+                $buffer= ($buffer & ((1 << $buffer_bits)-1) );
+                $flag=1;   
+            }
+
+            $codewords_counter++;
+            if ($codewords_counter<$max_data_codewords-1){
+                $codewords[$codewords_counter]=0;
+            }
+            $remaining_bits=8;
+        }
+    }
+    $i++;
+}
+if ($remaining_bits!=8) {
+    $codewords[$codewords_counter]=$codewords[$codewords_counter] << $remaining_bits;
+} else {
+    $codewords_counter--;
+}
+
+/* ----  set padding character */
+
+if ($codewords_counter<$max_data_codewords-1){
+    $flag=1;
+    while ($codewords_counter<$max_data_codewords-1){
+        $codewords_counter++;
+        if ($flag==1) {
+            $codewords[$codewords_counter]=236;
+        } else {
+            $codewords[$codewords_counter]=17;
+        }
+        $flag=$flag*(-1);
+    }
+}
+
+/* ---- RS-ECC prepare */
+
+$i=0;
+$j=0;
+$rs_block_number=0;
+$rs_temp[0]="";
+
+while($i<$max_data_codewords){
+
+    $rs_temp[$rs_block_number].=chr($codewords[$i]);
+    $j++;
+
+    if ($j>=$rs_block_order[$rs_block_number+1]-$rs_ecc_codewords){
+        $j=0;
+        $rs_block_number++;
+        $rs_temp[$rs_block_number]="";
+    }
+    $i++;
+}
+
+
+/*
+#
+# RS-ECC main
+#
+*/
+
+$rs_block_number=0;
+$rs_block_order_num=count($rs_block_order);
+
+while ($rs_block_number<$rs_block_order_num){
+
+    $rs_codewords=$rs_block_order[$rs_block_number+1];
+    $rs_data_codewords=$rs_codewords-$rs_ecc_codewords;
+
+    $rstemp=$rs_temp[$rs_block_number].str_repeat(chr(0),$rs_ecc_codewords);
+    $padding_data=str_repeat(chr(0),$rs_data_codewords);
+
+    $j=$rs_data_codewords;
+    while($j>0){
+        $first=ord(substr($rstemp,0,1));
+
+        if ($first){
+            $left_chr=substr($rstemp,1);
+            $cal=$rs_cal_table_array[$first].$padding_data;
+            $rstemp=$left_chr ^ $cal;
+        } else {
+            $rstemp=substr($rstemp,1);
+        }
+
+        $j--;
+    }
+
+    $codewords=array_merge($codewords,unpack("C*",$rstemp));
+
+    $rs_block_number++;
+}
+
+/* ---- flash matrix */
+
+$i=0;
+while ($i<$max_modules_1side){
+    $j=0;
+    while ($j<$max_modules_1side){
+        $matrix_content[$j][$i]=0;
+        $j++;
+    }
+    $i++;
+}
+
+/* --- attach data */
+
+$i=0;
+while ($i<$max_codewords){
+    $codeword_i=$codewords[$i];
+    $j=8;
+    while ($j>=1){
+        $codeword_bits_number=($i << 3) +  $j;
+        $matrix_content[ $matrix_x_array[$codeword_bits_number] ][ $matrix_y_array[$codeword_bits_number] ]=((255*($codeword_i & 1)) ^ $mask_array[$codeword_bits_number] ); 
+        $codeword_i= $codeword_i >> 1;
+        $j--;
+    }
+    $i++;
+}
+
+$matrix_remain=$matrix_remain_bit[$this->qrcode_version];
+while ($matrix_remain){
+    $remain_bit_temp = $matrix_remain + ( $max_codewords <<3);
+    $matrix_content[ $matrix_x_array[$remain_bit_temp] ][ $matrix_y_array[$remain_bit_temp] ]  =  ( 255 ^ $mask_array[$remain_bit_temp] );
+    $matrix_remain--;
+}
+
+#--- mask select
+
+$min_demerit_score=0;
+    $hor_master="";
+    $ver_master="";
+    $k=0;
+    while($k<$max_modules_1side){
+        $l=0;
+        while($l<$max_modules_1side){
+            $hor_master=$hor_master.chr($matrix_content[$l][$k]);
+            $ver_master=$ver_master.chr($matrix_content[$k][$l]);
+            $l++;
+        }
+        $k++;
+    }
+$i=0;
+$all_matrix=$max_modules_1side*$max_modules_1side;
+
+while ($i<8){
+    $demerit_n1=0;
+    $ptn_temp=array();
+    $bit= 1<< $i;
+    $bit_r=(~$bit)&255;
+    $bit_mask=str_repeat(chr($bit),$all_matrix);
+    $hor = $hor_master & $bit_mask;
+    $ver = $ver_master & $bit_mask;
+
+    $ver_shift1=$ver.str_repeat(chr(170),$max_modules_1side);
+    $ver_shift2=str_repeat(chr(170),$max_modules_1side).$ver;
+    $ver_or=chunk_split(~($ver_shift1 | $ver_shift2),$max_modules_1side,chr(170));
+    $ver_and=chunk_split(~($ver_shift1 & $ver_shift2),$max_modules_1side,chr(170));
+
+    $hor=chunk_split(~$hor,$max_modules_1side,chr(170));
+    $ver=chunk_split(~$ver,$max_modules_1side,chr(170));
+    $hor=$hor.chr(170).$ver;
+
+    $n1_search="/".str_repeat(chr(255),5)."+|".str_repeat(chr($bit_r),5)."+/";
+    $n3_search=chr($bit_r).chr(255).chr($bit_r).chr($bit_r).chr($bit_r).chr(255).chr($bit_r);
+
+   $demerit_n3=substr_count($hor,$n3_search)*40;
+   $demerit_n4=floor(abs(( (100* (substr_count($ver,chr($bit_r))/($byte_num)) )-50)/5))*10;
+
+
+   $n2_search1="/".chr($bit_r).chr($bit_r)."+/";
+   $n2_search2="/".chr(255).chr(255)."+/";
+   $demerit_n2=0;
+   preg_match_all($n2_search1,$ver_and,$ptn_temp);
+   foreach($ptn_temp[0] as $str_temp){
+       $demerit_n2+=(strlen($str_temp)-1);
+   }
+   $ptn_temp=array();
+   preg_match_all($n2_search2,$ver_or,$ptn_temp);
+   foreach($ptn_temp[0] as $str_temp){
+       $demerit_n2+=(strlen($str_temp)-1);
+   }
+   $demerit_n2*=3;
+  
+   $ptn_temp=array();
+
+   preg_match_all($n1_search,$hor,$ptn_temp);
+   foreach($ptn_temp[0] as $str_temp){
+       $demerit_n1+=(strlen($str_temp)-2);
+   }
+
+   $demerit_score=$demerit_n1+$demerit_n2+$demerit_n3+$demerit_n4;
+
+   if ($demerit_score<=$min_demerit_score || $i==0){
+        $mask_number=$i;
+        $min_demerit_score=$demerit_score;
+   }
+
+$i++;
+}
+
+$mask_content=1 << $mask_number;
+
+# --- format information
+
+$format_information_value=(($ec << 3) | $mask_number);
+$format_information_array=array("101010000010010","101000100100101",
+"101111001111100","101101101001011","100010111111001","100000011001110",
+"100111110010111","100101010100000","111011111000100","111001011110011",
+"111110110101010","111100010011101","110011000101111","110001100011000",
+"110110001000001","110100101110110","001011010001001","001001110111110",
+"001110011100111","001100111010000","000011101100010","000001001010101",
+"000110100001100","000100000111011","011010101011111","011000001101000",
+"011111100110001","011101000000110","010010010110100","010000110000011",
+"010111011011010","010101111101101");
+$i=0;
+while ($i<15){
+    $content=substr($format_information_array[$format_information_value],$i,1);
+
+    $matrix_content[$format_information_x1[$i]][$format_information_y1[$i]]=$content * 255;
+    $matrix_content[$format_information_x2[$i+1]][$format_information_y2[$i+1]]=$content * 255;
+    $i++;
+}
+
+$out="";
+$mxe=$max_modules_1side;
+$i=0;
+while ($i<$mxe){
+    $j=0;
+    while ($j<$mxe){
+        if ($matrix_content[$j][$i] & $mask_content){
+            $out.="1";
+        } else {
+            $out.="0";
+        }
+        $j++;
+    }
+    $out.="\n";
+    $i++;
+   }
+  
+
+$out = $out | $frame_data;
+
+return ($out);
+
+}
+}
+?>

+ 734 - 0
src/Library/QrCode/test/qrcode_img.class.php

@@ -0,0 +1,734 @@
+<?php
+/*
+#
+# QRcode image class library for PHP4  version 0.50beta9 (C)2002-2004,Y.Swetake
+#
+# This version supports QRcode model2 version 1-40.
+#
+*/
+//require "qrcode.php";
+//require "RoundedCorner.php";
+
+class Qrcode_image extends Qrcode{
+
+    var $module_size;
+    var $quiet_zone;
+    var $qrcode_version;
+
+    public function __construct(){
+       parent::__construct();
+       //$this->module_size=10;
+       $this->module_size=25;
+       
+       $this->quiet_zone=4;
+
+    }
+
+    public function set_module_size($z){
+        if ($z>0 && $z<9){
+            $this->module_size=$z;
+        }    
+    }
+
+    public function set_quietzone($z){
+        if ($z>0 && $z<9){
+            $this->quiet_zone=$z;
+        }
+    }
+   
+    /**
+     * 输出二维码
+     * @param type $org_data
+     * @param type $filename 图片名
+     * @param type $filetype 图片后缀
+     * @param type $imgwh 图片大小
+     * @param type $filelogo 图片logo
+     * @param type $ptcolor 定点
+     * @param type $inptcolor 内定点
+     * @param type $fcolor 前景色
+     * @param type $bcolor 背景色
+     * @param type $ccolor 内容
+     * @param type $style 样式:2液态 1直角 0圆角
+     */
+    public function qrcode_image_out($org_data,$filename='Uploads/yufu.png',$imgwh=380,$filelogo='',$filebg='',$ptcolor='#000000',$inptcolor='#000000',$fcolor='#000000',$bcolor='#FFFFFF',$ccolor='#000000',$style=1){
+        
+        
+        //生成二维码
+        $im=$this->mkimage($this->cal_qrcode($org_data),$ptcolor,$inptcolor,$fcolor,$bcolor,$ccolor,$style);
+
+        //保存原图
+        //imagepng($im, "src.png");
+        
+        //对原图按要求进行缩放
+        $im=$this->resizeImage($im,$imgwh,$imgwh);
+        $w=  imagesx($im);
+        $h=  imagesy($im);
+        
+        
+        //增加logo
+        if(!empty($filelogo)){
+            $im=$this->imageaddlogo($im,$filelogo);
+        }
+        
+
+        //添加背景图
+        if(!empty($filebg)){
+            $im=$this->imageaddbg($im,$filebg);
+        }
+        
+        //保存图片
+        
+        imagepng($im, $filename);
+    }
+
+    public function mkimage($data,$ptcolor,$inptcolor,$fcolor,$bcolor,$ccolor,$style){
+        
+        $data_array=explode("\n",$data);
+        
+        $ptcolor= $this->hex2rgb($ptcolor);
+        $inptcolor=  $this->hex2rgb($inptcolor);
+        $fcolor=  $this->hex2rgb($fcolor);
+        $bcolor=  $this->hex2rgb($bcolor);
+        $ccolor=  $this->hex2rgb($ccolor);
+
+        
+        
+        $image_size=$c=count($data_array)-1;
+        //$image_size=$c;
+        $s=$this->module_size;//每一块的大小
+        
+        $output_size=$image_size*$this->module_size;
+
+        
+        $img=ImageCreate($output_size,$output_size);
+        $bcolor = ImageColorAllocate ($img, $bcolor['r'], $bcolor['g'], $bcolor['b']);//背景色
+        $ptcolor = ImageColorAllocate ($img, $ptcolor['r'], $ptcolor['g'], $ptcolor['b']);//定点色
+        $inptcolor = ImageColorAllocate ($img, $inptcolor['r'], $inptcolor['g'], $inptcolor['b']);//内定点
+        $fcolor = ImageColorAllocate ($img, $fcolor['r'], $fcolor['g'], $fcolor['b']);//前景色
+        $ccolor = ImageColorAllocate ($img, $ccolor['r'], $ccolor['g'], $ccolor['b']);//内容色
+        
+        //imagecolorallocate() 返回一个标识符,代表了由给定的 RGB 成分组成的颜色。red,green 和 blue 分别是所需要的颜色的红,绿,蓝成分。这些参数是 0 到 255 的整数或者十六进制的 0x00 到 0xFF。 imagecolorallocate() 必须被调用以创建每一种用在 image 所代表的图像中的颜色。
+        //第一次对 imagecolorallocate() 的调用会给基于调色板的图像填充背景色,即用 imagecreate() 建立的图像。
+        
+        
+        $y=0;
+        foreach($data_array as $row){
+            
+            $x=0;
+            while ($x<$image_size){
+                 if (substr($row,$x,1)=="1"){
+                     //返回字符串 string 由 start 和 length 参数指定的子字符串。
+                     
+                        //左上角定点
+                        if($x<7&&$y<7){
+                            //左上角定点的四个大角
+                            if($x===0||$y===0||$x===6||$y===6){
+                                switch ($style) {
+                                    case 2:
+                                         //液态
+                                        if($x===0&&$y===0){
+                                            $this->roundedcorner($img,$x,$y,$s,$ptcolor,TRUE,FALSE,FALSE,FALSE);
+                                        }else if ($x===0&&$y===6) {
+                                            $this->roundedcorner($img,$x,$y,$s,$ptcolor,FALSE,TRUE,FALSE,FALSE);
+                                        }else if($x===6&&$y===6){
+                                            $this->roundedcorner($img,$x,$y,$s,$ptcolor,FALSE,FALSE,TRUE,FALSE);
+                                        }else if ($x===6&&$y===0) {
+                                            $this->roundedcorner($img,$x,$y,$s,$ptcolor,FALSE,FALSE,FALSE,TRUE);
+                                        }else {
+                                            imagefilledrectangle ( $img , $x*$this->module_size , $y*$this->module_size , ($x+1)*$this->module_size , ($y+1)*$this->module_size , $ptcolor);
+
+                                        }
+                                        break;
+                                    case 1:
+                                        //直角
+                                        imagefilledrectangle ( $img , $x*$this->module_size , $y*$this->module_size , ($x+1)*$this->module_size , ($y+1)*$this->module_size , $ptcolor);
+                                        break;
+                                    case 0:
+                                        //圆圈
+                                        imagefilledellipse ($img, ($x*$this->module_size)+($this->module_size/2), ($y*$this->module_size)+($this->module_size/2), $this->module_size, $this->module_size, $ptcolor );
+                                        break;
+                                }
+                                
+                            }else{
+                                switch ($style) {
+                                    case 2:
+                                        //液态
+                                        if($x===2&&$y===2){
+                                            $this->roundedcorner($img,$x,$y,$s,$inptcolor,TRUE,FALSE,FALSE,FALSE);
+                                        }else if ($x===2&&$y===4) {
+                                            $this->roundedcorner($img,$x,$y,$s,$inptcolor,FALSE,TRUE,FALSE,FALSE);
+                                        }else if($x===4&&$y===4){
+                                            $this->roundedcorner($img,$x,$y,$s,$inptcolor,FALSE,FALSE,TRUE,FALSE);
+                                        }else if ($x===4&&$y===2) {
+                                            $this->roundedcorner($img,$x,$y,$s,$inptcolor,FALSE,FALSE,FALSE,TRUE);
+                                        }else {
+                                           imagefilledrectangle ( $img , $x*$this->module_size , $y*$this->module_size , ($x+1)*$this->module_size , ($y+1)*$this->module_size , $inptcolor);
+                                        }
+                                        break;
+                                    case 1:
+                                        //直角
+                                        imagefilledrectangle ( $img , $x*$this->module_size , $y*$this->module_size , ($x+1)*$this->module_size , ($y+1)*$this->module_size , $inptcolor);
+                                        break;
+                                    case 0:
+                                        //圆圈
+                                        imagefilledellipse ($img, ($x*$this->module_size)+($this->module_size/2), ($y*$this->module_size)+($this->module_size/2), $this->module_size, $this->module_size, $inptcolor );
+                                        break;
+                                }
+                                 
+                            }
+                            
+                        } elseif ($x>$image_size-8&&$y<7) { //右上角定点
+                            
+                            if($x===$image_size-7||$y===0||$x===$image_size-1||$y===6){
+                                switch ($style) {
+                                    case 2:
+                                        //液态
+                                        if($x===$image_size-7&&$y===0){
+                                            $this->roundedcorner($img,$x,$y,$s,$ptcolor,TRUE,FALSE,FALSE,FALSE);
+                                        }else if ($x===$image_size-7&&$y===6) {
+                                            $this->roundedcorner($img,$x,$y,$s,$ptcolor,FALSE,TRUE,FALSE,FALSE);
+                                        }else if($x===$image_size-1&&$y===6){
+                                            $this->roundedcorner($img,$x,$y,$s,$ptcolor,FALSE,FALSE,TRUE,FALSE);
+                                        }else if ($x===$image_size-1&&$y===0) {
+                                            $this->roundedcorner($img,$x,$y,$s,$ptcolor,FALSE,FALSE,FALSE,TRUE);
+                                        }else {
+                                            imagefilledrectangle ( $img , $x*$this->module_size , $y*$this->module_size , ($x+1)*$this->module_size , ($y+1)*$this->module_size , $ptcolor);
+                                        }
+                                        break;
+                                    case 1:
+                                        //直角
+                                        imagefilledrectangle ( $img , $x*$this->module_size , $y*$this->module_size , ($x+1)*$this->module_size , ($y+1)*$this->module_size , $ptcolor);
+                                        break;
+                                    case 0:
+                                        //圆圈                                
+                                        imagefilledellipse ($img, ($x*$this->module_size)+($this->module_size/2), ($y*$this->module_size)+($this->module_size/2), $this->module_size, $this->module_size, $ptcolor );
+                                        break;
+                                }
+                                 
+                               }else{
+                                   switch ($style) {
+                                       case 2:
+                                           //液态
+                                            if($x===$image_size-5&&$y===2){
+                                                $this->roundedcorner($img,$x,$y,$s,$inptcolor,TRUE,FALSE,FALSE,FALSE);
+                                            }else if ($x===$image_size-5&&$y===4) {
+                                                $this->roundedcorner($img,$x,$y,$s,$inptcolor,FALSE,TRUE,FALSE,FALSE);
+                                            }else if($x===$image_size-3&&$y===4){
+                                                $this->roundedcorner($img,$x,$y,$s,$inptcolor,FALSE,FALSE,TRUE,FALSE);
+                                            }else if ($x===$image_size-3&&$y===2) {
+                                                $this->roundedcorner($img,$x,$y,$s,$inptcolor,FALSE,FALSE,FALSE,TRUE);
+                                            }else {
+                                                imagefilledrectangle ( $img , $x*$this->module_size , $y*$this->module_size , ($x+1)*$this->module_size , ($y+1)*$this->module_size , $inptcolor);
+                                            }
+                                           break;
+                                       case 1:
+                                           //直角
+                                            imagefilledrectangle ( $img , $x*$this->module_size , $y*$this->module_size , ($x+1)*$this->module_size , ($y+1)*$this->module_size , $inptcolor);
+                                           break;
+                                       case 0:
+                                            //圆圈                                
+                                            imagefilledellipse ($img, ($x*$this->module_size)+($this->module_size/2), ($y*$this->module_size)+($this->module_size/2), $this->module_size, $this->module_size, $inptcolor );
+                                           break;
+                                   }
+                                 
+                                
+                            }
+                            
+                        } elseif ($y>count($data_array)-9&&$x<7) { //左下角定点
+                            
+                            if($x===0||$y===$image_size-7||$x===6||$y===$image_size-1){
+                                switch ($style) {
+                                    case 2:
+                                        //液态
+                                        if($x===0&&$y===$image_size-7){
+                                            $this->roundedcorner($img,$x,$y,$s,$ptcolor,TRUE,FALSE,FALSE,FALSE);
+                                        }else if ($x===0&&$y===$image_size-1) {
+                                            $this->roundedcorner($img,$x,$y,$s,$ptcolor,FALSE,TRUE,FALSE,FALSE);
+                                        }else if($x===6&&$y===$image_size-1){
+                                            $this->roundedcorner($img,$x,$y,$s,$ptcolor,FALSE,FALSE,TRUE,FALSE);
+                                        }else if ($x===6&&$y===$image_size-7) {
+                                            $this->roundedcorner($img,$x,$y,$s,$ptcolor,FALSE,FALSE,FALSE,TRUE);
+                                        }else {
+                                            imagefilledrectangle ( $img , $x*$this->module_size , $y*$this->module_size , ($x+1)*$this->module_size , ($y+1)*$this->module_size , $ptcolor);
+                                        }
+                                        break;
+                                    case 1:
+                                        //直角
+                                        imagefilledrectangle ( $img , $x*$this->module_size , $y*$this->module_size , ($x+1)*$this->module_size , ($y+1)*$this->module_size , $ptcolor);
+                                        break;
+                                    case 0:
+                                        //圆圈                                
+                                        imagefilledellipse ($img, ($x*$this->module_size)+($this->module_size/2), ($y*$this->module_size)+($this->module_size/2), $this->module_size, $this->module_size, $ptcolor );
+                                        break;
+                                }
+                                
+                                
+                                }  else {
+                                    switch ($style) {
+                                        case 2:
+                                            //液态
+                                            if($x===2&&$y===$image_size-5){
+                                                $this->roundedcorner($img,$x,$y,$s,$inptcolor,TRUE,FALSE,FALSE,FALSE);
+                                            }else if ($x===2&&$y===$image_size-3) {
+                                                $this->roundedcorner($img,$x,$y,$s,$inptcolor,FALSE,TRUE,FALSE,FALSE);
+                                            }else if($x===4&&$y===$image_size-3){
+                                                $this->roundedcorner($img,$x,$y,$s,$inptcolor,FALSE,FALSE,TRUE,FALSE);
+                                            }else if ($x===4&&$y===$image_size-5) {
+                                                $this->roundedcorner($img,$x,$y,$s,$inptcolor,FALSE,FALSE,FALSE,TRUE);
+                                            }else {
+                                                imagefilledrectangle ( $img , $x*$this->module_size , $y*$this->module_size , ($x+1)*$this->module_size , ($y+1)*$this->module_size , $inptcolor);
+                                            }
+                                            break;
+                                        case 1:
+                                            //直角
+                                            imagefilledrectangle ( $img , $x*$this->module_size , $y*$this->module_size , ($x+1)*$this->module_size , ($y+1)*$this->module_size , $inptcolor);
+                                            break;
+                                        case 0:
+                                            //圆圈
+                                            imagefilledellipse ($img, ($x*$this->module_size)+($this->module_size/2), ($y*$this->module_size)+($this->module_size/2), $this->module_size, $this->module_size, $inptcolor );
+                            
+                                            break;
+                                    }
+
+                                }
+                            
+                        } else {
+                            //液态
+                            switch ($style) {
+                                case 2:
+                                    //上
+                                    if($y-1<0){
+                                        //靠边的块都属于0
+                                        $t=0;
+                                    }else{
+                                        $t= $data_array[$y-1][$x];
+                                    }
+                                    //左上
+                                    if($x-1<0||$y-1<0){
+                                        $lt=0;
+                                    }  else {
+                                        $lt= $data_array[$y-1][$x-1];
+                                    }
+                                    //左
+                                    if($x-1<0){
+                                        $l=0;
+                                    }else{
+                                        $l= $data_array[$y][$x-1];
+                                    }
+                                    //左下
+                                    if($x-1<0||$y+1>$image_size-1){
+                                        $lb=0;
+                                    }else{
+                                        $lb= $data_array[$y+1][$x-1];
+                                    }
+                                    //下
+                                    if($y+1>$image_size-1){
+                                        $b=0;
+                                    }  else {
+                                        $b= $data_array[$y+1][$x];
+                                    }
+                                    //右下
+                                    if($x+1>$image_size-1||$y+1>$image_size-1){
+                                        $rb=0;
+                                    }  else {
+                                        $rb= $data_array[$y+1][$x+1];
+                                    }
+                                    //右
+                                    if($x+1>$image_size-1){
+                                        $r=0;
+                                    }else{
+                                        $r= $data_array[$y][$x+1];
+                                    }
+                                    //右上
+                                    if($x+1>$image_size-1||$y-1<0){
+                                        $rt= 0;
+                                    }else{
+                                        $rt= $data_array[$y-1][$x+1];
+                                    }
+
+                                    //上+左+下+右=0 全圆
+                                    if($t==0&&$l==0&&$b==0&&$r==0){
+                                        //全圆
+                                        imagefilledellipse ($img, ($x*$s)+($s/2), ($y*$s)+($s/2), $s, $s, $fcolor );  
+                                    }elseif ($t==0&&$l==0&&$r==0) {
+                                        //上半圆
+                                        $this->halfrounded($img,$x,$y,$s,$fcolor,TRUE,FALSE,FALSE,FALSE); 
+                                    }elseif($t==0&&$l==0&&$b==0){
+                                        //左半圆
+                                        $this->halfrounded($img,$x,$y,$s,$fcolor,FALSE,TRUE,FALSE,FALSE); 
+                                    }elseif ($l==0&&$b==0&&$r==0) {
+                                        //下半圆
+                                        $this->halfrounded($img,$x,$y,$s,$fcolor,FALSE,FALSE,TRUE,FALSE); 
+                                    }elseif ($t==0&&$b==0&&$r==0) {
+                                        //右半圆
+                                        $this->halfrounded($img,$x,$y,$s,$fcolor,FALSE,FALSE,FALSE,TRUE);                    
+                                    }elseif ($t==0&&$l==0) {
+                                        //左上角
+                                        $this->roundedcorner($img,$x,$y,$s,$fcolor,TRUE,FALSE,FALSE,FALSE);
+                                    }elseif ($l==0&&$b==0) {
+                                        //左下角
+                                        $this->roundedcorner($img,$x,$y,$s,$fcolor,FALSE,TRUE,FALSE,FALSE);
+                                    }elseif($b==0&&$r==0){
+                                        //右下角
+                                        $this->roundedcorner($img,$x,$y,$s,$fcolor,FALSE,FALSE,TRUE,FALSE);
+                                    }elseif ($r==0&&$t==0) {
+                                        //右上角
+                                        $this->roundedcorner($img,$x,$y,$s,$fcolor,FALSE,FALSE,FALSE,TRUE);
+                                    }else{
+                                        //直角
+                                        imagefilledrectangle ( $img , $x*$this->module_size , $y*$this->module_size , ($x+1)*$this->module_size , ($y+1)*$this->module_size , $fcolor);
+
+                                    }
+                                    break;
+
+                                case 1:
+                                     //直角
+                                    imagefilledrectangle ( $img , $x*$this->module_size , $y*$this->module_size , ($x+1)*$this->module_size , ($y+1)*$this->module_size , $fcolor);
+                                    break;
+                                case 0:
+                                    //圆圈
+                                    imagefilledellipse ($img, ($x*$this->module_size)+($this->module_size/2), ($y*$this->module_size)+($this->module_size/2), $this->module_size, $this->module_size, $fcolor );
+                                    break;
+                            }
+                        }
+                     
+                     
+                 }else{
+                     if($x<7&&$y<7){
+                         
+                     }elseif ($x>$image_size-8&&$y<7) { //右上角定点
+                         
+                     }elseif ($y>count($data_array)-9&&$x<7) { //左下角定点
+                         
+                     }else {
+                         if($style===2){
+                            //液态
+                            //为两个黑块之间的直角填充圆度
+                            //上
+                            if($y-1<0){
+                                //靠边的块都属于0
+                                $t=0;
+                            }else{
+                                $t= $data_array[$y-1][$x];
+                            }
+                            //左上
+                            if($x-1<0||$y-1<0){
+                                $lt=0;
+                            }  else {
+                                $lt= $data_array[$y-1][$x-1];
+                            }
+                            //左
+                            if($x-1<0){
+                                $l=0;
+                            }else{
+                                $l= $data_array[$y][$x-1];
+                            }
+                            //左下
+                            if($x-1<0||$y+1>$image_size-1){
+                                $lb=0;
+                            }else{
+                                $lb= $data_array[$y+1][$x-1];
+                            }
+                            //下
+                            if($y+1>$image_size-1){
+                                $b=0;
+                            }  else {
+                                $b= $data_array[$y+1][$x];
+                            }
+                            //右下
+                            if($x+1>$image_size-1||$y+1>$image_size-1){
+                                $rb=0;
+                            }  else {
+                                $rb= $data_array[$y+1][$x+1];
+                            }
+                            //右
+                            if($x+1>$image_size-1){
+                                $r=0;
+                            }else{
+                                $r= $data_array[$y][$x+1];
+                            }
+                            //右上
+                            if($x+1>$image_size-1||$y-1<0){
+                                $rt= 0;
+                            }else{
+                                $rt= $data_array[$y-1][$x+1];
+                            }
+                            if ($t==1&&$lt==1&&$l==1) {
+                                //左上角
+                                $this->halfcorner($img,$x,$y,$s,$bcolor,$fcolor,TRUE,FALSE,FALSE,FALSE);
+                            }
+
+                            if ($l==1&&$lb==1&&$b==1) {
+                                //左下角
+                                $this->halfcorner($img,$x,$y,$s,$bcolor,$fcolor,FALSE,TRUE,FALSE,FALSE);
+                            }
+                            if($b==1&&$rb==1&&$r==1){
+                                //右下角
+                                $this->halfcorner($img,$x,$y,$s,$bcolor,$fcolor,FALSE,FALSE,TRUE,FALSE);
+                            }
+                            if ($r==1&&$rt==1&&$t==1) {
+                                //右上角
+                                $this->halfcorner($img,$x,$y,$s,$bcolor,$fcolor,FALSE,FALSE,FALSE,TRUE);
+                            }
+                         }
+                         
+                     }
+
+                 }
+                 $x++;
+            }
+            $y++;
+        }
+
+        return($img);
+
+    }
+    //半角
+    public function halfcorner($img,$x,$y,$s,$bcolor,$fcolor,$lt=TRUE,$lb=TRUE,$rb=TRUE,$rt=TRUE) {
+        //左上半角
+        if($lt){
+            imagefilledarc($img, $x*$s, $y*$s, $s/2, $s/2, 0, 90, $fcolor, IMG_ARC_PIE);
+            imagefilledarc($img, $x*$s+$s/4, $y*$s+$s/4, $s/2, $s/2, 180, 270, $bcolor, IMG_ARC_PIE);
+        }
+        //左下半角
+        if($lb){
+            imagefilledarc($img, $x*$s, ($y+1)*$s, $s/2, $s/2, 270, 360, $fcolor, IMG_ARC_PIE);
+            imagefilledarc($img, $x*$s+$s/4, ($y+1)*$s-$s/4, $s/2, $s/2, 90, 180, $bcolor, IMG_ARC_PIE);
+        }
+        //右下半角
+        if($rb){
+            imagefilledarc($img, ($x+1)*$s, ($y+1)*$s, $s/2, $s/2, 180, 270, $fcolor, IMG_ARC_PIE);
+            imagefilledarc($img, ($x+1)*$s-$s/4, ($y+1)*$s-$s/4, $s/2, $s/2, 0, 90, $bcolor, IMG_ARC_PIE);
+            
+        }
+        //右上半角
+        if($rt){
+            imagefilledarc($img, ($x+1)*$s, $y*$s, ($s/2), ($s/2), 90, 180,$fcolor , IMG_ARC_PIE);
+            imagefilledarc($img, ($x+1)*$s-($s/4), $y*$s+($s/4), ($s/2), ($s/2), 270, 360, $bcolor, IMG_ARC_PIE);
+        }
+        
+    }
+    //半圆
+    public function halfrounded($img,$x,$y,$s,$color,$t=TRUE,$l=TRUE,$b=TRUE,$r=TRUE) {
+        //上半圆
+        if($t){
+            imagefilledarc($img, ($x*$s)+($s/2), ($y*$s)+($s/2), $s, $s, 180, 270, $color, IMG_ARC_PIE);
+            imagefilledarc($img, ($x*$s)+($s/2), ($y*$s)+($s/2), $s, $s, 270, 360, $color, IMG_ARC_PIE);
+            imagefilledrectangle ($img , $x*$s , ($y*$s)+($s/2) , ($x+1)*$s , ($y+1)*$s , $color);
+        }
+        //左半圆
+        if($l){
+            imagefilledarc($img, ($x*$s)+($s/2), ($y*$s)+($s/2), $s, $s, 90, 180, $color, IMG_ARC_PIE);
+            imagefilledarc($img, ($x*$s)+($s/2), ($y*$s)+($s/2), $s, $s, 180, 270, $color, IMG_ARC_PIE);
+            imagefilledrectangle ($img , ($x*$s)+($s/2) , ($y*$s) , ($x+1)*$s , ($y+1)*$s , $color);
+        }
+        
+        //下半圆
+        if($b){
+            imagefilledarc($img, ($x*$s)+($s/2), ($y*$s)+($s/2), $s, $s, 0, 90, $color, IMG_ARC_PIE);
+            imagefilledarc($img, ($x*$s)+($s/2), ($y*$s)+($s/2), $s, $s, 90, 180, $color, IMG_ARC_PIE);
+            imagefilledrectangle ($img , $x*$s , $y*$s , ($x+1)*$s , ($y*$s)+($s/2) , $color);
+        }
+        //右半圆
+        if($r){
+            imagefilledarc($img, ($x*$s)+($s/2), ($y*$s)+($s/2), $s, $s, 270, 360, $color, IMG_ARC_PIE);
+            imagefilledarc($img, ($x*$s)+($s/2), ($y*$s)+($s/2), $s, $s, 0, 90, $color, IMG_ARC_PIE);
+            imagefilledrectangle ($img , $x*$s , $y*$s , ($x*$s)+($s/2) , ($y+1)*$s , $color);
+            
+        }
+    }
+    //圆角
+    public function roundedcorner($img,$x,$y,$s,$color,$lt=TRUE,$lb=TRUE,$rb=TRUE,$rt=TRUE) {
+        if($lt){
+            imagefilledarc($img, ($x*$s)+($s/2), ($y*$s)+($s/2), $s, $s, 180, 270, $color, IMG_ARC_PIE);
+            $values = array(($x+1)*$s,($y*$s),($x+1)*$s,($y+1)*$s,($x*$s),($y+1)*$s,);
+            $values1 = array(($x*$s),($y+1)*$s,($x*$s)+($s/2),($y*$s)+($s/2),($x*$s),($y*$s)+($s/2),);
+            $values2 = array(($x*$s)+($s/2),($y*$s)+($s/2),($x*$s)+($s/2),($y*$s),($x+1)*$s,($y*$s),);
+            imagefilledpolygon($img, $values, 3, $color);
+            imagefilledpolygon($img, $values1, 3, $color);
+            imagefilledpolygon($img, $values2, 3, $color);
+        }
+        if($lb){
+            imagefilledarc($img, ($x*$s)+($s/2), ($y*$s)+($s/2), $s, $s, 90, 180, $color, IMG_ARC_PIE);
+            $values = array($x*$s,$y*$s,$x*$s+$s,$y*$s,$x*$s+$s,($y+1)*$s,);
+            $values1 = array($x*$s,$y*$s,$x*$s,$y*$s+($s/2),$x*$s+$s,$y*$s+($s/2),);
+            $values2 = array($x*$s+($s/2),$y*$s+($s/2),$x*$s+($s/2),($y+1)*$s,$x*$s+$s,($y+1)*$s,);
+            imagefilledpolygon($img, $values, 3, $color);
+            imagefilledpolygon($img, $values1, 3, $color);
+            imagefilledpolygon($img, $values2, 3, $color);
+        }
+        if($rb){
+            imagefilledarc($img, ($x*$s)+($s/2), $y*$s+($s/2), $s, $s, 360, 90, $color, IMG_ARC_PIE);
+            $values = array($x*$s,($y+1)*$s,$x*$s,$y*$s,($x+1)*$s,$y*$s,);
+            $values1 = array($x*$s,($y+1)*$s,$x*$s+($s/2),$y*$s+($s/2),$x*$s+($s/2),($y+1)*$s,);
+            $values2 = array($x*$s+($s/2),$y*$s+($s/2),($x+1)*$s,$y*$s,($x+1)*$s,$y*$s+($s/2),);
+            imagefilledpolygon($img, $values, 3, $color);
+            imagefilledpolygon($img, $values1, 3, $color);
+            imagefilledpolygon($img, $values2, 3, $color);
+        }
+        if($rt){
+            imagefilledarc($img, ($x*$s)+($s/2), $y*$s+($s/2), $s, $s, 270, 360, $color, IMG_ARC_PIE);
+            $values = array($x*$s,$y*$s,$x*$s,$y*$s+$s,($x+1)*$s,$y*$s+$s,);
+            $values1 = array($x*$s,$y*$s,$x*$s+($s/2),$y*$s,$x*$s+($s/2),$y*$s+($s/2),);
+            $values2 = array($x*$s+($s/2),$y*$s+($s/2),($x+1)*$s,$y*$s+($s/2),($x+1)*$s,$y*$s+$s,);
+            imagefilledpolygon($img, $values, 3, $color);
+            imagefilledpolygon($img, $values1, 3, $color);
+            imagefilledpolygon($img, $values2, 3, $color);
+        }
+    }
+    
+    /**
+     * 缩放图片
+     * @param type $im
+     * @param type $maxwidth
+     * @param type $maxheight
+     * @return type
+     */
+    public function resizeImage($im,$maxwidth,$maxheight){
+        $pic_width = imagesx($im);
+        $pic_height = imagesy($im);
+
+        $newim = imagecreatetruecolor($maxwidth,$maxheight);
+        ImageCopyResampled($newim,$im,0,0,0,0,$maxwidth,$maxheight,$pic_width,$pic_height);
+        imagedestroy($im);  
+        
+        return $newim;
+        
+    }
+    
+    //增加背景
+    public function imageaddbg($im,$bgpath) {
+        
+        //计算宽和高
+        $w = imagesx($im);
+        $h = imagesy($im);
+
+        //加载logo
+        $ext = substr($bgpath, strrpos($bgpath, '.'));
+        if (empty($ext)) {
+            return false;	
+        }
+        switch(strtolower($ext)) {
+            case '.jpg':
+                    $src_im = @imagecreatefromjpeg($bgpath);
+                    break;
+            case '.gif':
+                    $src_im = @imagecreatefromgif($bgpath);
+                    break;
+            case '.png':
+                    $src_im = @imagecreatefrompng($bgpath);
+                    break;
+
+        }
+       
+        $bgw=  imagesx($src_im);
+        $bgh=  imagesy($src_im);
+        imagecopymerge($src_im, $im, ($bgw/2)-($w/2), ($bgh/2)-($h/2), 0, 0, $w, $h, 100);
+        imagedestroy($im); 
+        return $src_im;
+    }
+    
+    //图片增加logo
+    public function imageaddlogo($im,$logopath) {
+        
+        //计算宽和高
+        $w = imagesx($im);
+        $h = imagesy($im);
+
+        //加载logo
+        $ext = substr($logopath, strrpos($logopath, '.'));
+        if (empty($ext)) {
+            return false;	
+        }
+        switch(strtolower($ext)) {
+            case '.jpg':
+                    $src_im = @imagecreatefromjpeg($logopath);
+                    break;
+            case '.gif':
+                    $src_im = @imagecreatefromgif($logopath);
+                    break;
+            case '.png':
+                    $src_im = @imagecreatefrompng($logopath);
+                    break;
+
+        }
+        $src_im=  $this->resizeImage($src_im,46,46);
+        $src_w = imagesx($src_im);
+        $src_h = imagesy($src_im);
+
+        
+        //logo边框1 小
+        $bor1=ImageCreate($src_w+2,$src_h+2);
+        ImageColorAllocate ($bor1, 237, 234, 237);//背景色
+        $bor1_w = imagesx($bor1);
+        $bor1_h = imagesy($bor1);
+        
+        //logo边框2 中
+        $bor2=ImageCreate($bor1_w+8,$bor1_h+8);
+        ImageColorAllocate ($bor2, 255, 255, 255);//背景色
+        $bor2_w = imagesx($bor2);
+        $bor2_h = imagesy($bor2);
+        
+        //logo边框3 大
+        $bor3=ImageCreate($bor2_w+2,$bor2_h+2);
+        ImageColorAllocate ($bor3, 215, 215, 215);//背景色
+        $bor3_w = imagesx($bor3);
+        $bor3_h = imagesy($bor3);
+
+        //圆角处理
+        $rounder = new RoundedCorner('', 5);
+
+        //二维码与logo边框3合并
+        $bor3=$rounder->round_it($bor3);
+        imagecopymerge($im, $bor3, ($w/2)-($bor3_w/2), ($h/2)-($bor3_h/2), 0, 0, $bor3_w, $bor3_h, 100);
+        imagedestroy($bor3); 
+
+        //二维码与logo边框2合并
+        $bor2=$rounder->round_it($bor2);
+        imagecopymerge($im, $bor2, ($w/2)-($bor2_w/2), ($h/2)-($bor2_h/2), 0, 0, $bor2_w, $bor2_h, 100);
+        imagedestroy($bor2); 
+
+       //二维码与logo边框1合并
+        $bor1=$rounder->round_it($bor1);
+        imagecopymerge($im, $bor1, ($w/2)-($bor1_w/2), ($h/2)-($bor1_h/2), 0, 0, $bor1_w, $bor1_h, 100);
+        imagedestroy($bor1); 
+        
+       //二维码与logo合并
+        $src_im=$rounder->round_it($src_im);
+        imagecopymerge($im, $src_im, ($w/2)-($src_w/2), ($h/2)-($src_h/2), 0, 0, $src_w, $src_h, 100);
+        imagedestroy($src_im); 
+        return $im;
+    }
+    /** 
+    * 16进制颜色转换为RGB色值 
+    * @method hex2rgb 
+    */ 
+    public function hex2rgb($hexColor) { 
+        $color = str_replace('#', '', $hexColor); 
+        if (strlen($color) > 3) { 
+
+            $rgb = array( 
+                'r' => hexdec(substr($color, 0, 2)), 
+                'g' => hexdec(substr($color, 2, 2)), 
+                'b' => hexdec(substr($color, 4, 2)) 
+            ); 
+        } else { 
+
+            $color = str_replace('#', '', $hexColor); 
+            $r = substr($color, 0, 1) . substr($color, 0, 1); 
+            $g = substr($color, 1, 1) . substr($color, 1, 1); 
+            $b = substr($color, 2, 1) . substr($color, 2, 1); 
+            $rgb = array( 
+                'r' => hexdec($r), 
+                'g' => hexdec($g), 
+                'b' => hexdec($b) 
+            ); 
+        } 
+
+        return $rgb; 
+    } 
+    
+    
+}
+
+?>

+ 260 - 0
src/Library/QrCode/traits/Fill.php

@@ -0,0 +1,260 @@
+<?php
+namespace QrCode\traits;
+
+trait Fill
+{
+    //半角
+    public function halfCorner($img, $x, $y, $s, $bgColor, $frontColor, $lt = true, $lb = true, $rb = true, $rt = true)
+    {
+        //左上半角
+        if ($lt) {
+            imagefilledarc($img, $x * $s, $y * $s, $s / 2, $s / 2, 0, 90, $frontColor, IMG_ARC_PIE);
+            imagefilledarc($img, $x * $s + $s / 4, $y * $s + $s / 4, $s / 2, $s / 2, 180, 270, $bgColor, IMG_ARC_PIE);
+        }
+        //左下半角
+        if ($lb) {
+            imagefilledarc($img, $x * $s, ($y + 1) * $s, $s / 2, $s / 2, 270, 360, $frontColor, IMG_ARC_PIE);
+            imagefilledarc($img, $x * $s + $s / 4, ($y + 1) * $s - $s / 4, $s / 2, $s / 2, 90, 180, $bgColor, IMG_ARC_PIE);
+        }
+        //右下半角
+        if ($rb) {
+            imagefilledarc($img, ($x + 1) * $s, ($y + 1) * $s, $s / 2, $s / 2, 180, 270, $frontColor, IMG_ARC_PIE);
+            imagefilledarc($img, ($x + 1) * $s - $s / 4, ($y + 1) * $s - $s / 4, $s / 2, $s / 2, 0, 90, $bgColor, IMG_ARC_PIE);
+
+        }
+        //右上半角
+        if ($rt) {
+            imagefilledarc($img, ($x + 1) * $s, $y * $s, ($s / 2), ($s / 2), 90, 180, $frontColor, IMG_ARC_PIE);
+            imagefilledarc($img, ($x + 1) * $s - ($s / 4), $y * $s + ($s / 4), ($s / 2), ($s / 2), 270, 360, $bgColor, IMG_ARC_PIE);
+        }
+
+    }
+
+    //半圆
+    public function halfRounded($img, $x, $y, $s, $color, $t = true, $l = true, $b = true, $r = true)
+    {
+        //上半圆
+        if ($t) {
+            imagefilledarc($img, ($x * $s) + ($s / 2), ($y * $s) + ($s / 2), $s, $s, 180, 270, $color, IMG_ARC_PIE);
+            imagefilledarc($img, ($x * $s) + ($s / 2), ($y * $s) + ($s / 2), $s, $s, 270, 360, $color, IMG_ARC_PIE);
+            imagefilledrectangle($img, $x * $s, ($y * $s) + ($s / 2), ($x + 1) * $s, ($y + 1) * $s, $color);
+        }
+        //左半圆
+        if ($l) {
+            imagefilledarc($img, ($x * $s) + ($s / 2), ($y * $s) + ($s / 2), $s, $s, 90, 180, $color, IMG_ARC_PIE);
+            imagefilledarc($img, ($x * $s) + ($s / 2), ($y * $s) + ($s / 2), $s, $s, 180, 270, $color, IMG_ARC_PIE);
+            imagefilledrectangle($img, ($x * $s) + ($s / 2), ($y * $s), ($x + 1) * $s, ($y + 1) * $s, $color);
+        }
+
+        //下半圆
+        if ($b) {
+            imagefilledarc($img, ($x * $s) + ($s / 2), ($y * $s) + ($s / 2), $s, $s, 0, 90, $color, IMG_ARC_PIE);
+            imagefilledarc($img, ($x * $s) + ($s / 2), ($y * $s) + ($s / 2), $s, $s, 90, 180, $color, IMG_ARC_PIE);
+            imagefilledrectangle($img, $x * $s, $y * $s, ($x + 1) * $s, ($y * $s) + ($s / 2), $color);
+        }
+        //右半圆
+        if ($r) {
+            imagefilledarc($img, ($x * $s) + ($s / 2), ($y * $s) + ($s / 2), $s, $s, 270, 360, $color, IMG_ARC_PIE);
+            imagefilledarc($img, ($x * $s) + ($s / 2), ($y * $s) + ($s / 2), $s, $s, 0, 90, $color, IMG_ARC_PIE);
+            imagefilledrectangle($img, $x * $s, $y * $s, ($x * $s) + ($s / 2), ($y + 1) * $s, $color);
+
+        }
+    }
+
+    //圆角
+    public function roundedCorner($img, $x, $y, $s, $color, $lt = true, $lb = true, $rb = true, $rt = true)
+    {
+        if ($lt) {
+            imagefilledarc($img, ($x * $s) + ($s / 2), ($y * $s) + ($s / 2), $s, $s, 180, 270, $color, IMG_ARC_PIE);
+            $values = array(($x + 1) * $s, ($y * $s), ($x + 1) * $s, ($y + 1) * $s, ($x * $s), ($y + 1) * $s,);
+            $values1 = array(($x * $s), ($y + 1) * $s, ($x * $s) + ($s / 2), ($y * $s) + ($s / 2), ($x * $s), ($y * $s) + ($s / 2),);
+            $values2 = array(($x * $s) + ($s / 2), ($y * $s) + ($s / 2), ($x * $s) + ($s / 2), ($y * $s), ($x + 1) * $s, ($y * $s),);
+            imagefilledpolygon($img, $values, 3, $color);
+            imagefilledpolygon($img, $values1, 3, $color);
+            imagefilledpolygon($img, $values2, 3, $color);
+        }
+        if ($lb) {
+            imagefilledarc($img, ($x * $s) + ($s / 2), ($y * $s) + ($s / 2), $s, $s, 90, 180, $color, IMG_ARC_PIE);
+            $values = array($x * $s, $y * $s, $x * $s + $s, $y * $s, $x * $s + $s, ($y + 1) * $s,);
+            $values1 = array($x * $s, $y * $s, $x * $s, $y * $s + ($s / 2), $x * $s + $s, $y * $s + ($s / 2),);
+            $values2 = array($x * $s + ($s / 2), $y * $s + ($s / 2), $x * $s + ($s / 2), ($y + 1) * $s, $x * $s + $s, ($y + 1) * $s,);
+            imagefilledpolygon($img, $values, 3, $color);
+            imagefilledpolygon($img, $values1, 3, $color);
+            imagefilledpolygon($img, $values2, 3, $color);
+        }
+        if ($rb) {
+            imagefilledarc($img, ($x * $s) + ($s / 2), $y * $s + ($s / 2), $s, $s, 360, 90, $color, IMG_ARC_PIE);
+            $values = array($x * $s, ($y + 1) * $s, $x * $s, $y * $s, ($x + 1) * $s, $y * $s,);
+            $values1 = array($x * $s, ($y + 1) * $s, $x * $s + ($s / 2), $y * $s + ($s / 2), $x * $s + ($s / 2), ($y + 1) * $s,);
+            $values2 = array($x * $s + ($s / 2), $y * $s + ($s / 2), ($x + 1) * $s, $y * $s, ($x + 1) * $s, $y * $s + ($s / 2),);
+            imagefilledpolygon($img, $values, 3, $color);
+            imagefilledpolygon($img, $values1, 3, $color);
+            imagefilledpolygon($img, $values2, 3, $color);
+        }
+        if ($rt) {
+            imagefilledarc($img, ($x * $s) + ($s / 2), $y * $s + ($s / 2), $s, $s, 270, 360, $color, IMG_ARC_PIE);
+            $values = array($x * $s, $y * $s, $x * $s, $y * $s + $s, ($x + 1) * $s, $y * $s + $s,);
+            $values1 = array($x * $s, $y * $s, $x * $s + ($s / 2), $y * $s, $x * $s + ($s / 2), $y * $s + ($s / 2),);
+            $values2 = array($x * $s + ($s / 2), $y * $s + ($s / 2), ($x + 1) * $s, $y * $s + ($s / 2), ($x + 1) * $s, $y * $s + $s,);
+            imagefilledpolygon($img, $values, 3, $color);
+            imagefilledpolygon($img, $values1, 3, $color);
+            imagefilledpolygon($img, $values2, 3, $color);
+        }
+    }
+
+    /**
+     * 缩放图片
+     * @param type $im
+     * @param type $maxwidth
+     * @param type $maxheight
+     * @return type
+     */
+    public function resizeImage($im, $maxwidth, $maxheight)
+    {
+        $picWidth = imagesx($im);
+        $picHeight = imagesy($im);
+
+        $newim = imagecreatetruecolor($maxwidth, $maxheight);
+        ImageCopyResampled($newim, $im, 0, 0, 0, 0, $maxwidth, $maxheight, $picWidth, $picHeight);
+        imagedestroy($im);
+
+        return $newim;
+
+    }
+
+    //增加背景
+    public function imageAddBG($im, $bgpath)
+    {
+
+        //计算宽和高
+        $w = imagesx($im);
+        $h = imagesy($im);
+
+        //加载logo
+        $ext = substr($bgpath, strrpos($bgpath, '.'));
+        if (empty($ext)) {
+            return false;
+        }
+        switch (strtolower($ext)) {
+            case '.jpg':
+                $srcIm = @imagecreatefromjpeg($bgpath);
+                break;
+            case '.gif':
+                $srcIm = @imagecreatefromgif($bgpath);
+                break;
+            case '.png':
+                $srcIm = @imagecreatefrompng($bgpath);
+                break;
+
+        }
+
+        $bgw = imagesx($srcIm);
+        $bgh = imagesy($srcIm);
+        imagecopymerge($srcIm, $im, ($bgw / 2) - ($w / 2), ($bgh / 2) - ($h / 2), 0, 0, $w, $h, 100);
+        imagedestroy($im);
+        return $srcIm;
+    }
+
+    //图片增加logo
+    public function imageAddLogo($im, $logo)
+    {
+
+        //计算宽和高
+        $w = imagesx($im);
+        $h = imagesy($im);
+
+        //加载logo
+        $ext = substr($logo, strrpos($logo, '.'));
+        if (empty($ext)) {
+            return false;
+        }
+        switch (strtolower($ext)) {
+            case '.jpg':
+                $srcIm = @imagecreatefromjpeg($logo);
+                break;
+            case '.gif':
+                $srcIm = @imagecreatefromgif($logo);
+                break;
+            case '.png':
+                $srcIm = @imagecreatefrompng($logo);
+                break;
+
+        }
+        $srcIm = $this->resizeImage($srcIm, min(46, $w / 5), min(46, $h / 5));
+        $srcWidth = imagesx($srcIm);
+        $srcHeight = imagesy($srcIm);
+
+
+        //logo边框1 小
+        $bor1 = ImageCreate($srcWidth + 2, $srcHeight + 2);
+        ImageColorAllocate($bor1, 237, 234, 237);//背景色
+        $bor1Width = imagesx($bor1);
+        $bor1Height = imagesy($bor1);
+
+        //logo边框2 中
+        $bor2 = ImageCreate($bor1Width + 8, $bor1Height + 8);
+        ImageColorAllocate($bor2, 255, 255, 255);//背景色
+        $bor2_w = imagesx($bor2);
+        $bor2_h = imagesy($bor2);
+
+        //logo边框3 大
+        $bor3 = ImageCreate($bor2_w + 2, $bor2_h + 2);
+        ImageColorAllocate($bor3, 215, 215, 215);//背景色
+        $bor3Width = imagesx($bor3);
+        $bor3Height = imagesy($bor3);
+
+        //圆角处理
+        $rounder = new \QrCode\RoundedCorner('', 5);
+
+        //二维码与logo边框3合并
+        $bor3 = $rounder->round_it($bor3);
+        imagecopymerge($im, $bor3, ($w / 2) - ($bor3Width / 2), ($h / 2) - ($bor3Height / 2), 0, 0, $bor3Width, $bor3Height, 100);
+        imagedestroy($bor3);
+
+        //二维码与logo边框2合并
+        $bor2 = $rounder->round_it($bor2);
+        imagecopymerge($im, $bor2, ($w / 2) - ($bor2_w / 2), ($h / 2) - ($bor2_h / 2), 0, 0, $bor2_w, $bor2_h, 100);
+        imagedestroy($bor2);
+
+        //二维码与logo边框1合并
+        $bor1 = $rounder->round_it($bor1);
+        imagecopymerge($im, $bor1, ($w / 2) - ($bor1Width / 2), ($h / 2) - ($bor1Height / 2), 0, 0, $bor1Width, $bor1Height, 100);
+        imagedestroy($bor1);
+
+        //二维码与logo合并
+        $srcIm = $rounder->round_it($srcIm);
+        imagecopymerge($im, $srcIm, ($w / 2) - ($srcWidth / 2), ($h / 2) - ($srcHeight / 2), 0, 0, $srcWidth, $srcHeight, 100);
+        imagedestroy($srcIm);
+        return $im;
+    }
+
+    /**
+     * 16进制颜色转换为RGB色值
+     * @method hex2rgb
+     */
+    public function hex2rgb($hexColor)
+    {
+        $color = str_replace('#', '', $hexColor);
+        if (strlen($color) > 3) {
+
+            $rgb = array(
+                'r' => hexdec(substr($color, 0, 2)),
+                'g' => hexdec(substr($color, 2, 2)),
+                'b' => hexdec(substr($color, 4, 2))
+            );
+        } else {
+
+            $color = str_replace('#', '', $hexColor);
+            $r = substr($color, 0, 1) . substr($color, 0, 1);
+            $g = substr($color, 1, 1) . substr($color, 1, 1);
+            $b = substr($color, 2, 1) . substr($color, 2, 1);
+            $rgb = array(
+                'r' => hexdec($r),
+                'g' => hexdec($g),
+                'b' => hexdec($b)
+            );
+        }
+
+        return $rgb;
+    }
+}