فهرست منبع

:sparkles: examples

smiley 8 سال پیش
والد
کامیت
7df5a47e35
6فایلهای تغییر یافته به همراه242 افزوده شده و 2 حذف شده
  1. 33 0
      examples/MyAuthenticatorClass.php
  2. 17 0
      examples/authenticator.php
  3. 106 0
      examples/html.php
  4. 55 0
      examples/svg.php
  5. 29 0
      examples/text.php
  6. 2 2
      public/index.html

+ 33 - 0
examples/MyAuthenticatorClass.php

@@ -0,0 +1,33 @@
+<?php
+/**
+ * Class MyAuthenticatorClass
+ *
+ * @filesource   MyAuthenticatorClass.php
+ * @created      24.12.2017
+ * @package      chillerlan\QRCodeExamples
+ * @author       Smiley <smiley@chillerlan.net>
+ * @copyright    2017 Smiley
+ * @license      MIT
+ */
+
+namespace chillerlan\QRCodeExamples;
+
+use chillerlan\QRCode\{QRCode, QROptions, Traits\QRAuthenticator};
+
+/**
+ * using the QRAuthenticator trait
+ */
+class MyAuthenticatorClass{
+	use QRAuthenticator;
+
+	public function getQRCode(){
+		// data fetched from wherever
+		$this->authenticatorSecret = 'SECRETTEST234567';
+		$this->qrOptions = new QROptions(['outputType' => QRCode::OUTPUT_MARKUP_SVG]); // set options if needed
+		$label = 'my label';
+		$issuer = 'example.com';
+
+		return $this->getURIQRCode($label, $issuer);
+	}
+
+}

+ 17 - 0
examples/authenticator.php

@@ -0,0 +1,17 @@
+<?php
+/**
+ *
+ * @filesource   authenticator.php
+ * @created      24.12.2017
+ * @author       Smiley <smiley@chillerlan.net>
+ * @copyright    2017 Smiley
+ * @license      MIT
+ */
+
+namespace chillerlan\QRCodeExamples;
+
+require_once '../vendor/autoload.php';
+
+header('Content-type: image/svg+xml');
+
+echo (new MyAuthenticatorClass)->getQRCode();

+ 106 - 0
examples/html.php

@@ -0,0 +1,106 @@
+<?php
+/**
+ *
+ * @filesource   html.php
+ * @created      21.12.2017
+ * @author       Smiley <smiley@chillerlan.net>
+ * @copyright    2017 Smiley
+ * @license      MIT
+ */
+
+use chillerlan\QRCode\{QRCode, QROptions};
+
+require_once '../vendor/autoload.php';
+
+header('Content-Type: text/html; charset=utf-8');
+
+?>
+<!DOCTYPE html>
+<html lang="en">
+<head>
+	<meta charset="UTF-8"/>
+	<meta name="viewport" content="width=device-width, initial-scale=1.0"/>
+	<title>QRCode test</title>
+	<style>
+		body{
+			margin: 5em;
+			padding: 0;
+		}
+
+		div.qrcode{
+			margin: 0;
+			padding: 0;
+		}
+
+		/* row element */
+		div.qrcode > div {
+			margin: 0;
+			padding: 0;
+			height: 10px;
+		}
+
+		/* column element(s) */
+		div.qrcode > div > span,
+		div.qrcode > div > span {
+			display: inline-block;
+			width: 10px;
+			height: 10px;
+		}
+
+		div.qrcode > div > span {
+			background-color: #ccc;
+		}
+
+		div.qrcode > div > span {
+			background-color: #fff;
+		}
+
+	</style>
+</head>
+<body>
+	<div class="qrcode">
+<?php
+
+	$data = 'https://www.youtube.com/watch?v=DLzxrzFCyOs&t=43s';
+
+	$options = new QROptions([
+		'version' => 5,
+		'outputType' => QRCode::OUTPUT_MARKUP_HTML,
+		'eccLevel' => QRCode::ECC_L,
+		'moduleValues' => [
+			// finder
+			1536 => '#A71111', // dark (true)
+			6    => '#FFBFBF', // light (false)
+			// alignment
+			2560 => '#A70364',
+			10   => '#FFC9C9',
+			// timing
+			3072 => '#98005D',
+			12   => '#FFB8E9',
+			// format
+			3584 => '#003804',
+			14   => '#00FB12',
+			// version
+			4096 => '#650098',
+			16   => '#E0B8FF',
+			// data
+			1024 => '#4A6000',
+			4    => '#ECF9BE',
+			// darkmodule
+			512  => '#080063',
+			// separator
+			8    => '#AFBFBF',
+			// quietzone
+			18   => '#FFFFFF',
+		],
+	]);
+
+	echo (new QRCode($options))->render($data);
+
+?>
+	</div>
+</body>
+</html>
+
+
+

+ 55 - 0
examples/svg.php

@@ -0,0 +1,55 @@
+<?php
+/**
+ *
+ * @filesource   svg.php
+ * @created      21.12.2017
+ * @author       Smiley <smiley@chillerlan.net>
+ * @copyright    2017 Smiley
+ * @license      MIT
+ */
+
+use chillerlan\QRCode\{QRCode, QROptions};
+
+require_once __DIR__.'/../vendor/autoload.php';
+
+$data = 'https://www.youtube.com/watch?v=DLzxrzFCyOs&t=43s';
+
+$options = new QROptions([
+	'version'      => 5,
+	'outputType'   => QRCode::OUTPUT_MARKUP_SVG,
+	'eccLevel'     => QRCode::ECC_L,
+	'scale'        => 10,
+	'moduleValues' => [
+		// finder
+		1536 => '#A71111', // dark (true)
+		6    => '#FFBFBF', // light (false)
+		// alignment
+		2560 => '#A70364',
+		10   => '#FFC9C9',
+		// timing
+		3072 => '#98005D',
+		12   => '#FFB8E9',
+		// format
+		3584 => '#003804',
+		14   => '#00FB12',
+		// version
+		4096 => '#650098',
+		16   => '#E0B8FF',
+		// data
+		1024 => '#4A6000',
+		4    => '#ECF9BE',
+		// darkmodule
+		512  => '#080063',
+		// separator
+		8    => '#AFBFBF',
+		// quietzone
+		18   => '#FFFFFF',
+	],
+]);
+
+header('Content-type: image/svg+xml');
+
+echo (new QRCode($options))->render($data);
+
+
+

+ 29 - 0
examples/text.php

@@ -0,0 +1,29 @@
+<?php
+/**
+ *
+ * @filesource   text.php
+ * @created      21.12.2017
+ * @author       Smiley <smiley@chillerlan.net>
+ * @copyright    2017 Smiley
+ * @license      MIT
+ */
+
+use chillerlan\QRCode\{QRCode, QROptions};
+
+require_once __DIR__.'/../vendor/autoload.php';
+
+$data = 'https://www.youtube.com/watch?v=DLzxrzFCyOs&t=43s';
+
+$options = new QROptions([
+	'version'      => 5,
+	'outputType'   => QRCode::OUTPUT_STRING_TEXT,
+	'eccLevel'     => QRCode::ECC_L,
+]);
+
+// <pre> to view it in a browser
+echo '<pre style="font-size: 75%; line-height: 1;">'.(new QRCode($options))->render($data).'</pre>';
+
+
+
+
+

+ 2 - 2
public/index.html

@@ -48,8 +48,8 @@
 
 	<label for="output_type" >Output</label >
 	<select class="options" id="output_type" name="output_type" >
-		<option value="html" selected="selected"  >Markup - HTML</option >
-		<option value="svg" >Markup - SVG</option >
+		<option value="html" >Markup - HTML</option >
+		<option value="svg"  selected="selected" >Markup - SVG</option >
 		<option value="png">Image - png</option >
 		<option value="jpg" >Image - jpg</option >
 		<option value="gif" >Image - gif</option >