diff --git a/php/qrcode.php b/php/qrcode.php index 234a38b..1e75416 100644 --- a/php/qrcode.php +++ b/php/qrcode.php @@ -551,6 +551,68 @@ function printHTML($size = "2px") { print(""); } + + public function toHtml($size = "2px", $color = '#000', $background = null) { + + $class = uniqid('qr'); + $html = ""; + + $bg = $background === null ? '' : ' style="background-color:' . $background . '"'; + + for ($r = 0, $moduleCount = $this->getModuleCount(); $r < $moduleCount; $r++) { + + $html .= ''; + + for ($c = 0; $c < $moduleCount; $c++) { + $html .= 'isDark($r, $c) ? " style='background-color:$color'" : $bg) . '/>'; + } + + $html .= ''; + } + + return $html . '
'; + } + + public function toSvg($scale = 5, $color = '#000', $background = null, $opacity = 1) { + + $class = uniqid('qr'); + $moduleCount = $this->getModuleCount(); + $length = $moduleCount * $scale; + + $bg = $background === null ? '' : ' style="background-color:' . $background . '"'; + + $svg = '' + . $bg . ''; + + for ($r = 0; $r < $moduleCount; $r++) { + $path = ''; + $count = 0; + $len = $r * $scale; + for ($c = 0; $c < $moduleCount; $c++) { + if($this->isDark($r, $c)) { + if($count == 0) { + $start = $c * $scale; + $path .= 'M' .$start. ' ' .$len; + } + $count++; + if ($c == $moduleCount - 1) { + $path .= 'h'.($count * $scale).'v'.$scale.'h-'.($count * $scale).'Z'; + } + } elseif ($count > 0) { + $path .= 'h'.($count * $scale).'v'.$scale.'h-'.($count * $scale).'Z'; + $count = 0; + } + } + $svg .= ''; + } + + return $svg . ''; + } } //---------------------------------------------------------------