Warning: chmod(): Operation not permitted in /var/www/hopeinstoughton_www/wp-content/plugins/simple-universal-google-analytics/main.php on line 8 [0] in function chmod in /var/www/hopeinstoughton_www/wp-content/plugins/simple-universal-google-analytics/main.php on line 8 [1] in function include_once in /var/www/hopeinstoughton_www/wp-settings.php on line 560 [2] in function require_once in /var/www/hopeinstoughton_www/wp-config.php on line 85 [3] in function require_once in /var/www/hopeinstoughton_www/wp-load.php on line 50 [4] in function require_once in /var/www/hopeinstoughton_www/wp-blog-header.php on line 13 [5] in function require in /var/www/hopeinstoughton_www/index.php on line 17
| Server IP : 94.177.8.99 / Your IP : 216.73.217.165 Web Server : Apache/2.4.58 (Ubuntu) System : Linux aries 6.8.0-134-generic #134-Ubuntu SMP PREEMPT_DYNAMIC Fri Jun 26 18:43:11 UTC 2026 x86_64 User : www-data ( 33) PHP Version : 8.1.34 Disable Function : NONE MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : OFF | Sudo : ON | Pkexec : OFF Directory : /var/www/kjvdictionary_store/modules/qrCode/model/ |
Upload File : |
<?php // dynamic qrcodes
// requires php5-gd
require_once __DIR__ . '/qrcode.php';
class Qrcode_Model extends Model {
private $info;
private $png;
private $fgcol;
private $startofrow;
private $num_cols;
private $num_rows;
private $colorStart;
private $colorEnd;
private $markers;
function __construct() {
parent::__construct();
}
public function generateQRCode($info) {
$this->info = $info;
$data = $info->text ?? '(text goes here)';
$qrcode = new QRcode($data, $info->quality ?? 'H');
$barcode_array = $qrcode->getBarcodeArray();
$this->markers = $qrcode->ALIGNMENTS;
$cols = 2 + max($barcode_array['num_cols'], $barcode_array['num_rows']);
$size = $info->size ?? '200x200';
[$wd, $ht] = explode('x', $size);
$cellsize = intval($wd / $cols);
$barcode_array['code'] = $data;
$colorfg = $info->colorStart ?? '#000';
$colorbg = $info->colorBackground ?? FALSE;
$colorfg2 = $info->colorEnd ?? $colorfg;
$this->colorEnd = $this->hex2rgb($colorfg2);
$imagetext = $this->getBarcodePngData($barcode_array, $cellsize, $cellsize, $colorfg, $colorbg);
$info->imagedata = $imagetext;
}
function _generateGradientsInterpolate($pBegin, $pEnd, $pStep, $pMax) {
if ($pBegin < $pEnd) {
return (($pEnd - $pBegin) * ($pStep / $pMax)) + $pBegin;
} else {
return (($pBegin - $pEnd) * (1 - ($pStep / $pMax))) + $pEnd;
}
}
public function generateBlip($r, $c, $x, $y, $w, $h) {
if ($this->startofrow) {
$this->startofrow = FALSE;
$steps = $this->num_rows;
$theR = $this->_generateGradientsInterpolate($this->colorStart[0], $this->colorEnd[0], $r, $steps);
$theG = $this->_generateGradientsInterpolate($this->colorStart[1], $this->colorEnd[1], $r, $steps);
$theB = $this->_generateGradientsInterpolate($this->colorStart[2], $this->colorEnd[2], $r, $steps);
$this->fgcol = imagecolorallocate($this->png, $theR, $theG, $theB);
}
imagefilledrectangle($this->png, $x, $y, ($x + $w - 1), ($y + $h - 1), $this->fgcol);
}
private function isMarkerStart(&$barcode_array, $r, $c, $w, $h) {
foreach($this->markers as $m) {
if ($r == $m['y'] && $c == $m['x']) {
// clear out items
$sz = $m['sz'];
for($i = 0; $i < $sz; $i++) {
for($j = 0; $j < $sz; $j++) {
$barcode_array['bcode'][$r + $i][$c + $j] = 0;
}
}
// draw the new shape
//
return $sz;
}
}
return 0;
}
function hex2rgb($hex) {
$hex = str_replace('#', '', $hex);
if(strlen($hex) == 3) {
$r = hexdec(substr($hex,0,1).substr($hex,0,1));
$g = hexdec(substr($hex,1,1).substr($hex,1,1));
$b = hexdec(substr($hex,2,1).substr($hex,2,1));
} else {
$r = hexdec(substr($hex,0,2));
$g = hexdec(substr($hex,2,2));
$b = hexdec(substr($hex,4,2));
}
return [ $r, $g, $b ];
}
/**
* Return a PNG image representation of barcode (requires GD or Imagick library).
* @param $w (int) Width of a single rectangle element in pixels.
* @param $h (int) Height of a single rectangle element in pixels.
* @param $color (array) RGB (0-255) foreground color for bar elements (background is transparent).
* @return image or false in case of error.
* @public
*/
// this version has a white border around it
public function getBarcodePngData($barcode_array, $w=3, $h=3, $colorfg, $colorbg) {
// calculate image size
$width = (($barcode_array['num_cols'] + 2) * $w);
$height = (($barcode_array['num_rows'] + 2) * $h);
$this->num_cols = $barcode_array['num_cols'];
$this->num_rows = $barcode_array['num_rows'];
// GD library
$imagick = false;
$this->png = imagecreate($width, $height);
$transparent = $colorbg === FALSE;
if ($transparent) $colorbg = '#fff';
$rgb = $this->hex2rgb($colorbg);
$bgcol = imagecolorallocate($this->png, $rgb[0], $rgb[1], $rgb[2]);
if ($transparent) imagecolortransparent($this->png, $bgcol);
$rgb = $this->hex2rgb($colorfg);
$this->colorStart = $rgb;
$this->fgcol = imagecolorallocate($this->png, $rgb[0], $rgb[1], $rgb[2]);
// print barcode elements
$y = 0;
// for each row
for ($r = -1; $r <= $barcode_array['num_rows']; ++$r) {
$x = 0;
$this->startofrow = TRUE;
// for each column
for ($c = -1; $c <= $barcode_array['num_cols']; ++$c) {
//if ($this->isMarkerStart($barcode_array, $r, $c, $w, $h)) {
//}
if (($barcode_array['bcode'][$r][$c] ?? 0) > 0) {
$this->generateBlip($r, $c, $x, $y, $w, $h); // draw a single barcode cell
} else {
// space for graphic?
}
$x += $w;
}
$y += $h;
}
ob_start();
imagepng($this->png);
$imagedata = ob_get_clean();
imagedestroy($this->png);
return $imagedata;
// putAlignmentMarker is smaller bottom right square
// putFinderPattern are the larger ones
}
}