Compare commits
23 commits
2.0.0-beta
...
main
Author | SHA1 | Date | |
---|---|---|---|
|
3c6fbcde2f | ||
|
e013ef7abe | ||
|
b4ef98673f | ||
dfe393384c | |||
020c3274e1 | |||
1503b0dfc8 | |||
|
d45ebbea70 | ||
f205f36b80 | |||
fc02a7e3da | |||
a706b97a1c | |||
d0f211f61e | |||
80aa7f5e95 | |||
8814307d86 | |||
5e455c1499 | |||
fdfa947fc0 | |||
8fdfb1b0a0 | |||
449d9634db | |||
acc7409bfe | |||
68cbec8a8d | |||
147a25c93f | |||
6832804dc0 | |||
b9af8aced5 | |||
9b147ecc37 |
609 changed files with 20090 additions and 38061 deletions
7
.gitignore
vendored
7
.gitignore
vendored
|
@ -1,3 +1,4 @@
|
|||
.directory
|
||||
css/*
|
||||
!css/.gitkeep
|
||||
/.directory
|
||||
/css/*
|
||||
!/css/.gitkeep
|
||||
/composer.lock
|
||||
|
|
16
CHANGELOG.md
16
CHANGELOG.md
|
@ -4,11 +4,23 @@ All notable changes to this project will be documented in this file.
|
|||
|
||||
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
|
||||
|
||||
## Unreleased
|
||||
## 2.0.1 - 2023-07-08
|
||||
|
||||
### Added
|
||||
|
||||
* Indonesian localization
|
||||
* Basque localization
|
||||
|
||||
### Changed
|
||||
|
||||
* Update dependencies
|
||||
|
||||
## 2.0.0 - 2022-06-07
|
||||
|
||||
### Added
|
||||
|
||||
* Occitan l10n (PR [#10](https://code.antopie.org/miraty/libreqr/pulls/10))
|
||||
* Composer
|
||||
|
||||
### Changed
|
||||
|
||||
|
@ -16,7 +28,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
|
|||
* Output generated QR code with `data:` URI
|
||||
* Change the QR code generation library
|
||||
* Use less.php instead of lesserphp
|
||||
* Use the prefers-color-scheme CSS feature to let the client choose its prefered theme (dark/light)
|
||||
* Use the prefers-color-scheme CSS feature to let the client choose its preferred theme (dark/light)
|
||||
|
||||
### Removed
|
||||
|
||||
|
|
1370
LICENSE.html
1370
LICENSE.html
File diff suppressed because it is too large
Load diff
64
README.md
64
README.md
|
@ -1,6 +1,4 @@
|
|||
# ![](themes/dark/icons/32.png) LibreQR
|
||||
|
||||
[Lire ceci en français](README_fr.md)
|
||||
# LibreQR
|
||||
|
||||
A PHP Web interface for generating QR codes.
|
||||
|
||||
|
@ -12,74 +10,54 @@ A LibreQR instance is available at <https://qr.antopie.org>.
|
|||
|
||||
### Generic
|
||||
|
||||
Just place this source code in a Web server with PHP.
|
||||
Just place this source code in a Web server with PHP8.0+, extensions `gd`, `mbstring` and `iconv`, and writing rights on the `css/` directory.
|
||||
|
||||
`wget https://code.antopie.org/miraty/libreqr/archive/1.3.0.zip`
|
||||
#### Security hardening
|
||||
|
||||
GD extension is required.
|
||||
|
||||
`apt install php7.3-gd`
|
||||
|
||||
LibreQR need writing rights on the `css/` directory.
|
||||
##### HTTP headers
|
||||
|
||||
Your HTTP server can reply the following headers:
|
||||
```
|
||||
chown -R www-data:www-data /var/www/libreqr/css
|
||||
chmod -R 600 /var/www/libreqr/css
|
||||
Content-Security-Policy: default-src 'none'; img-src 'self' data:; style-src 'self'; frame-ancestors 'none'; form-action 'self';
|
||||
Referrer-Policy: no-referrer
|
||||
```
|
||||
|
||||
##### PHP-FPM chroot
|
||||
|
||||
LibreQR can be chrooted using PHP-FPM.
|
||||
|
||||
### YunoHost
|
||||
|
||||
There is [a package](https://code.antopie.org/miraty/qr_ynh/) for [YunoHost](https://yunohost.org/).
|
||||
|
||||
For historical reasons, LibreQR is technically named `qr` in YunoHost.
|
||||
|
||||
You can install it from the WebAdmin or with this command :
|
||||
|
||||
You can install it from the WebAdmin or with this command:
|
||||
```
|
||||
sudo yunohost app install qr
|
||||
```
|
||||
|
||||
## Themes
|
||||
|
||||
### Change theme
|
||||
Themes are located in `themes/*`, the default theme is in `themes/libreqr/`.
|
||||
|
||||
In config.inc.php, set $theme to the wanted theme.
|
||||
|
||||
By default, 3 themes are offered:
|
||||
|
||||
* dark, the default dark theme. Used here: <https://qr.antopie.org>
|
||||
* light, the light theme.
|
||||
* parinux, a blue theme, made for [Bastet](https://bastet.parinux.org), the [Parinux](https://parinux.org)'s CHATON. Used here: <https://codeqr.parinux.org>
|
||||
|
||||
### Make a theme
|
||||
|
||||
* Copy themes/dark to themes/[new theme's name]
|
||||
* Fill theme.php according to CSS colors you want
|
||||
* Change the source.png image according to your theme
|
||||
* To automatically generate favicons with the rights sizes, use `php themes/resize.php [theme's name]`
|
||||
|
||||
This last step will need [ImageMagick](https://imagemagick.org) and [pngquant](https://pngquant.org) to be installed.
|
||||
|
||||
```apt install imagemagick pngquant```
|
||||
You can customize your LibreQR instance look by changing the colors in `theme.php`, the logo in `logo.less` or the icons in `icons/<size>.png` (then list the sizes in `theme.php`).
|
||||
|
||||
## Contribute
|
||||
|
||||
If you want to report a bug, you can open an issue at <https://code.antopie.org/miraty/libreqr/issues> after creating an account (prefered method) or contact me in another way.
|
||||
The public forge is <https://code.antopie.org/miraty/libreqr>. You can open issues and pull requests there.
|
||||
|
||||
### Translations
|
||||
|
||||
You can add your translations in `locales/<language-code>.php`.
|
||||
|
||||
## Contact
|
||||
|
||||
If you want to contact me, for instance to report a bug or ask me a question about installing or using LibreQR, you can get my contact details on <https://miraty.antopie.org>.
|
||||
|
||||
## Libraries
|
||||
|
||||
This source code includes:
|
||||
|
||||
* [CodeItNow Barcode & QrCode Generator](https://github.com/codeitnowin/barcode-generator) to generate QR codes
|
||||
* [Less.php](https://github.com/wikimedia/less.php) to compile [Less](http://lesscss.org)
|
||||
You can get my contact details on <https://miraty.antopie.org/>, feel free to use them if you want more informations about using or contributing to LibreQR.
|
||||
|
||||
## License
|
||||
|
||||
[AGPLv3+](https://code.antopie.org/miraty/libreqr/src/branch/main/LICENSE)
|
||||
LibreQR is published under [AGPLv3+](https://code.antopie.org/miraty/libreqr/src/branch/main/LICENSE). Librairies located in the `vendor` subdirectory use their own licenses.
|
||||
|
||||
LibreQR is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
|
||||
|
||||
|
|
88
README_fr.md
88
README_fr.md
|
@ -1,88 +0,0 @@
|
|||
# ![](themes/dark/icons/32.png) LibreQR
|
||||
|
||||
[Read this in english](README.md)
|
||||
|
||||
Une interface Web en PHP pour générer des codes QR.
|
||||
|
||||
## Démo
|
||||
|
||||
Une instance de LibreQR est disponible sur <https://qr.antopie.org>.
|
||||
|
||||
## Installation
|
||||
|
||||
### Générique
|
||||
|
||||
Placez simplement ce code source dans un serveur Web avec PHP.
|
||||
|
||||
`wget https://code.antopie.org/miraty/libreqr/archive/1.3.0.zip`
|
||||
|
||||
L'extension GD est requise.
|
||||
|
||||
`apt install php7.3-gd`
|
||||
|
||||
LibreQR a besoin des permissions d'écriture dans le dossier `css/`.
|
||||
|
||||
```
|
||||
chown -R www-data:www-data /var/www/libreqr/css
|
||||
chmod -R 600 /var/www/libreqr/css
|
||||
```
|
||||
|
||||
### YunoHost
|
||||
|
||||
Il y a [un paquet](https://code.antopie.org/miraty/qr_ynh/) pour [YunoHost](https://yunohost.org/).
|
||||
|
||||
Pour des raisons historiques, LibreQR est techniquement nommée `qr` dans YunoHost.
|
||||
|
||||
Vous pouvez l'installer depuis l'interface Web d'administration ou avec cette commande :
|
||||
|
||||
```
|
||||
sudo yunohost app install qr
|
||||
```
|
||||
|
||||
## Thèmes
|
||||
|
||||
### Changer de thème
|
||||
|
||||
Dans config.inc.php, donnez à $theme le nom du thème voulu.
|
||||
|
||||
Par défaut, trois thèmes sont proposés :
|
||||
|
||||
* dark, le thème par défaut, sombre. Il est utilisé ici : <https://qr.antopie.org>
|
||||
* light, thème clair
|
||||
* parinux, un thème bleu, créé pour [Bastet](https://bastet.parinux.org), le CHATON de [Parinux](https://parinux.org). Il est utilisé ici : <https://codeqr.parinux.org>
|
||||
|
||||
### Créer un thème
|
||||
|
||||
* Copiez themes/dark vers themes/[nom de votre thème]
|
||||
* Complétez theme.php en fonction des couleurs CSS voulues dans l'interface
|
||||
* Modifiez l'image source.png en fonction de votre thème
|
||||
* Pour générer automatiquement les icônes aux tailles correctes, utilisez `php themes/resize.php [nom du thème]`
|
||||
|
||||
Cette dernière étape nécessite d'avoir installé [ImageMagick](https://imagemagick.org) et [pngquant](https://pngquant.org).
|
||||
|
||||
```apt install imagemagick pngquant```
|
||||
|
||||
## Contribuer
|
||||
|
||||
Si vous souhaitez rapporter un bug, vous pouvez ouvrir un ticket sur <https://code.antopie.org/miraty/libreqr/issues> après vous être créé un compte (méthode préférée) ou me contacter d'une autre manière.
|
||||
|
||||
## Contact
|
||||
|
||||
Si vous voulez me contacter, par exemple pour signaler un bug ou me poser une question sur l'installation ou l'utilisation de LibreQR, vous trouverez des moyens de me contacter sur <https://miraty.antopie.org>.
|
||||
|
||||
## Bibliothèques tierces
|
||||
|
||||
Ce code source inclus :
|
||||
|
||||
* [CodeItNow Barcode & QrCode Generator](https://github.com/codeitnowin/barcode-generator) pour générer les codes QR
|
||||
* [less.php](https://github.com/wikimedia/less.php) pour compiler le [Less](http://lesscss.org)
|
||||
|
||||
## Licence
|
||||
|
||||
[AGPLv3+](https://code.antopie.org/miraty/libreqr/src/branch/main/LICENSE)
|
||||
|
||||
LibreQR est un logiciel libre ; vous pouvez le diffuser et le modifier suivant les termes de la GNU Affero General Public License telle que publiée par la Free Software Foundation ; soit la version 3 de cette licence, soit (à votre convenance) une version ultérieure.
|
||||
|
||||
LibreQR est diffusé dans l’espoir qu’il sera utile, mais SANS AUCUNE GARANTIE ; sans même une garantie implicite de COMMERCIALISATION ou d’ADÉQUATION À UN USAGE PARTICULIER. Voyez la GNU Affero General Public License pour plus de détails.
|
||||
|
||||
Vous devriez avoir reçu une copie de la GNU Affero General Public License avec ce code. Sinon, consultez <https://www.gnu.org/licenses/>
|
|
@ -1,31 +0,0 @@
|
|||
<?php
|
||||
/**
|
||||
*--------------------------------------------------------------------
|
||||
*
|
||||
* Argument Exception
|
||||
*
|
||||
*--------------------------------------------------------------------
|
||||
*
|
||||
* @author Akhtar Khan <er.akhtarkhan@gmail.com>
|
||||
* @link http://www.codeitnow.in
|
||||
* @package https://github.com/codeitnowin/barcode-generator
|
||||
*/
|
||||
|
||||
namespace CodeItNow\BarcodeBundle\Generator;
|
||||
use Exception;
|
||||
|
||||
class CINArgumentException extends Exception {
|
||||
protected $param;
|
||||
|
||||
/**
|
||||
* Constructor with specific message for a parameter.
|
||||
*
|
||||
* @param string $message
|
||||
* @param string $param
|
||||
*/
|
||||
public function __construct($message, $param) {
|
||||
$this->param = $param;
|
||||
parent::__construct($message, 20000);
|
||||
}
|
||||
}
|
||||
?>
|
|
@ -1,439 +0,0 @@
|
|||
<?php
|
||||
/**
|
||||
*--------------------------------------------------------------------
|
||||
*
|
||||
* Base class for Barcode 1D and 2D
|
||||
*
|
||||
*--------------------------------------------------------------------
|
||||
* @author Akhtar Khan <er.akhtarkhan@gmail.com>
|
||||
* @link http://www.codeitnow.in
|
||||
* @package https://github.com/codeitnowin/barcode-generator
|
||||
*/
|
||||
namespace CodeItNow\BarcodeBundle\Generator;
|
||||
use CodeItNow\BarcodeBundle\Generator\CINColor;
|
||||
use CodeItNow\BarcodeBundle\Generator\CINLabel;
|
||||
use CodeItNow\BarcodeBundle\Generator\CINArgumentException;
|
||||
use CodeItNow\BarcodeBundle\Generator\CINDrawException;
|
||||
|
||||
abstract class CINBarcode {
|
||||
const COLOR_BG = 0;
|
||||
const COLOR_FG = 1;
|
||||
|
||||
protected $colorFg, $colorBg; // Color Foreground, Barckground
|
||||
protected $scale; // Scale of the graphic, default: 1
|
||||
protected $offsetX, $offsetY; // Position where to start the drawing
|
||||
protected $labels = array(); // Array of CINLabel
|
||||
protected $pushLabel = array(0, 0); // Push for the label, left and top
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*/
|
||||
protected function __construct() {
|
||||
$this->setOffsetX(0);
|
||||
$this->setOffsetY(0);
|
||||
$this->setForegroundColor(0x000000);
|
||||
$this->setBackgroundColor(0xffffff);
|
||||
$this->setScale(1);
|
||||
}
|
||||
|
||||
/**
|
||||
* Parses the text before displaying it.
|
||||
*
|
||||
* @param mixed $text
|
||||
*/
|
||||
public function parse($text) {
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the foreground color of the barcode.
|
||||
*
|
||||
* @return CINColor
|
||||
*/
|
||||
public function getForegroundColor() {
|
||||
return $this->colorFg;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the foreground color of the barcode. It could be a CINColor
|
||||
* value or simply a language code (white, black, yellow...) or hex value.
|
||||
*
|
||||
* @param mixed $code
|
||||
*/
|
||||
public function setForegroundColor($code) {
|
||||
if ($code instanceof CINColor) {
|
||||
$this->colorFg = $code;
|
||||
} else {
|
||||
$this->colorFg = new CINColor($code);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the background color of the barcode.
|
||||
*
|
||||
* @return CINColor
|
||||
*/
|
||||
public function getBackgroundColor() {
|
||||
return $this->colorBg;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the background color of the barcode. It could be a CINColor
|
||||
* value or simply a language code (white, black, yellow...) or hex value.
|
||||
*
|
||||
* @param mixed $code
|
||||
*/
|
||||
public function setBackgroundColor($code) {
|
||||
if ($code instanceof CINColor) {
|
||||
$this->colorBg = $code;
|
||||
} else {
|
||||
$this->colorBg = new CINColor($code);
|
||||
}
|
||||
|
||||
foreach ($this->labels as $label) {
|
||||
$label->setBackgroundColor($this->colorBg);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the color.
|
||||
*
|
||||
* @param mixed $fg
|
||||
* @param mixed $bg
|
||||
*/
|
||||
public function setColor($fg, $bg) {
|
||||
$this->setForegroundColor($fg);
|
||||
$this->setBackgroundColor($bg);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the scale of the barcode.
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function getScale() {
|
||||
return $this->scale;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the scale of the barcode in pixel.
|
||||
* If the scale is lower than 1, an exception is raised.
|
||||
*
|
||||
* @param int $scale
|
||||
*/
|
||||
public function setScale($scale) {
|
||||
$scale = intval($scale);
|
||||
if ($scale <= 0) {
|
||||
throw new CINArgumentException('The scale must be larger than 0.', 'scale');
|
||||
}
|
||||
|
||||
$this->scale = $scale;
|
||||
}
|
||||
|
||||
/**
|
||||
* Abstract method that draws the barcode on the resource.
|
||||
*
|
||||
* @param resource $im
|
||||
*/
|
||||
public abstract function draw($im);
|
||||
|
||||
/**
|
||||
* Returns the maximal size of a barcode.
|
||||
* [0]->width
|
||||
* [1]->height
|
||||
*
|
||||
* @param int $w
|
||||
* @param int $h
|
||||
* @return int[]
|
||||
*/
|
||||
public function getDimension($w, $h) {
|
||||
$labels = $this->getBiggestLabels(false);
|
||||
$pixelsAround = array(0, 0, 0, 0); // TRBL
|
||||
if (isset($labels[CINLabel::POSITION_TOP])) {
|
||||
$dimension = $labels[CINLabel::POSITION_TOP]->getDimension();
|
||||
$pixelsAround[0] += $dimension[1];
|
||||
}
|
||||
|
||||
if (isset($labels[CINLabel::POSITION_RIGHT])) {
|
||||
$dimension = $labels[CINLabel::POSITION_RIGHT]->getDimension();
|
||||
$pixelsAround[1] += $dimension[0];
|
||||
}
|
||||
|
||||
if (isset($labels[CINLabel::POSITION_BOTTOM])) {
|
||||
$dimension = $labels[CINLabel::POSITION_BOTTOM]->getDimension();
|
||||
$pixelsAround[2] += $dimension[1];
|
||||
}
|
||||
|
||||
if (isset($labels[CINLabel::POSITION_LEFT])) {
|
||||
$dimension = $labels[CINLabel::POSITION_LEFT]->getDimension();
|
||||
$pixelsAround[3] += $dimension[0];
|
||||
}
|
||||
|
||||
$finalW = ($w + $this->offsetX) * $this->scale;
|
||||
$finalH = ($h + $this->offsetY) * $this->scale;
|
||||
|
||||
// This section will check if a top/bottom label is too big for its width and left/right too big for its height
|
||||
$reversedLabels = $this->getBiggestLabels(true);
|
||||
foreach ($reversedLabels as $label) {
|
||||
$dimension = $label->getDimension();
|
||||
$alignment = $label->getAlignment();
|
||||
if ($label->getPosition() === CINLabel::POSITION_LEFT || $label->getPosition() === CINLabel::POSITION_RIGHT) {
|
||||
if ($alignment === CINLabel::ALIGN_TOP) {
|
||||
$pixelsAround[2] = max($pixelsAround[2], $dimension[1] - $finalH);
|
||||
} elseif ($alignment === CINLabel::ALIGN_CENTER) {
|
||||
$temp = ceil(($dimension[1] - $finalH) / 2);
|
||||
$pixelsAround[0] = max($pixelsAround[0], $temp);
|
||||
$pixelsAround[2] = max($pixelsAround[2], $temp);
|
||||
} elseif ($alignment === CINLabel::ALIGN_BOTTOM) {
|
||||
$pixelsAround[0] = max($pixelsAround[0], $dimension[1] - $finalH);
|
||||
}
|
||||
} else {
|
||||
if ($alignment === CINLabel::ALIGN_LEFT) {
|
||||
$pixelsAround[1] = max($pixelsAround[1], $dimension[0] - $finalW);
|
||||
} elseif ($alignment === CINLabel::ALIGN_CENTER) {
|
||||
$temp = ceil(($dimension[0] - $finalW) / 2);
|
||||
$pixelsAround[1] = max($pixelsAround[1], $temp);
|
||||
$pixelsAround[3] = max($pixelsAround[3], $temp);
|
||||
} elseif ($alignment === CINLabel::ALIGN_RIGHT) {
|
||||
$pixelsAround[3] = max($pixelsAround[3], $dimension[0] - $finalW);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$this->pushLabel[0] = $pixelsAround[3];
|
||||
$this->pushLabel[1] = $pixelsAround[0];
|
||||
|
||||
$finalW = ($w + $this->offsetX) * $this->scale + $pixelsAround[1] + $pixelsAround[3];
|
||||
$finalH = ($h + $this->offsetY) * $this->scale + $pixelsAround[0] + $pixelsAround[2];
|
||||
|
||||
return array($finalW, $finalH);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the X offset.
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function getOffsetX() {
|
||||
return $this->offsetX;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the X offset.
|
||||
*
|
||||
* @param int $offsetX
|
||||
*/
|
||||
public function setOffsetX($offsetX) {
|
||||
$offsetX = intval($offsetX);
|
||||
if ($offsetX < 0) {
|
||||
throw new CINArgumentException('The offset X must be 0 or larger.', 'offsetX');
|
||||
}
|
||||
|
||||
$this->offsetX = $offsetX;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the Y offset.
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function getOffsetY() {
|
||||
return $this->offsetY;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the Y offset.
|
||||
*
|
||||
* @param int $offsetY
|
||||
*/
|
||||
public function setOffsetY($offsetY) {
|
||||
$offsetY = intval($offsetY);
|
||||
if ($offsetY < 0) {
|
||||
throw new CINArgumentException('The offset Y must be 0 or larger.', 'offsetY');
|
||||
}
|
||||
|
||||
$this->offsetY = $offsetY;
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds the label to the drawing.
|
||||
*
|
||||
* @param CINLabel $label
|
||||
*/
|
||||
public function addLabel(CINLabel $label) {
|
||||
$label->setBackgroundColor($this->colorBg);
|
||||
$label->setForegroundColor($this->colorFg);
|
||||
$this->labels[] = $label;
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes the label from the drawing.
|
||||
*
|
||||
* @param CINLabel $label
|
||||
*/
|
||||
public function removeLabel(CINLabel $label) {
|
||||
$remove = -1;
|
||||
$c = count($this->labels);
|
||||
for ($i = 0; $i < $c; $i++) {
|
||||
if ($this->labels[$i] === $label) {
|
||||
$remove = $i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if ($remove > -1) {
|
||||
array_splice($this->labels, $remove, 1);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Clears the labels.
|
||||
*/
|
||||
public function clearLabels() {
|
||||
$this->labels = array();
|
||||
}
|
||||
|
||||
/**
|
||||
* Draws the text.
|
||||
* The coordinate passed are the positions of the barcode.
|
||||
* $x1 and $y1 represent the top left corner.
|
||||
* $x2 and $y2 represent the bottom right corner.
|
||||
*
|
||||
* @param resource $im
|
||||
* @param int $x1
|
||||
* @param int $y1
|
||||
* @param int $x2
|
||||
* @param int $y2
|
||||
*/
|
||||
protected function drawText($im, $x1, $y1, $x2, $y2) {
|
||||
foreach ($this->labels as $label) {
|
||||
$label->draw($im,
|
||||
($x1 + $this->offsetX) * $this->scale + $this->pushLabel[0],
|
||||
($y1 + $this->offsetY) * $this->scale + $this->pushLabel[1],
|
||||
($x2 + $this->offsetX) * $this->scale + $this->pushLabel[0],
|
||||
($y2 + $this->offsetY) * $this->scale + $this->pushLabel[1]);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Draws 1 pixel on the resource at a specific position with a determined color.
|
||||
*
|
||||
* @param resource $im
|
||||
* @param int $x
|
||||
* @param int $y
|
||||
* @param int $color
|
||||
*/
|
||||
protected function drawPixel($im, $x, $y, $color = self::COLOR_FG) {
|
||||
$xR = ($x + $this->offsetX) * $this->scale + $this->pushLabel[0];
|
||||
$yR = ($y + $this->offsetY) * $this->scale + $this->pushLabel[1];
|
||||
|
||||
// We always draw a rectangle
|
||||
imagefilledrectangle($im,
|
||||
$xR,
|
||||
$yR,
|
||||
$xR + $this->scale - 1,
|
||||
$yR + $this->scale - 1,
|
||||
$this->getColor($im, $color));
|
||||
}
|
||||
|
||||
/**
|
||||
* Draws an empty rectangle on the resource at a specific position with a determined color.
|
||||
*
|
||||
* @param resource $im
|
||||
* @param int $x1
|
||||
* @param int $y1
|
||||
* @param int $x2
|
||||
* @param int $y2
|
||||
* @param int $color
|
||||
*/
|
||||
protected function drawRectangle($im, $x1, $y1, $x2, $y2, $color = self::COLOR_FG) {
|
||||
if ($this->scale === 1) {
|
||||
imagefilledrectangle($im,
|
||||
($x1 + $this->offsetX) + $this->pushLabel[0],
|
||||
($y1 + $this->offsetY) + $this->pushLabel[1],
|
||||
($x2 + $this->offsetX) + $this->pushLabel[0],
|
||||
($y2 + $this->offsetY) + $this->pushLabel[1],
|
||||
$this->getColor($im, $color));
|
||||
} else {
|
||||
imagefilledrectangle($im, ($x1 + $this->offsetX) * $this->scale + $this->pushLabel[0], ($y1 + $this->offsetY) * $this->scale + $this->pushLabel[1], ($x2 + $this->offsetX) * $this->scale + $this->pushLabel[0] + $this->scale - 1, ($y1 + $this->offsetY) * $this->scale + $this->pushLabel[1] + $this->scale - 1, $this->getColor($im, $color));
|
||||
imagefilledrectangle($im, ($x1 + $this->offsetX) * $this->scale + $this->pushLabel[0], ($y1 + $this->offsetY) * $this->scale + $this->pushLabel[1], ($x1 + $this->offsetX) * $this->scale + $this->pushLabel[0] + $this->scale - 1, ($y2 + $this->offsetY) * $this->scale + $this->pushLabel[1] + $this->scale - 1, $this->getColor($im, $color));
|
||||
imagefilledrectangle($im, ($x2 + $this->offsetX) * $this->scale + $this->pushLabel[0], ($y1 + $this->offsetY) * $this->scale + $this->pushLabel[1], ($x2 + $this->offsetX) * $this->scale + $this->pushLabel[0] + $this->scale - 1, ($y2 + $this->offsetY) * $this->scale + $this->pushLabel[1] + $this->scale - 1, $this->getColor($im, $color));
|
||||
imagefilledrectangle($im, ($x1 + $this->offsetX) * $this->scale + $this->pushLabel[0], ($y2 + $this->offsetY) * $this->scale + $this->pushLabel[1], ($x2 + $this->offsetX) * $this->scale + $this->pushLabel[0] + $this->scale - 1, ($y2 + $this->offsetY) * $this->scale + $this->pushLabel[1] + $this->scale - 1, $this->getColor($im, $color));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Draws a filled rectangle on the resource at a specific position with a determined color.
|
||||
*
|
||||
* @param resource $im
|
||||
* @param int $x1
|
||||
* @param int $y1
|
||||
* @param int $x2
|
||||
* @param int $y2
|
||||
* @param int $color
|
||||
*/
|
||||
protected function drawFilledRectangle($im, $x1, $y1, $x2, $y2, $color = self::COLOR_FG) {
|
||||
if ($x1 > $x2) { // Swap
|
||||
$x1 ^= $x2 ^= $x1 ^= $x2;
|
||||
}
|
||||
|
||||
if ($y1 > $y2) { // Swap
|
||||
$y1 ^= $y2 ^= $y1 ^= $y2;
|
||||
}
|
||||
|
||||
imagefilledrectangle($im,
|
||||
($x1 + $this->offsetX) * $this->scale + $this->pushLabel[0],
|
||||
($y1 + $this->offsetY) * $this->scale + $this->pushLabel[1],
|
||||
($x2 + $this->offsetX) * $this->scale + $this->pushLabel[0] + $this->scale - 1,
|
||||
($y2 + $this->offsetY) * $this->scale + $this->pushLabel[1] + $this->scale - 1,
|
||||
$this->getColor($im, $color));
|
||||
}
|
||||
|
||||
/**
|
||||
* Allocates the color based on the integer.
|
||||
*
|
||||
* @param resource $im
|
||||
* @param int $color
|
||||
* @return resource
|
||||
*/
|
||||
protected function getColor($im, $color) {
|
||||
if ($color === self::COLOR_BG) {
|
||||
return $this->colorBg->allocate($im);
|
||||
} else {
|
||||
return $this->colorFg->allocate($im);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returning the biggest label widths for LEFT/RIGHT and heights for TOP/BOTTOM.
|
||||
*
|
||||
* @param bool $reversed
|
||||
* @return CINLabel[]
|
||||
*/
|
||||
private function getBiggestLabels($reversed = false) {
|
||||
$searchLR = $reversed ? 1 : 0;
|
||||
$searchTB = $reversed ? 0 : 1;
|
||||
|
||||
$labels = array();
|
||||
foreach ($this->labels as $label) {
|
||||
$position = $label->getPosition();
|
||||
if (isset($labels[$position])) {
|
||||
$savedDimension = $labels[$position]->getDimension();
|
||||
$dimension = $label->getDimension();
|
||||
if ($position === CINLabel::POSITION_LEFT || $position === CINLabel::POSITION_RIGHT) {
|
||||
if ($dimension[$searchLR] > $savedDimension[$searchLR]) {
|
||||
$labels[$position] = $label;
|
||||
}
|
||||
} else {
|
||||
if ($dimension[$searchTB] > $savedDimension[$searchTB]) {
|
||||
$labels[$position] = $label;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
$labels[$position] = $label;
|
||||
}
|
||||
}
|
||||
|
||||
return $labels;
|
||||
}
|
||||
}
|
||||
?>
|
|
@ -1,262 +0,0 @@
|
|||
<?php
|
||||
/**
|
||||
*--------------------------------------------------------------------
|
||||
*
|
||||
* Holds all type of barcodes for 1D generation
|
||||
*
|
||||
*--------------------------------------------------------------------
|
||||
* @author Akhtar Khan <er.akhtarkhan@gmail.com>
|
||||
* @link http://www.codeitnow.in
|
||||
* @package https://github.com/codeitnowin/barcode-generator
|
||||
*/
|
||||
namespace CodeItNow\BarcodeBundle\Generator;
|
||||
use CodeItNow\BarcodeBundle\Generator\CINArgumentException;
|
||||
use CodeItNow\BarcodeBundle\Generator\CINBarcode1D;
|
||||
use CodeItNow\BarcodeBundle\Generator\CINFontPhp;
|
||||
use CodeItNow\BarcodeBundle\Generator\CINFontFile;
|
||||
use CodeItNow\BarcodeBundle\Generator\CINLabel;
|
||||
|
||||
|
||||
abstract class CINBarcode1D extends CINBarcode {
|
||||
const SIZE_SPACING_FONT = 5;
|
||||
|
||||
const AUTO_LABEL = '##!!AUTO_LABEL!!##';
|
||||
|
||||
protected $thickness; // int
|
||||
protected $keys, $code; // string[]
|
||||
protected $positionX; // int
|
||||
protected $font; // CINFont
|
||||
protected $text; // string
|
||||
protected $checksumValue; // int or int[]
|
||||
protected $displayChecksum; // bool
|
||||
protected $label; // string
|
||||
protected $defaultLabel; // CINLabel
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*/
|
||||
protected function __construct() {
|
||||
parent::__construct();
|
||||
|
||||
$this->setThickness(30);
|
||||
|
||||
$this->defaultLabel = new CINLabel();
|
||||
$this->defaultLabel->setPosition(CINLabel::POSITION_BOTTOM);
|
||||
$this->setLabel(self::AUTO_LABEL);
|
||||
$this->setFont(new CINFontPhp(5));
|
||||
|
||||
$this->text = '';
|
||||
$this->checksumValue = false;
|
||||
$this->positionX = 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the thickness.
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function getThickness() {
|
||||
return $this->thickness;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the thickness.
|
||||
*
|
||||
* @param int $thickness
|
||||
*/
|
||||
public function setThickness($thickness) {
|
||||
$thickness = intval($thickness);
|
||||
if ($thickness <= 0) {
|
||||
throw new CINArgumentException('The thickness must be larger than 0.', 'thickness');
|
||||
}
|
||||
|
||||
$this->thickness = $thickness;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the label.
|
||||
* If the label was set to CINBarcode1D::AUTO_LABEL, the label will display the value from the text parsed.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getLabel() {
|
||||
$label = $this->label;
|
||||
if ($this->label === self::AUTO_LABEL) {
|
||||
$label = $this->text;
|
||||
if ($this->displayChecksum === true && ($checksum = $this->processChecksum()) !== false) {
|
||||
$label .= $checksum;
|
||||
}
|
||||
}
|
||||
|
||||
return $label;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the label.
|
||||
* You can use CINBarcode::AUTO_LABEL to have the label automatically written based on the parsed text.
|
||||
*
|
||||
* @param string $label
|
||||
*/
|
||||
public function setLabel($label) {
|
||||
$this->label = $label;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the font.
|
||||
*
|
||||
* @return CINFont
|
||||
*/
|
||||
public function getFont() {
|
||||
return $this->font;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the font.
|
||||
*
|
||||
* @param mixed $font CINFont or int
|
||||
*/
|
||||
public function setFont($font) {
|
||||
if (is_int($font)) {
|
||||
if ($font === 0) {
|
||||
$font = null;
|
||||
} else {
|
||||
$font = new CINFontPhp($font);
|
||||
}
|
||||
}
|
||||
|
||||
$this->font = $font;
|
||||
}
|
||||
|
||||
/**
|
||||
* Parses the text before displaying it.
|
||||
*
|
||||
* @param mixed $text
|
||||
*/
|
||||
public function parse($text) {
|
||||
$this->text = $text;
|
||||
$this->checksumValue = false; // Reset checksumValue
|
||||
$this->validate();
|
||||
|
||||
parent::parse($text);
|
||||
|
||||
$this->addDefaultLabel();
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the checksum of a Barcode.
|
||||
* If no checksum is available, return FALSE.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getChecksum() {
|
||||
return $this->processChecksum();
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets if the checksum is displayed with the label or not.
|
||||
* The checksum must be activated in some case to make this variable effective.
|
||||
*
|
||||
* @param boolean $displayChecksum
|
||||
*/
|
||||
public function setDisplayChecksum($displayChecksum) {
|
||||
$this->displayChecksum = (bool)$displayChecksum;
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds the default label.
|
||||
*/
|
||||
protected function addDefaultLabel() {
|
||||
$label = $this->getLabel();
|
||||
$font = $this->font;
|
||||
if ($label !== null && $label !== '' && $font !== null && $this->defaultLabel !== null) {
|
||||
$this->defaultLabel->setText($label);
|
||||
$this->defaultLabel->setFont($font);
|
||||
$this->addLabel($this->defaultLabel);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Validates the input
|
||||
*/
|
||||
protected function validate() {
|
||||
// No validation in the abstract class.
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the index in $keys (useful for checksum).
|
||||
*
|
||||
* @param mixed $var
|
||||
* @return mixed
|
||||
*/
|
||||
protected function findIndex($var) {
|
||||
return array_search($var, $this->keys);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the code of the char (useful for drawing bars).
|
||||
*
|
||||
* @param mixed $var
|
||||
* @return string
|
||||
*/
|
||||
protected function findCode($var) {
|
||||
return $this->code[$this->findIndex($var)];
|
||||
}
|
||||
|
||||
/**
|
||||
* Draws all chars thanks to $code. If $startBar is true, the line begins by a space.
|
||||
* If $startBar is false, the line begins by a bar.
|
||||
*
|
||||
* @param resource $im
|
||||
* @param string $code
|
||||
* @param boolean $startBar
|
||||
*/
|
||||
protected function drawChar($im, $code, $startBar = true) {
|
||||
$colors = array(CINBarcode::COLOR_FG, CINBarcode::COLOR_BG);
|
||||
$currentColor = $startBar ? 0 : 1;
|
||||
$c = strlen($code);
|
||||
for ($i = 0; $i < $c; $i++) {
|
||||
for ($j = 0; $j < intval($code[$i]) + 1; $j++) {
|
||||
$this->drawSingleBar($im, $colors[$currentColor]);
|
||||
$this->nextX();
|
||||
}
|
||||
|
||||
$currentColor = ($currentColor + 1) % 2;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Draws a Bar of $color depending of the resolution.
|
||||
*
|
||||
* @param resource $img
|
||||
* @param int $color
|
||||
*/
|
||||
protected function drawSingleBar($im, $color) {
|
||||
$this->drawFilledRectangle($im, $this->positionX, 0, $this->positionX, $this->thickness - 1, $color);
|
||||
}
|
||||
|
||||
/**
|
||||
* Moving the pointer right to write a bar.
|
||||
*/
|
||||
protected function nextX() {
|
||||
$this->positionX++;
|
||||
}
|
||||
|
||||
/**
|
||||
* Method that saves FALSE into the checksumValue. This means no checksum
|
||||
* but this method should be overriden when needed.
|
||||
*/
|
||||
protected function calculateChecksum() {
|
||||
$this->checksumValue = false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns FALSE because there is no checksum. This method should be
|
||||
* overriden to return correctly the checksum in string with checksumValue.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
protected function processChecksum() {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
?>
|
|
@ -1,157 +0,0 @@
|
|||
<?php
|
||||
/**
|
||||
*--------------------------------------------------------------------
|
||||
*
|
||||
* Holds Color in RGB Format.
|
||||
*
|
||||
*--------------------------------------------------------------------
|
||||
* @author Akhtar Khan <er.akhtarkhan@gmail.com>
|
||||
* @link http://www.codeitnow.in
|
||||
* @package https://github.com/codeitnowin/barcode-generator
|
||||
*/
|
||||
namespace CodeItNow\BarcodeBundle\Generator;
|
||||
|
||||
class CINColor {
|
||||
protected $r, $g, $b; // int Hexadecimal Value
|
||||
protected $transparent;
|
||||
|
||||
/**
|
||||
* Save RGB value into the classes.
|
||||
*
|
||||
* There are 4 way to associate color with this classes :
|
||||
* 1. Gives 3 parameters int (R, G, B)
|
||||
* 2. Gives 1 parameter string hex value (#ff0000) (preceding with #)
|
||||
* 3. Gives 1 parameter int hex value (0xff0000)
|
||||
* 4. Gives 1 parameter string color code (white, black, orange...)
|
||||
*
|
||||
* @param mixed ...
|
||||
*/
|
||||
public function __construct() {
|
||||
$args = func_get_args();
|
||||
$c = count($args);
|
||||
if ($c === 3) {
|
||||
$this->r = intval($args[0]);
|
||||
$this->g = intval($args[1]);
|
||||
$this->b = intval($args[2]);
|
||||
} elseif ($c === 1) {
|
||||
if (is_string($args[0]) && strlen($args[0]) === 7 && $args[0][0] === '#') { // Hex Value in String
|
||||
$this->r = intval(substr($args[0], 1, 2), 16);
|
||||
$this->g = intval(substr($args[0], 3, 2), 16);
|
||||
$this->b = intval(substr($args[0], 5, 2), 16);
|
||||
} else {
|
||||
if (is_string($args[0])) {
|
||||
$args[0] = self::getColor($args[0]);
|
||||
}
|
||||
|
||||
$args[0] = intval($args[0]);
|
||||
$this->r = ($args[0] & 0xff0000) >> 16;
|
||||
$this->g = ($args[0] & 0x00ff00) >> 8;
|
||||
$this->b = ($args[0] & 0x0000ff);
|
||||
}
|
||||
} else {
|
||||
$this->r = $this->g = $this->b = 0;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the color transparent.
|
||||
*
|
||||
* @param bool $transparent
|
||||
*/
|
||||
public function setTransparent($transparent) {
|
||||
$this->transparent = $transparent;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns Red Color.
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function r() {
|
||||
return $this->r;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns Green Color.
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function g() {
|
||||
return $this->g;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns Blue Color.
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function b() {
|
||||
return $this->b;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the int value for PHP color.
|
||||
*
|
||||
* @param resource $im
|
||||
* @return int
|
||||
*/
|
||||
public function allocate(&$im) {
|
||||
$allocated = imagecolorallocate($im, $this->r, $this->g, $this->b);
|
||||
if ($this->transparent) {
|
||||
return imagecolortransparent($im, $allocated);
|
||||
} else {
|
||||
return $allocated;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns class of CINColor depending of the string color.
|
||||
*
|
||||
* If the color doens't exist, it takes the default one.
|
||||
*
|
||||
* @param string $code
|
||||
* @param string $default
|
||||
*/
|
||||
public static function getColor($code, $default = 'white') {
|
||||
switch(strtolower($code)) {
|
||||
case '':
|
||||
case 'white':
|
||||
return 0xffffff;
|
||||
case 'black':
|
||||
return 0x000000;
|
||||
case 'maroon':
|
||||
return 0x800000;
|
||||
case 'red':
|
||||
return 0xff0000;
|
||||
case 'orange':
|
||||
return 0xffa500;
|
||||
case 'yellow':
|
||||
return 0xffff00;
|
||||
case 'olive':
|
||||
return 0x808000;
|
||||
case 'purple':
|
||||
return 0x800080;
|
||||
case 'fuchsia':
|
||||
return 0xff00ff;
|
||||
case 'lime':
|
||||
return 0x00ff00;
|
||||
case 'green':
|
||||
return 0x008000;
|
||||
case 'navy':
|
||||
return 0x000080;
|
||||
case 'blue':
|
||||
return 0x0000ff;
|
||||
case 'aqua':
|
||||
return 0x00ffff;
|
||||
case 'teal':
|
||||
return 0x008080;
|
||||
case 'silver':
|
||||
return 0xc0c0c0;
|
||||
case 'gray':
|
||||
return 0x808080;
|
||||
default:
|
||||
return self::getColor($default, 'white');
|
||||
}
|
||||
}
|
||||
}
|
||||
?>
|
|
@ -1,25 +0,0 @@
|
|||
<?php
|
||||
/**
|
||||
*--------------------------------------------------------------------
|
||||
*
|
||||
* Draw Exception
|
||||
*
|
||||
*--------------------------------------------------------------------
|
||||
* @author Akhtar Khan <er.akhtarkhan@gmail.com>
|
||||
* @link http://www.codeitnow.in
|
||||
* @package https://github.com/codeitnowin/barcode-generator
|
||||
*/
|
||||
namespace CodeItNow\BarcodeBundle\Generator;
|
||||
use Exception;
|
||||
|
||||
class CINDrawException extends Exception {
|
||||
/**
|
||||
* Constructor with specific message.
|
||||
*
|
||||
* @param string $message
|
||||
*/
|
||||
public function __construct($message) {
|
||||
parent::__construct($message, 30000);
|
||||
}
|
||||
}
|
||||
?>
|
|
@ -1,250 +0,0 @@
|
|||
<?php
|
||||
/**
|
||||
*--------------------------------------------------------------------
|
||||
*
|
||||
* Holds the drawing $im
|
||||
* You can use get_im() to add other kind of form not held into these classes.
|
||||
*
|
||||
*--------------------------------------------------------------------
|
||||
* @author Akhtar Khan <er.akhtarkhan@gmail.com>
|
||||
* @link http://www.codeitnow.in
|
||||
* @package https://github.com/codeitnowin/barcode-generator
|
||||
*/
|
||||
namespace CodeItNow\BarcodeBundle\Generator;
|
||||
use CodeItNow\BarcodeBundle\Generator\CINBarcode;
|
||||
use CodeItNow\BarcodeBundle\Generator\CINColor;
|
||||
use CodeItNow\BarcodeBundle\Generator\CINDrawException;
|
||||
use CodeItNow\BarcodeBundle\Generator\Drawer\CINDrawJPG;
|
||||
use CodeItNow\BarcodeBundle\Generator\Drawer\CINDrawPNG;
|
||||
|
||||
class CINDrawing {
|
||||
const IMG_FORMAT_PNG = 1;
|
||||
const IMG_FORMAT_JPEG = 2;
|
||||
const IMG_FORMAT_GIF = 3;
|
||||
const IMG_FORMAT_WBMP = 4;
|
||||
|
||||
private $w, $h; // int
|
||||
private $color; // CINColor
|
||||
private $filename; // char *
|
||||
private $im; // {object}
|
||||
private $barcode; // CINBarcode
|
||||
private $dpi; // float
|
||||
private $rotateDegree; // float
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @param int $w
|
||||
* @param int $h
|
||||
* @param string filename
|
||||
* @param CINColor $color
|
||||
*/
|
||||
public function __construct($filename, CINColor $color) {
|
||||
$this->im = null;
|
||||
$this->setFilename($filename);
|
||||
$this->color = $color;
|
||||
$this->dpi = null;
|
||||
$this->rotateDegree = 0.0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Destructor.
|
||||
*/
|
||||
public function __destruct() {
|
||||
$this->destroy();
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the filename.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getFilename() {
|
||||
return $this->filename;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the filename.
|
||||
*
|
||||
* @param string $filaneme
|
||||
*/
|
||||
public function setFilename($filename) {
|
||||
$this->filename = $filename;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return resource.
|
||||
*/
|
||||
public function get_im() {
|
||||
return $this->im;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the image.
|
||||
*
|
||||
* @param resource $im
|
||||
*/
|
||||
public function set_im($im) {
|
||||
$this->im = $im;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets barcode for drawing.
|
||||
*
|
||||
* @return CINBarcode
|
||||
*/
|
||||
public function getBarcode() {
|
||||
return $this->barcode;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets barcode for drawing.
|
||||
*
|
||||
* @param CINBarcode $barcode
|
||||
*/
|
||||
public function setBarcode(CINBarcode $barcode) {
|
||||
$this->barcode = $barcode;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the DPI for supported filetype.
|
||||
*
|
||||
* @return float
|
||||
*/
|
||||
public function getDPI() {
|
||||
return $this->dpi;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the DPI for supported filetype.
|
||||
*
|
||||
* @param float $dpi
|
||||
*/
|
||||
public function setDPI($dpi) {
|
||||
$this->dpi = $dpi;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the rotation angle in degree clockwise.
|
||||
*
|
||||
* @return float
|
||||
*/
|
||||
public function getRotationAngle() {
|
||||
return $this->rotateDegree;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the rotation angle in degree clockwise.
|
||||
*
|
||||
* @param float $degree
|
||||
*/
|
||||
public function setRotationAngle($degree) {
|
||||
$this->rotateDegree = (float)$degree;
|
||||
}
|
||||
|
||||
/**
|
||||
* Draws the barcode on the image $im.
|
||||
*/
|
||||
public function draw() {
|
||||
$size = $this->barcode->getDimension(0, 0);
|
||||
$this->w = max(1, $size[0]);
|
||||
$this->h = max(1, $size[1]);
|
||||
$this->init();
|
||||
$this->barcode->draw($this->im);
|
||||
}
|
||||
|
||||
/**
|
||||
* Saves $im into the file (many format available).
|
||||
*
|
||||
* @param int $image_style
|
||||
* @param int $quality
|
||||
*/
|
||||
public function finish($image_style = self::IMG_FORMAT_PNG, $quality = 100) {
|
||||
$drawer = null;
|
||||
|
||||
$im = $this->im;
|
||||
if ($this->rotateDegree > 0.0) {
|
||||
if (function_exists('imagerotate')) {
|
||||
$im = imagerotate($this->im, 360 - $this->rotateDegree, $this->color->allocate($this->im));
|
||||
} else {
|
||||
throw new CINDrawException('The method imagerotate doesn\'t exist on your server. Do not use any rotation.');
|
||||
}
|
||||
}
|
||||
|
||||
if ($image_style === self::IMG_FORMAT_PNG) {
|
||||
$drawer = new CINDrawPNG($im);
|
||||
$drawer->setFilename($this->filename);
|
||||
$drawer->setDPI($this->dpi);
|
||||
} elseif ($image_style === self::IMG_FORMAT_JPEG) {
|
||||
$drawer = new CINDrawJPG($im);
|
||||
$drawer->setFilename($this->filename);
|
||||
$drawer->setDPI($this->dpi);
|
||||
$drawer->setQuality($quality);
|
||||
} elseif ($image_style === self::IMG_FORMAT_GIF) {
|
||||
// Some PHP versions have a bug if passing 2nd argument as null.
|
||||
if ($this->filename === null || $this->filename === '') {
|
||||
imagegif($im);
|
||||
} else {
|
||||
imagegif($im, $this->filename);
|
||||
}
|
||||
} elseif ($image_style === self::IMG_FORMAT_WBMP) {
|
||||
imagewbmp($im, $this->filename);
|
||||
}
|
||||
|
||||
if ($drawer !== null) {
|
||||
$drawer->draw();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Writes the Error on the picture.
|
||||
*
|
||||
* @param Exception $exception
|
||||
*/
|
||||
public function drawException($exception) {
|
||||
$this->w = 1;
|
||||
$this->h = 1;
|
||||
$this->init();
|
||||
|
||||
// Is the image big enough?
|
||||
$w = imagesx($this->im);
|
||||
$h = imagesy($this->im);
|
||||