mirror of
https://github.com/chillerlan/php-qrcode.git
synced 2026-10-09 21:35:53 +00:00
:octocat: fix PHPCS config, add Slevomat rules
This commit is contained in:
@@ -21,33 +21,21 @@ require_once __DIR__.'/../vendor/autoload.php';
|
||||
|
||||
class MyCustomOutput extends QROutputAbstract{
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public static function moduleValueIsValid(mixed $value):bool{
|
||||
// TODO: Implement moduleValueIsValid() method. (interface)
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
protected function prepareModuleValue(mixed $value):mixed{
|
||||
// TODO: Implement prepareModuleValue() method. (abstract)
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
protected function getDefaultModuleValue(bool $isDark):mixed{
|
||||
// TODO: Implement getDefaultModuleValue() method. (abstract)
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function dump(string|null $file = null):string{
|
||||
$output = '';
|
||||
|
||||
|
||||
+1
-1
@@ -55,7 +55,7 @@ $options->moduleValues = [
|
||||
|
||||
$out = (new QRCode($options))->render('https://www.youtube.com/watch?v=dQw4w9WgXcQ', __DIR__.'/qrcode.eps');
|
||||
|
||||
if(php_sapi_name() !== 'cli'){
|
||||
if(PHP_SAPI !== 'cli'){
|
||||
// if viewed in the browser, we should push it as file download as EPS isn't usually supported
|
||||
header('Content-type: application/postscript');
|
||||
header('Content-Disposition: filename="qrcode.eps"');
|
||||
|
||||
+2
-2
@@ -11,7 +11,7 @@ use chillerlan\QRCode\{QRCode, QROptions};
|
||||
use chillerlan\QRCode\Data\QRMatrix;
|
||||
use chillerlan\QRCode\Output\QRFpdf;
|
||||
|
||||
require_once __DIR__ . '/../vendor/autoload.php';
|
||||
require_once __DIR__.'/../vendor/autoload.php';
|
||||
|
||||
$options = new QROptions;
|
||||
|
||||
@@ -53,7 +53,7 @@ $options->moduleValues = [
|
||||
|
||||
$out = (new QRCode($options))->render('https://www.youtube.com/watch?v=dQw4w9WgXcQ');
|
||||
|
||||
if(php_sapi_name() !== 'cli'){
|
||||
if(PHP_SAPI !== 'cli'){
|
||||
header('Content-type: application/pdf');
|
||||
}
|
||||
|
||||
|
||||
@@ -24,13 +24,11 @@ require_once __DIR__.'/../vendor/autoload.php';
|
||||
class QRImageWithLogo extends QRGdImagePNG{
|
||||
|
||||
/**
|
||||
* @param string|null $file
|
||||
* @param string|null $logo
|
||||
*
|
||||
* @return string
|
||||
* @throws \chillerlan\QRCode\Output\QRCodeOutputException
|
||||
*/
|
||||
public function dump(string|null $file = null, string|null $logo = null):string{
|
||||
$logo ??= '';
|
||||
|
||||
// set returnResource to true to skip further processing for now
|
||||
$this->options->returnResource = true;
|
||||
|
||||
@@ -45,6 +43,10 @@ class QRImageWithLogo extends QRGdImagePNG{
|
||||
|
||||
$im = imagecreatefrompng($logo);
|
||||
|
||||
if($im === false){
|
||||
throw new QRCodeOutputException('imagecreatefrompng() error');
|
||||
}
|
||||
|
||||
// get logo image size
|
||||
$w = imagesx($im);
|
||||
$h = imagesy($im);
|
||||
|
||||
@@ -19,7 +19,7 @@ use chillerlan\QRCode\Data\QRMatrix;
|
||||
use chillerlan\QRCode\Output\QRGdImagePNG;
|
||||
use chillerlan\Settings\SettingsContainerInterface;
|
||||
|
||||
require_once __DIR__ . '/../vendor/autoload.php';
|
||||
require_once __DIR__.'/../vendor/autoload.php';
|
||||
|
||||
// --------------------
|
||||
// Class definition
|
||||
@@ -27,7 +27,6 @@ require_once __DIR__ . '/../vendor/autoload.php';
|
||||
|
||||
class QRGdRounded extends QRGdImagePNG{
|
||||
|
||||
/** @inheritDoc */
|
||||
public function __construct(SettingsContainerInterface|QROptions $options, QRMatrix $matrix){
|
||||
// enable the internal scaling for better rounding results at scale < 20
|
||||
$options->drawCircularModules = true;
|
||||
@@ -35,7 +34,6 @@ class QRGdRounded extends QRGdImagePNG{
|
||||
parent::__construct($options, $matrix);
|
||||
}
|
||||
|
||||
/** @inheritDoc */
|
||||
protected function module(int $x, int $y, int $M_TYPE):void{
|
||||
|
||||
/**
|
||||
@@ -121,7 +119,7 @@ class QRGdRounded extends QRGdImagePNG{
|
||||
(int)($y * $this->scale + $this->scale / 2),
|
||||
($this->scale - 1),
|
||||
($this->scale - 1),
|
||||
$light
|
||||
$light,
|
||||
);
|
||||
}
|
||||
|
||||
@@ -133,14 +131,14 @@ class QRGdRounded extends QRGdImagePNG{
|
||||
// --------------------
|
||||
|
||||
$options = new QROptions([
|
||||
'version' => 7,
|
||||
'eccLevel' => EccLevel::H,
|
||||
'outputInterface' => QRGdRounded::class,
|
||||
'outputBase64' => false,
|
||||
'scale' => 30,
|
||||
'addLogoSpace' => true,
|
||||
'logoSpaceWidth' => 13,
|
||||
'logoSpaceHeight' => 13,
|
||||
'version' => 7,
|
||||
'eccLevel' => EccLevel::H,
|
||||
'outputInterface' => QRGdRounded::class,
|
||||
'outputBase64' => false,
|
||||
'scale' => 30,
|
||||
'addLogoSpace' => true,
|
||||
'logoSpaceWidth' => 13,
|
||||
'logoSpaceHeight' => 13,
|
||||
]);
|
||||
|
||||
|
||||
|
||||
@@ -23,9 +23,6 @@ require_once __DIR__.'/../vendor/autoload.php';
|
||||
|
||||
class QRImageWithText extends QRGdImagePNG{
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function dump(string|null $file = null, string|null $text = null):string{
|
||||
// set returnResource to true to skip further processing for now
|
||||
$this->options->returnResource = true;
|
||||
|
||||
@@ -14,17 +14,18 @@
|
||||
* @author smiley <smiley@chillerlan.net>
|
||||
* @copyright 2023 smiley
|
||||
* @license MIT
|
||||
*
|
||||
* @noinspection PhpComposerExtensionStubsInspection
|
||||
*/
|
||||
|
||||
use chillerlan\QRCode\{QRCode, QROptions};
|
||||
use chillerlan\QRCode\Data\QRMatrix;
|
||||
use chillerlan\QRCode\Output\QRMarkupSVG;
|
||||
use chillerlan\QRCode\Output\{QRCodeOutputException, QRMarkupSVG};
|
||||
|
||||
require_once __DIR__.'/../vendor/autoload.php';
|
||||
|
||||
class SVGConvert extends QRMarkupSVG{
|
||||
|
||||
/** @inheritDoc */
|
||||
protected function header():string{
|
||||
[$width, $height] = $this->getOutputDimensions();
|
||||
|
||||
@@ -36,7 +37,7 @@ class SVGConvert extends QRMarkupSVG{
|
||||
$this->options->svgPreserveAspectRatio,
|
||||
$this->options->eol,
|
||||
($width * $this->scale), // use the scale option to modify the size
|
||||
($height * $this->scale)
|
||||
($height * $this->scale),
|
||||
);
|
||||
|
||||
if($this->options->svgAddXmlHeader){
|
||||
@@ -46,7 +47,6 @@ class SVGConvert extends QRMarkupSVG{
|
||||
return $header;
|
||||
}
|
||||
|
||||
/** @inheritDoc */
|
||||
public function dump(string|null $file = null):string{
|
||||
$base64 = $this->options->outputBase64;
|
||||
// we don't want the SVG in base64
|
||||
@@ -70,7 +70,13 @@ class SVGConvert extends QRMarkupSVG{
|
||||
|
||||
if($base64){
|
||||
// use finfo to guess the mime type
|
||||
$imageData = $this->toBase64DataURI($imageData, (new finfo(FILEINFO_MIME_TYPE))->buffer($imageData));
|
||||
$mime = (new finfo(FILEINFO_MIME_TYPE))->buffer($imageData);
|
||||
|
||||
if($mime === false){
|
||||
throw new QRCodeOutputException('unable to detect mime type');
|
||||
}
|
||||
|
||||
$imageData = $this->toBase64DataURI($imageData);
|
||||
}
|
||||
|
||||
return $imageData;
|
||||
|
||||
@@ -16,17 +16,11 @@ require_once __DIR__.'/../vendor/autoload.php';
|
||||
|
||||
class QRImagickImageAsBackground extends QRImagick{
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
protected function getDefaultModuleValue(bool $isDark):ImagickPixel{
|
||||
// RGBA, adjust opacity to increase contrast
|
||||
return $this->prepareModuleValue(($isDark) ? '#00000040' : '#ffffffa0');
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
protected function createImage():Imagick{
|
||||
$imagick = new Imagick($this->options->background);
|
||||
$width = $imagick->getImageWidth();
|
||||
|
||||
@@ -55,7 +55,7 @@ class QRImagickWithLogo extends QRImagick{
|
||||
$this->saveToFile($imageData, $file);
|
||||
|
||||
if($this->options->outputBase64){
|
||||
$imageData = $this->toBase64DataURI($imageData, (new finfo(FILEINFO_MIME_TYPE))->buffer($imageData));
|
||||
$imageData = $this->toBase64DataURI($imageData, $this->guessMimeType($imageData));
|
||||
}
|
||||
|
||||
return $imageData;
|
||||
@@ -77,6 +77,8 @@ class ImagickWithLogoOptions extends QROptions{
|
||||
*
|
||||
* of course, we could accept other formats too.
|
||||
* we're not checking for the file type either for simplicity reasons (assuming PNG)
|
||||
*
|
||||
* @throws \chillerlan\QRCode\QRCodeException
|
||||
*/
|
||||
protected function set_pngLogo(string $pngLogo):void{
|
||||
|
||||
|
||||
@@ -75,6 +75,3 @@ header('Content-type: image/png');
|
||||
echo $out;
|
||||
|
||||
exit;
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -56,7 +56,7 @@ try{
|
||||
|
||||
$moduleValues = array_map(function($v){
|
||||
if(preg_match('/[a-f\d]{6}/i', $v) === 1){
|
||||
return in_array($_POST['output_type'], ['png', 'jpg', 'gif'])
|
||||
return in_array($_POST['output_type'], ['png', 'jpg', 'gif'], true)
|
||||
? array_map('hexdec', str_split($v, 2))
|
||||
: '#'.$v ;
|
||||
}
|
||||
@@ -81,7 +81,7 @@ try{
|
||||
|
||||
$qrcode = (new QRCode($options))->render($_POST['inputstring']);
|
||||
|
||||
if(in_array($_POST['output_type'], ['png', 'jpg', 'gif', 'svg'])){
|
||||
if(in_array($_POST['output_type'], ['png', 'jpg', 'gif', 'svg'], true)){
|
||||
$qrcode = '<img alt="qrcode" src="'.$qrcode.'" />';
|
||||
}
|
||||
elseif($_POST['output_type'] === 'text'){
|
||||
|
||||
+1
-1
@@ -60,7 +60,7 @@ catch(Throwable $e){
|
||||
}
|
||||
|
||||
|
||||
if(php_sapi_name() !== 'cli'){
|
||||
if(PHP_SAPI !== 'cli'){
|
||||
header('Content-type: image/svg+xml');
|
||||
|
||||
if(extension_loaded('zlib')){
|
||||
|
||||
@@ -80,9 +80,9 @@ header('Content-type: text/html');
|
||||
<script type="module">
|
||||
import SVGConvert from './SVGConvert.js';
|
||||
|
||||
// SVG DOM element
|
||||
SVGConvert.toDataURI(document.querySelector('svg.qr-svg'), document.getElementById('qr-svg-dest'), 300, 300, 'image/jpeg');
|
||||
// base64 data URI in image element
|
||||
SVGConvert.toDataURI(document.getElementById('qr-svg-base64'), document.getElementById('qr-svg-base64-dest'), 300, 300);
|
||||
// SVG DOM element
|
||||
SVGConvert.toDataURI(document.querySelector('svg.qr-svg'), document.getElementById('qr-svg-dest'), 300, 300, 'image/jpeg');
|
||||
// base64 data URI in image element
|
||||
SVGConvert.toDataURI(document.getElementById('qr-svg-base64'), document.getElementById('qr-svg-base64-dest'), 300, 300);
|
||||
</script>
|
||||
</html>
|
||||
|
||||
@@ -26,17 +26,11 @@ require_once __DIR__.'/../vendor/autoload.php';
|
||||
*/
|
||||
class MeltedSVGQRCodeOutput extends QRMarkupSVG{
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
protected function path(string $path, int $M_TYPE):string{
|
||||
// omit the "fill" and "opacity" attributes on the path element
|
||||
return sprintf('<path class="%s" d="%s"/>', $this->getCssClass($M_TYPE), $path);
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
protected function collectModules(Closure $transform):array{
|
||||
$paths = [];
|
||||
$melt = $this->options->melt; // avoid magic getter in long loops
|
||||
@@ -76,9 +70,6 @@ class MeltedSVGQRCodeOutput extends QRMarkupSVG{
|
||||
return $paths;
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
protected function module(int $x, int $y, int $M_TYPE):string{
|
||||
$bits = $this->matrix->checkNeighbours($x, $y, null);
|
||||
$check = fn(int $all, int $any = 0):bool => ($bits & ($all | (~$any & 0xff))) === $all;
|
||||
@@ -289,7 +280,7 @@ $options->svgDefs = '
|
||||
$out = (new QRCode($options))->render('https://www.youtube.com/watch?v=dQw4w9WgXcQ');
|
||||
|
||||
|
||||
if(php_sapi_name() !== 'cli'){
|
||||
if(PHP_SAPI !== 'cli'){
|
||||
header('Content-type: image/svg+xml');
|
||||
|
||||
if(extension_loaded('zlib')){
|
||||
|
||||
@@ -26,9 +26,6 @@ require_once __DIR__.'/../vendor/autoload.php';
|
||||
// the extended SVG output module
|
||||
class RandomDotsSVGOutput extends QRMarkupSVG{
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
protected function path(string $path, int $M_TYPE):string{
|
||||
// omit the "fill" and "opacity" attributes on the path element
|
||||
return sprintf('<path class="%s" d="%s"/>', $this->getCssClass($M_TYPE), $path);
|
||||
@@ -160,7 +157,7 @@ $out = (new QRCode($options))->render('https://www.youtube.com/watch?v=dQw4w9WgX
|
||||
|
||||
|
||||
// dump the output
|
||||
if(php_sapi_name() !== 'cli'){
|
||||
if(PHP_SAPI !== 'cli'){
|
||||
header('content-type: image/svg+xml');
|
||||
}
|
||||
|
||||
|
||||
@@ -31,9 +31,6 @@ class RoundQuietzoneSVGoutput extends QRMarkupSVG{
|
||||
|
||||
protected float $center;
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
protected function createMarkup(bool $saveToFile):string{
|
||||
// some Pythagorean magick
|
||||
$diameter = sqrt(2 * pow(($this->moduleCount + $this->options->additionalModules), 2));
|
||||
@@ -69,9 +66,6 @@ class RoundQuietzoneSVGoutput extends QRMarkupSVG{
|
||||
return $svg;
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
protected function path(string $path, int $M_TYPE):string{
|
||||
// omit the "fill" and "opacity" attributes on the path element
|
||||
return sprintf('<path class="%s" d="%s"/>', $this->getCssClass($M_TYPE), $path);
|
||||
@@ -141,7 +135,7 @@ class RoundQuietzoneSVGoutput extends QRMarkupSVG{
|
||||
$this->center,
|
||||
round($radius, 5),
|
||||
($this->options->circleRadius * 2),
|
||||
$this->options->eol
|
||||
$this->options->eol,
|
||||
);
|
||||
}
|
||||
|
||||
@@ -159,13 +153,10 @@ class RoundQuietzoneSVGoutput extends QRMarkupSVG{
|
||||
$this->options->svgLogoScale,
|
||||
$this->options->svgLogoCssClass,
|
||||
file_get_contents($this->options->svgLogo),
|
||||
$this->options->eol
|
||||
$this->options->eol,
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
protected function collectModules(Closure $transform):array{
|
||||
$paths = [];
|
||||
$dotColors = $this->options->dotColors; // avoid magic getter in long loops
|
||||
@@ -345,7 +336,7 @@ $options->keepAsSquare = [
|
||||
$out = (new QRCode($options))->render('https://www.youtube.com/watch?v=dQw4w9WgXcQ');
|
||||
|
||||
|
||||
if(php_sapi_name() !== 'cli'){
|
||||
if(PHP_SAPI !== 'cli'){
|
||||
header('Content-type: image/svg+xml');
|
||||
|
||||
if(extension_loaded('zlib')){
|
||||
|
||||
@@ -26,9 +26,6 @@ require_once __DIR__.'/../vendor/autoload.php';
|
||||
*/
|
||||
class QRSvgWithLogo extends QRMarkupSVG{
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
protected function paths():string{
|
||||
$size = (int)ceil($this->moduleCount * $this->options->svgLogoScale);
|
||||
|
||||
@@ -41,9 +38,6 @@ class QRSvgWithLogo extends QRMarkupSVG{
|
||||
return $svg;
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
protected function path(string $path, int $M_TYPE):string{
|
||||
// omit the "fill" and "opacity" attributes on the path element
|
||||
return sprintf('<path class="%s" d="%s"/>', $this->getCssClass($M_TYPE), $path);
|
||||
@@ -63,7 +57,7 @@ class QRSvgWithLogo extends QRMarkupSVG{
|
||||
$this->options->svgLogoScale,
|
||||
$this->options->svgLogoCssClass,
|
||||
file_get_contents($this->options->svgLogo),
|
||||
$this->options->eol
|
||||
$this->options->eol,
|
||||
);
|
||||
}
|
||||
|
||||
@@ -146,7 +140,7 @@ $options->svgDefs = '
|
||||
$out = (new QRCode($options))->render('https://www.youtube.com/watch?v=dQw4w9WgXcQ');
|
||||
|
||||
|
||||
if(php_sapi_name() !== 'cli'){
|
||||
if(PHP_SAPI !== 'cli'){
|
||||
header('Content-type: image/svg+xml');
|
||||
|
||||
if(extension_loaded('zlib')){
|
||||
|
||||
@@ -28,9 +28,6 @@ require_once __DIR__.'/../vendor/autoload.php';
|
||||
*/
|
||||
class QRSvgWithLogoAndCustomShapes extends QRMarkupSVG{
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
protected function paths():string{
|
||||
// make sure connect paths is enabled
|
||||
$this->options->connectPaths = true;
|
||||
@@ -48,9 +45,6 @@ class QRSvgWithLogoAndCustomShapes extends QRMarkupSVG{
|
||||
return $svg;
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
protected function path(string $path, int $M_TYPE):string{
|
||||
// omit the "fill" and "opacity" attributes on the path element
|
||||
return sprintf('<path class="%s" d="%s"/>', $this->getCssClass($M_TYPE), $path);
|
||||
@@ -103,7 +97,7 @@ class QRSvgWithLogoAndCustomShapes extends QRMarkupSVG{
|
||||
'%s<path class="%s" d="%s"/>',
|
||||
$this->options->eol,
|
||||
$this->getCssClass(QRMatrix::M_FINDER_DARK),
|
||||
implode(' ', $finder)
|
||||
implode(' ', $finder),
|
||||
);
|
||||
}
|
||||
|
||||
@@ -121,7 +115,7 @@ class QRSvgWithLogoAndCustomShapes extends QRMarkupSVG{
|
||||
$this->options->svgLogoScale,
|
||||
$this->options->svgLogoCssClass,
|
||||
file_get_contents($this->options->svgLogo),
|
||||
$this->options->eol
|
||||
$this->options->eol,
|
||||
);
|
||||
}
|
||||
|
||||
@@ -199,7 +193,7 @@ $options->svgDefs = '
|
||||
$out = (new QRCode($options))->render('https://www.youtube.com/watch?v=dQw4w9WgXcQ');
|
||||
|
||||
|
||||
if(php_sapi_name() !== 'cli'){
|
||||
if(PHP_SAPI !== 'cli'){
|
||||
header('Content-type: image/svg+xml');
|
||||
|
||||
if(extension_loaded('zlib')){
|
||||
|
||||
+3
-2
@@ -8,7 +8,8 @@
|
||||
* @license MIT
|
||||
*/
|
||||
|
||||
use chillerlan\QRCode\{Data\QRMatrix, QRCode, QROptions};
|
||||
use chillerlan\QRCode\Data\QRMatrix;
|
||||
use chillerlan\QRCode\{QRCode, QROptions};
|
||||
use chillerlan\QRCode\Output\QRMarkupXML;
|
||||
|
||||
require_once __DIR__.'/../vendor/autoload.php';
|
||||
@@ -61,7 +62,7 @@ catch(Throwable $e){
|
||||
}
|
||||
|
||||
|
||||
if(php_sapi_name() !== 'cli'){
|
||||
if(PHP_SAPI !== 'cli'){
|
||||
header('Content-type: '.QRMarkupXML::MIME_TYPE);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user