Skip to content

Commit

Permalink
Merge pull request seandrickson#10 from rizlas/master
Browse files Browse the repository at this point in the history
Plugin update
  • Loading branch information
seandrickson authored Jan 4, 2022
2 parents 6601625 + 1fde494 commit 47d4942
Show file tree
Hide file tree
Showing 6 changed files with 191 additions and 5,115 deletions.
30 changes: 15 additions & 15 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
YOURLS QR Code Plugin
=====================

Allows you to get the QR code by simply clicking on a button in the Admin area (or by adding `.qr` to the end of the short URL.) Can also optionally display a QR code in the share box.

QR codes can be configured to be either PNG or SVG format by default. Appending the extension `.svg` or `.png` to the URL will force the format.
Allows you to get the QR code by simply clicking on a button in the Admin area (or by adding `.qr` to the end of the short URL.) Can also optionally display a QR code in the share box.

Installation
------------

Install via composer using the `composer.json` provided.

Move the `seans-qrcode` folder into the `/users/plugins` folder. Then, activate the plugin in the admin interface. That's all there is to it, but see Configuration below

Requirements
------------

User must have [YOURLS](http://yourls.org/#Install) 1.5.1+ installed. Latest version is tested with YOURLS 1.7.1.
User must have [YOURLS](http://yourls.org/#Install) 1.5.1+ installed. Latest version is tested with YOURLS 1.8.2.

**WARNING**: Does not work with YOURLS 1.6.

Expand All @@ -28,23 +28,23 @@ The plugin requires no special configuration, but there are a few options that y


```php
define("SEAN_QR_WIDTH", 250);
define("SEAN_QR_SCALE", 5);
```

### SEAN_QR_WIDTH
_Interger. Default: 200._
The width (and height) of the generated QR code in pixels. For PNG this will be approximate.
### SEAN_QR_SCALE
_Interger. Default: 5._
The size of a QR code pixel (SVG, IMAGE_*), HTML -> via CSS

### SEAN_QR_LOGO_SPACE
_Interger. Default: 13._
The size in QR modules, multiply with QROptions::$scale for pixel size

### SEAN_QR_ADD_TO_SHAREBOX
_Boolean. Default: false._
_Boolean. Default: true._
Whether to include a QR code in the share boxes. Set to true to enable.

### SEAN_QR_DEFAULT_FMT
_String. 'png' or 'svg'. Default: png._
The default format to generate QR codes in. This can be overridden be adding the appropriate extension to the QR code's URL. eg `http://mydomain.com/bleh.qr.svg` or `http://mydomain.com/bleh.qr.png`

### SEAN_QR_MARGIN
_Interger. Default: 2._
_Interger. Default: 4._
The width of the margin (quiet zone) around the QR, in 'virtual pixels'. A value of 4 is generally recommended, but if you are using the QR code in a context where it is surrounded by white space anyway lower values may work fine.

Bonus
Expand All @@ -57,4 +57,4 @@ Credits

Main functionality of adding a QR code is borrowed from [Ozh's orginal plugin code](https://github.com/YOURLS/YOURLS/wiki/Plugin-%3D-QRCode-ShortURL).

QR code generation made possible by [PHP QR Code](http://phpqrcode.sourceforge.net/) (Google's own QR Code generation, through the Chart Image API [is deprecated](http://googledevelopers.blogspot.com/2012/04/changes-to-deprecation-policies-and-api.html) and will no longer be developed).
QR code generation made possible by [chillerlan/php-qrcode](https://github.com/chillerlan/php-qrcode)
81 changes: 81 additions & 0 deletions seans-qrcode/QRImageWithLogo.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
<?php
/**
* Class QRImageWithLogo
*
* @filesource QRImageWithLogo.php
* @created 18.11.2020
* @package chillerlan\QRCodeExamples
* @author smiley <[email protected]>
* @copyright 2020 smiley
* @license MIT
*
* @noinspection PhpComposerExtensionStubsInspection
*/

// namespace chillerlan\QRCode;

use chillerlan\QRCode\Output\{QRCodeOutputException, QRImage};

use function imagecopyresampled, imagecreatefrompng, imagesx, imagesy, is_file, is_readable;

/**
* @property \chillerlan\QRCodeExamples\LogoOptions $options
*/
class QRImageWithLogo extends QRImage{

/**
* @param string|null $file
* @param string|null $logo
*
* @return string
* @throws \chillerlan\QRCode\Output\QRCodeOutputException
*/
public function dump(string $file = null, string $logo = null):string{
// set returnResource to true to skip further processing for now
$this->options->returnResource = true;

// of course you could accept other formats too (such as resource or Imagick)
// i'm not checking for the file type either for simplicity reasons (assuming PNG)
if(!is_file($logo) || !is_readable($logo)){
throw new QRCodeOutputException('invalid logo');
}

$this->matrix->setLogoSpace(
$this->options->logoSpaceWidth,
$this->options->logoSpaceHeight
// not utilizing the position here
);

// there's no need to save the result of dump() into $this->image here
parent::dump($file);

$im = imagecreatefrompng($logo);

// get logo image size
$w = imagesx($im);
$h = imagesy($im);

// set new logo size, leave a border of 1 module (no proportional resize/centering)
$lw = ($this->options->logoSpaceWidth - 2) * $this->options->scale;
$lh = ($this->options->logoSpaceHeight - 2) * $this->options->scale;

// get the qrcode size
$ql = $this->matrix->size() * $this->options->scale;

// scale the logo and copy it over. done!
imagecopyresampled($this->image, $im, ($ql - $lw) / 2, ($ql - $lh) / 2, 0, 0, $lw, $lh, $w, $h);

$imageData = $this->dumpImage();

if($file !== null){
$this->saveToFile($imageData, $file);
}

if($this->options->imageBase64){
$imageData = 'data:image/'.$this->options->outputType.';base64,'.base64_encode($imageData);
}

return $imageData;
}

}
8 changes: 8 additions & 0 deletions seans-qrcode/composer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"require": {
"php": "^8.0",
"chillerlan/php-qrcode": "4.3",
"ext-mbstring": "*",
"ext-gd": "*"
}
}
Binary file added seans-qrcode/logo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit 47d4942

Please sign in to comment.