Browse Source

Update:修复二维码问题

Zhu Jinhui 7 năm trước cách đây
mục cha
commit
e9f2c0a588

+ 8 - 0
src/Functions/Funcs.php

@@ -23,6 +23,14 @@ function _e()
 {
     return call_user_func_array('\Qii::e', func_get_args());
 }
+
+/**
+ * Chrome logs
+ * @return mixed
+ */
+function _log() {
+    return call_user_func_array('\Qii\Library\Chrome::log', func_get_args());
+}
 /**
  * 加载语言包
  * @param string $language 语言包

+ 15 - 13
src/Library/Qr.php

@@ -62,56 +62,58 @@ class Qr
     }
 
     /**
+     * 生成带颜色的二维码
+     * 注意:背景色和前景色不能一样,否则识别不出来
+     *
      * @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())
+    public function creatorColor($txt, $pointSize = 10, $margin = 1, $errorLevel = 4, $options = array())
     {
         $defaults = array(
             'width' => 240, //图片大小
-            'logo' => 'static/images/logo.png', //logo
+            'margin' => 2,
+            'logo' => '', //logo
             'bg' => '',
-            'pointColor' => '#000000', //定点颜色
-            'inPointColor' => '#000000',//内定点
+            'pointColor' => '', //定点颜色
+            'inPointColor' => '',//内定点
             'frontColor' => '#000000',//前景色
             'bgColor' => '#FFFFFF', //背景色
-            'contentColor' => '#000000', //内容颜色
+            'contentColor' => '', //内容颜色
             '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);
+                $handle = new \QrCode\Widget\Liquid($pointSize, $options);
                 break;
             case 1:
-                $handle = new \QrCode\Rectangle($pointSize, $options);
+                $handle = new \QrCode\Widget\Rectangle($pointSize, $options);
                 break;
             case 0:
-                $handle = new \QrCode\Edellipse($pointSize, $options);
+                $handle = new \QrCode\Widget\Edellipse($pointSize, $options);
                 break;
         }
-        $img = $handle->handle($data);
+        $qrImage = $handle->handle($data);
 
         //保存图片
-
-        $im = $this->resizeImage($img, $options['width'], $options['width']);
-
+        $im = $this->resizeImage($qrImage, $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']);

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

@@ -1,91 +0,0 @@
-<?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;
-    }
-
-}

+ 25 - 13
src/Library/QrCode/Edellipse.php → src/Library/QrCode/Widget/Edellipse.php

@@ -1,10 +1,12 @@
 <?php
-namespace QrCode;
+namespace QrCode\Widget;
+use Qrcode\Traits;
 
 class Edellipse
 {
     use Traits\Fill;
     public $defaults = array(
+        'margin' => 1,
         'pointColor' => '#000000', //定点颜色
         'inPointColor' => '#000000',//内定点
         'frontColor' => '#000000',//前景色
@@ -21,6 +23,11 @@ class Edellipse
     {
         $this->pointSize = $pointSize;
         $this->options = array_merge($this->defaults, $options);
+        if(!empty($options['frontColor'])) {
+            if(empty($options['pointColor'])) $this->options['pointColor'] = $options['frontColor'];
+            if(empty($options['inPointColor'])) $this->options['inPointColor'] = $options['frontColor'];
+            if(empty($options['contentColor'])) $this->options['contentColor'] = $options['frontColor'];
+        }
         return $this;
     }
 
@@ -29,7 +36,6 @@ class Edellipse
 
         $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']);
 
@@ -40,46 +46,52 @@ class Edellipse
         $s = $this->pointSize;//每一块的大小
 
 
-        $img = ImageCreate($w * $this->pointSize, $h * $this->pointSize);
+        $img = ImageCreate($w * $this->pointSize + 2 * $this->options['margin'], $h * $this->pointSize+ 2 * $this->options['margin']);
 
         $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 参数指定的子字符串。
+                    //x左边开始坐标
+                    $xPointLeft = ($x * $this->pointSize) + ($this->pointSize / 2) + $this->options['margin'];
+                    //y左边开始坐标
+                    $yPointLeft = ($y * $this->pointSize) + ($this->pointSize / 2) + $this->options['margin'];
                     //左上角定点
                     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);
+                            imagefilledellipse($img, $xPointLeft, $yPointLeft, $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);
+                            imagefilledellipse($img, $xPointLeft, $yPointLeft, $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);
+                            imagefilledellipse($img, $xPointLeft, $yPointLeft, $this->pointSize, $this->pointSize, $pointColor);
+                        }else if($x === $imageSize || ($x === $imageSize - 6 && $y < 6)) {//左|右
+                            imagefilledellipse($img, $xPointLeft, $yPointLeft, $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);
+                            imagefilledellipse($img, $xPointLeft, $yPointLeft, $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);
+                            imagefilledellipse($img, $xPointLeft, $yPointLeft, $this->pointSize, $this->pointSize, $pointColor);
+                        }else if(($y === $imageSize - 6 && $x < 6) || $y === $imageSize && $x < 6) {//上|下
+                            imagefilledellipse($img, $xPointLeft, $yPointLeft, $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);
+                            imagefilledellipse($img, $xPointLeft, $yPointLeft, $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);
+                        imagefilledellipse($img, $xPointLeft, $yPointLeft, $this->pointSize, $this->pointSize, $contentColor);
                     }
 
                 }

+ 69 - 59
src/Library/QrCode/Liquid.php → src/Library/QrCode/Widget/Liquid.php

@@ -1,11 +1,12 @@
 <?php
-
-namespace QrCode;
+namespace QrCode\Widget;
+use Qrcode\Traits;
 
 class Liquid
 {
     use Traits\Fill;
     public $defaults = array(
+        'margin' => 1,
         'pointColor' => '#000000', //定点颜色
         'inPointColor' => '#000000',//内定点
         'frontColor' => '#000000',//前景色
@@ -22,16 +23,19 @@ class Liquid
     {
         $this->pointSize = $pointSize;
         $this->options = array_merge($this->defaults, $options);
+        if(!empty($options['frontColor'])) {
+            if(empty($options['pointColor'])) $this->options['pointColor'] = $options['frontColor'];
+            if(empty($options['inPointColor'])) $this->options['inPointColor'] = $options['frontColor'];
+            if(empty($options['contentColor'])) $this->options['contentColor'] = $options['frontColor'];
+        }
         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']);
 
@@ -47,9 +51,9 @@ class Liquid
         $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) {
@@ -62,14 +66,16 @@ class Liquid
                         //左上角定点的四个大角
                         if ($x === 0 || $y === 0 || $x === 6 || $y === 6) {
                             //液态
+                            $xPointLeft = $x;
+                            $yPointLeft = $y;
                             if ($x === 0 && $y === 0) {
-                                $this->roundedCorner($img, $x, $y, $s, $pointColor, true, false, false, false);
+                                $this->roundedCorner($img, $xPointLeft, $yPointLeft, $s, $pointColor, true, false, false, false);
                             } else if ($x === 0 && $y === 6) {
-                                $this->roundedCorner($img, $x, $y, $s, $pointColor, false, true, false, false);
+                                $this->roundedCorner($img, $xPointLeft, $yPointLeft, $s, $pointColor, false, true, false, false);
                             } else if ($x === 6 && $y === 6) {
-                                $this->roundedCorner($img, $x, $y, $s, $pointColor, false, false, true, false);
+                                $this->roundedCorner($img, $xPointLeft, $yPointLeft, $s, $pointColor, false, false, true, false);
                             } else if ($x === 6 && $y === 0) {
-                                $this->roundedCorner($img, $x, $y, $s, $pointColor, false, false, false, true);
+                                $this->roundedCorner($img, $xPointLeft, $yPointLeft, $s, $pointColor, false, false, false, true);
                             } else {
                                 imagefilledrectangle($img, $x * $this->pointSize, $y * $this->pointSize, ($x + 1) * $this->pointSize, ($y + 1) * $this->pointSize, $pointColor);
                             }
@@ -77,13 +83,13 @@ class Liquid
                         } else {
                             //液态
                             if ($x === 2 && $y === 2) {
-                                $this->roundedCorner($img, $x, $y, $s, $inPointColor, true, false, false, false);
+                                $this->roundedCorner($img, $x, $y, $this->pointSize, $inPointColor, true, false, false, false);
                             } else if ($x === 2 && $y === 4) {
-                                $this->roundedCorner($img, $x, $y, $s, $inPointColor, false, true, false, false);
+                                $this->roundedCorner($img, $x, $y, $this->pointSize, $inPointColor, false, true, false, false);
                             } else if ($x === 4 && $y === 4) {
-                                $this->roundedCorner($img, $x, $y, $s, $inPointColor, false, false, true, false);
+                                $this->roundedCorner($img, $x, $y, $this->pointSize, $inPointColor, false, false, true, false);
                             } else if ($x === 4 && $y === 2) {
-                                $this->roundedCorner($img, $x, $y, $s, $inPointColor, false, false, false, true);
+                                $this->roundedCorner($img, $x, $y, $this->pointSize, $inPointColor, false, false, false, true);
                             } else {
                                 imagefilledrectangle($img, $x * $this->pointSize, $y * $this->pointSize, ($x + 1) * $this->pointSize, ($y + 1) * $this->pointSize, $inPointColor);
                             }
@@ -93,58 +99,59 @@ class Liquid
 
                         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 {
+                            if ($x === $imageSize - 6 && $y === 0) {
+                                $this->roundedCorner($img, $x, $y, $this->pointSize, $pointColor, true, false, false, false);
+                            } else if ($x === $imageSize - 6 && $y === 6) {
+                                $this->roundedCorner($img, $x, $y, $this->pointSize, $pointColor, false, true, false, false);
+                            } else if ($x === $imageSize && $y === 6) {
+                                $this->roundedCorner($img, $x, $y, $this->pointSize, $pointColor, false, false, true, false);
+                            } else if ($x === $imageSize && $y === 0) {
+                                $this->roundedCorner($img, $x, $y, $this->pointSize, $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);
+                            if ($x === $imageSize - 4 && $y === 2) {
+                                $this->roundedCorner($img, $x, $y, $this->pointSize, $inPointColor, true, false, false, false);
+                            } else if ($x === $imageSize - 4 && $y === 4) {
+                                $this->roundedCorner($img, $x, $y, $this->pointSize, $inPointColor, false, true, false, false);
+                            } else if ($x === $imageSize - 2 && $y === 4) {
+                                $this->roundedCorner($img, $x, $y, $this->pointSize, $inPointColor, false, false, true, false);
+                            } else if ($x === $imageSize - 2 && $y === 2) {
+                                $this->roundedCorner($img, $x, $y, $this->pointSize, $inPointColor, false, false, false, true);
+                            }else if($x === $imageSize - 6 || $x === $imageSize){
+                                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) {
+                        if ($x === 0 || $y === $imageSize - 6 || $x === 6 || $y === $imageSize - 1) {
                             //液态
-                            if ($x === 0 && $y === $imageSize - 7) {
+                            if ($x === 0 && $y === $imageSize - 6) {
                                 $this->roundedCorner($img, $x, $y, $s, $pointColor, true, false, false, false);
-                            } else if ($x === 0 && $y === $imageSize - 1) {
+                            } else if ($x === 0 && $y === $imageSize) {
                                 $this->roundedCorner($img, $x, $y, $s, $pointColor, false, true, false, false);
-                            } else if ($x === 6 && $y === $imageSize - 1) {
+                            } else if ($x === 6 && $y === $imageSize) {
                                 $this->roundedCorner($img, $x, $y, $s, $pointColor, false, false, true, false);
-                            } else if ($x === 6 && $y === $imageSize - 7) {
+                            } else if ($x === 6 && $y === $imageSize - 6) {
                                 $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) {
+                            if ($x === 2 && $y === $imageSize - 4) {
                                 $this->roundedCorner($img, $x, $y, $s, $inPointColor, true, false, false, false);
-                            } else if ($x === 2 && $y === $imageSize - 3) {
+                            } else if ($x === 2 && $y === $imageSize - 2) {
                                 $this->roundedCorner($img, $x, $y, $s, $inPointColor, false, true, false, false);
-                            } else if ($x === 4 && $y === $imageSize - 3) {
+                            } else if ($x === 4 && $y === $imageSize - 2) {
                                 $this->roundedCorner($img, $x, $y, $s, $inPointColor, false, false, true, false);
-                            } else if ($x === 4 && $y === $imageSize - 5) {
+                            } else if ($x === 4 && $y === $imageSize - 4) {
                                 $this->roundedCorner($img, $x, $y, $s, $inPointColor, false, false, false, true);
+                            }else if($x < 6 && $y == $imageSize){
+                                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);
                             }
@@ -205,35 +212,34 @@ class Liquid
                         //上+左+下+右=0 全圆
                         if ($t == 0 && $l == 0 && $b == 0 && $r == 0) {
                             //全圆
-                            imagefilledellipse($img, ($x * $s) + ($s / 2), ($y * $s) + ($s / 2), $s, $s, $frontColor);
+                            imagefilledellipse($img, ($x * $s) + ($s / 2), ($y * $s) + ($s / 2), $s, $s, $contentColor);
                         } elseif ($t == 0 && $l == 0 && $r == 0) {
                             //上半圆
-                            $this->halfRounded($img, $x, $y, $s, $frontColor, true, false, false, false);
+                            $this->halfRounded($img, $x, $y, $s, $contentColor, true, false, false, false);
                         } elseif ($t == 0 && $l == 0 && $b == 0) {
                             //左半圆
-                            $this->halfRounded($img, $x, $y, $s, $frontColor, false, true, false, false);
+                            $this->halfRounded($img, $x, $y, $s, $contentColor, false, true, false, false);
                         } elseif ($l == 0 && $b == 0 && $r == 0) {
                             //下半圆
-                            $this->halfRounded($img, $x, $y, $s, $frontColor, false, false, true, false);
+                            $this->halfRounded($img, $x, $y, $s, $contentColor, false, false, true, false);
                         } elseif ($t == 0 && $b == 0 && $r == 0) {
                             //右半圆
-                            $this->halfRounded($img, $x, $y, $s, $frontColor, false, false, false, true);
+                            $this->halfRounded($img, $x, $y, $s, $contentColor, false, false, false, true);
                         } elseif ($t == 0 && $l == 0) {
                             //左上角
-                            $this->roundedCorner($img, $x, $y, $s, $frontColor, true, false, false, false);
+                            $this->roundedCorner($img, $x, $y, $s, $contentColor, true, false, false, false);
                         } elseif ($l == 0 && $b == 0) {
                             //左下角
-                            $this->roundedCorner($img, $x, $y, $s, $frontColor, false, true, false, false);
+                            $this->roundedCorner($img, $x, $y, $s, $contentColor, false, true, false, false);
                         } elseif ($b == 0 && $r == 0) {
                             //右下角
-                            $this->roundedCorner($img, $x, $y, $s, $frontColor, false, false, true, false);
+                            $this->roundedCorner($img, $x, $y, $s, $contentColor, false, false, true, false);
                         } elseif ($r == 0 && $t == 0) {
                             //右上角
-                            $this->roundedCorner($img, $x, $y, $s, $frontColor, false, false, false, true);
+                            $this->roundedCorner($img, $x, $y, $s, $contentColor, false, false, false, true);
                         } else {
                             //直角
-                            imagefilledrectangle($img, $x * $this->pointSize, $y * $this->pointSize, ($x + 1) * $this->pointSize, ($y + 1) * $this->pointSize, $frontColor);
-
+                            imagefilledrectangle($img, $x * $this->pointSize, $y * $this->pointSize, ($x + 1) * $this->pointSize, ($y + 1) * $this->pointSize, $contentColor);
                         }
                     }
 
@@ -299,28 +305,32 @@ class Liquid
 
                         if ($t == 1 && $lt == 1 && $l == 1) {
                             //左上角
-                            $this->halfCorner($img, $x, $y, $s, $bgColor, $frontColor, true, false, false, false);
+                            $this->halfCorner($img, $x, $y, $s, $bgColor, $contentColor, true, false, false, false);
                         }
 
                         if ($l == 1 && $lb == 1 && $b == 1) {
                             //左下角
-                            $this->halfCorner($img, $x, $y, $s, $bgColor, $frontColor, false, true, false, false);
+                            $this->halfCorner($img, $x, $y, $s, $bgColor, $contentColor, false, true, false, false);
                         }
                         if ($b == 1 && $rb == 1 && $r == 1) {
                             //右下角
-                            $this->halfCorner($img, $x, $y, $s, $bgColor, $frontColor, false, false, true, false);
+                            $this->halfCorner($img, $x, $y, $s, $bgColor, $contentColor, false, false, true, false);
                         }
                         if ($r == 1 && $rt == 1 && $t == 1) {
                             //右上角
-                            $this->halfCorner($img, $x, $y, $s, $bgColor, $frontColor, false, false, false, true);
+                            $this->halfCorner($img, $x, $y, $s, $bgColor, $contentColor, false, false, false, true);
                         }
                     }
-
                 }
                 $x++;
             }
             $y++;
         }
-        return $img;
+        $background = ImageCreate($w * $this->pointSize + 2 * $this->options['margin'], $h * $this->pointSize + 2 * $this->options['margin']);
+        imagefill($background, 0, 0, $bgColor);
+        imagecopymerge($background, $img, $this->options['margin'], $this->options['margin'], 0, 0, $w * $this->pointSize, $h * $this->pointSize, 100);
+        imagedestroy($img);
+
+        return $background;
     }
 }

+ 105 - 0
src/Library/QrCode/Widget/Rectangle.php

@@ -0,0 +1,105 @@
+<?php
+namespace QrCode\Widget;
+use Qrcode\Traits;
+
+class Rectangle
+{
+    use Traits\Fill;
+    public $defaults = array(
+        'margin' => 1,
+        '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);
+        if(!empty($options['frontColor'])) {
+            if(empty($options['pointColor'])) $this->options['pointColor'] = $options['frontColor'];
+            if(empty($options['inPointColor'])) $this->options['inPointColor'] = $options['frontColor'];
+            if(empty($options['contentColor'])) $this->options['contentColor'] = $options['frontColor'];
+        }
+        return $this;
+    }
+
+    public function handle($data)
+    {
+        $pointColor = $this->hex2rgb($this->options['pointColor']);
+        $inPointColor = $this->hex2rgb($this->options['inPointColor']);
+        $bgColor = $this->hex2rgb($this->options['bgColor']);
+        $contentColor = $this->hex2rgb($this->options['contentColor']);
+
+        $w = strlen($data[0]);
+        $h = count($data);
+
+        $imageSize = count($data) - 1;
+
+
+        $img = ImageCreate($w * $this->pointSize + 2 * $this->options['margin'], $h * $this->pointSize + 2 * $this->options['margin']);
+
+        $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']);//内定点
+        $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 参数指定的子字符串。
+                    //x左边开始坐标
+                    $xPointLeft = ($x * $this->pointSize) + $this->options['margin'];
+                    //y左边开始坐标
+                    $yPointLeft = ($y * $this->pointSize) + $this->options['margin'];
+                    //x右下角坐标
+                    $xPointRight = ($x + 1) * $this->pointSize + $this->options['margin'];
+                    //y右下角坐标
+                    $yPointRight = ($y + 1) * $this->pointSize + $this->options['margin'];
+                    //左上角定点
+                    if ($x < 7 && $y < 7) {
+                        //左上角定点的四个大角
+                        if ($x === 0 || $y === 0 || $x === 6 || $y === 6) {
+                            imagefilledrectangle($img, $xPointLeft, $yPointLeft, $xPointRight, $yPointRight, $pointColor);
+                        } else {//里边
+                            imagefilledrectangle($img, $xPointLeft, $yPointLeft, $xPointRight, $yPointRight, $inPointColor);
+                        }
+                    } elseif ($x > $imageSize - 8 && $y < 7) { //右上角定点
+                        if ($x === $imageSize - 7 || $y === 0 || $x === $imageSize - 1 || $y === 6) {
+                            imagefilledrectangle($img, $xPointLeft, $yPointLeft, $xPointRight, $yPointRight, $pointColor);
+                        }else if($x === $imageSize || ($x === $imageSize - 6 && $y < 6)) {//左|右
+                            imagefilledrectangle($img, $xPointLeft, $yPointLeft, $xPointRight, $yPointRight, $pointColor);
+                        } else {//中间
+                            imagefilledrectangle($img, $xPointLeft, $yPointLeft, $xPointRight, $yPointRight, $inPointColor);
+                        }
+                    } elseif ($y > count($data) - 9 && $x < 7) { //左下角定点
+                        if ($x === 0 || $y === $imageSize - 7 || $x === 6 || $y === $imageSize - 1) {
+                            imagefilledrectangle($img, $xPointLeft, $yPointLeft, $xPointRight, $yPointRight, $pointColor);
+                        }else if(($y === $imageSize - 6 && $x < 6) || $y === $imageSize && $x < 6) {//上|下
+                            imagefilledrectangle($img, $xPointLeft, $yPointLeft, $xPointRight, $yPointRight, $pointColor);
+                        }else {//中间
+                            imagefilledrectangle($img, $xPointLeft, $yPointLeft, $xPointRight, $yPointRight, $inPointColor);
+                        }
+                    } else {
+                        imagefilledrectangle($img, $xPointLeft, $yPointLeft, $xPointRight, $yPointRight, $contentColor);
+                    }
+                }
+                $x++;
+            }
+            $y++;
+        }
+        return $img;
+    }
+
+}

+ 6 - 5
src/Library/QrCode/traits/Fill.php

@@ -164,23 +164,24 @@ trait Fill
         $h = imagesy($im);
 
         //加载logo
-        $ext = substr($logo, strrpos($logo, '.'));
+        $ext = pathinfo($logo, PATHINFO_EXTENSION);
+
         if (empty($ext)) {
             return false;
         }
         switch (strtolower($ext)) {
-            case '.jpg':
+            case 'jpg':
                 $srcIm = @imagecreatefromjpeg($logo);
                 break;
-            case '.gif':
+            case 'gif':
                 $srcIm = @imagecreatefromgif($logo);
                 break;
-            case '.png':
+            case 'png':
                 $srcIm = @imagecreatefrompng($logo);
                 break;
 
         }
-        $srcIm = $this->resizeImage($srcIm, min(46, $w / 5), min(46, $h / 5));
+        $srcIm = $this->resizeImage($srcIm, min(36, $w / 5), min(36, $h / 5));
         $srcWidth = imagesx($srcIm);
         $srcHeight = imagesy($srcIm);