|
@@ -7,6 +7,9 @@
|
|
|
|
|
|
|
|
namespace OpenMind\System;
|
|
namespace OpenMind\System;
|
|
|
|
|
|
|
|
|
|
+use Picqer\Barcode\BarcodeGeneratorPNG;
|
|
|
|
|
+use Picqer\Barcode\Exceptions\BarcodeException;
|
|
|
|
|
+
|
|
|
/**
|
|
/**
|
|
|
* Class GDSupport
|
|
* Class GDSupport
|
|
|
* Facility for draw images using GD php library
|
|
* Facility for draw images using GD php library
|
|
@@ -24,20 +27,11 @@ class GDSupport
|
|
|
$this->image = null;
|
|
$this->image = null;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- /**
|
|
|
|
|
- * @param string $colorStr
|
|
|
|
|
- * @return false|int
|
|
|
|
|
- */
|
|
|
|
|
- private function getColor(string $colorStr)
|
|
|
|
|
- {
|
|
|
|
|
- list($r, $g, $b) = sscanf($colorStr, "#%02x%02x%02x");
|
|
|
|
|
- return imagecolorallocate($this->image, $r, $g, $b);
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
/**
|
|
/**
|
|
|
* @param array $drawings
|
|
* @param array $drawings
|
|
|
* @param string|null $outputPathFile
|
|
* @param string|null $outputPathFile
|
|
|
* @return string if outputPathFile is null, return the image instead to write to file
|
|
* @return string if outputPathFile is null, return the image instead to write to file
|
|
|
|
|
+ * @throws BarcodeException
|
|
|
*/
|
|
*/
|
|
|
public function Render(array $drawings, $outputPathFile = NULL): string
|
|
public function Render(array $drawings, $outputPathFile = NULL): string
|
|
|
{
|
|
{
|
|
@@ -46,27 +40,53 @@ class GDSupport
|
|
|
$prop = $gdElement[$name];
|
|
$prop = $gdElement[$name];
|
|
|
$color = isset($prop['color']) ? $this->getColor($prop['color']) : NULL;
|
|
$color = isset($prop['color']) ? $this->getColor($prop['color']) : NULL;
|
|
|
switch ($name) {
|
|
switch ($name) {
|
|
|
|
|
+
|
|
|
case 'BODY':
|
|
case 'BODY':
|
|
|
$this->image = imagecreatetruecolor($prop['w'], $prop['h']);
|
|
$this->image = imagecreatetruecolor($prop['w'], $prop['h']);
|
|
|
|
|
+ imageantialias($this->image, true);
|
|
|
|
|
+ $bgColor = isset($prop['bgcolor']) ? $this->getColor($prop['bgcolor']) : NULL;
|
|
|
|
|
+ imagefill($this->image, 0, 0, $bgColor);
|
|
|
break;
|
|
break;
|
|
|
|
|
+
|
|
|
case 'TEXT':
|
|
case 'TEXT':
|
|
|
- imagettftext($this->image, $prop['size'], 0, $prop['x'], $prop['y'], $color, 'C:\Windows\Fonts\arial.ttf', $prop['value']);
|
|
|
|
|
|
|
+ imagettftext($this->image, $prop['size'], 0, $prop['x'], $prop['y'], $color, $prop['font'], $prop['value']);
|
|
|
break;
|
|
break;
|
|
|
|
|
+
|
|
|
case 'FILL':
|
|
case 'FILL':
|
|
|
imagefill($this->image, $prop['x'], $prop['y'], $color);
|
|
imagefill($this->image, $prop['x'], $prop['y'], $color);
|
|
|
break;
|
|
break;
|
|
|
- case 'RECTFILL':
|
|
|
|
|
- imagefilledrectangle($this->image, $prop['x1'], $prop['y1'], $prop['x2'], $prop['y2'], $color);
|
|
|
|
|
|
|
+
|
|
|
|
|
+ case 'RECT':
|
|
|
|
|
+ if (isset($prop['filled']))
|
|
|
|
|
+ imagefilledrectangle($this->image, $prop['x1'], $prop['y1'], $prop['x2'], $prop['y2'], $color);
|
|
|
|
|
+ else
|
|
|
|
|
+ imagerectangle($this->image, $prop['x1'], $prop['y1'], $prop['x2'], $prop['y2'], $color);
|
|
|
break;
|
|
break;
|
|
|
|
|
+
|
|
|
case 'LINE':
|
|
case 'LINE':
|
|
|
|
|
+ if (isset($prop['thickness']))
|
|
|
|
|
+ imagesetthickness($this->image, $prop['thickness']);
|
|
|
|
|
+
|
|
|
imageline($this->image, $prop['x1'], $prop['y1'], $prop['x2'], $prop['y2'], $color);
|
|
imageline($this->image, $prop['x1'], $prop['y1'], $prop['x2'], $prop['y2'], $color);
|
|
|
|
|
+
|
|
|
|
|
+ if (isset($prop['thickness'])) // Restore default tickness
|
|
|
|
|
+ imagesetthickness($this->image, 1);
|
|
|
break;
|
|
break;
|
|
|
|
|
+
|
|
|
case 'PIXEL':
|
|
case 'PIXEL':
|
|
|
imagesetpixel($this->image, $prop['x'], $prop['y'], $color);
|
|
imagesetpixel($this->image, $prop['x'], $prop['y'], $color);
|
|
|
break;
|
|
break;
|
|
|
|
|
+
|
|
|
case 'ELLIPSE':
|
|
case 'ELLIPSE':
|
|
|
imagefilledellipse($this->image, $prop['x'], $prop['y'], $prop['w'], $prop['h'], $color);
|
|
imagefilledellipse($this->image, $prop['x'], $prop['y'], $prop['w'], $prop['h'], $color);
|
|
|
break;
|
|
break;
|
|
|
|
|
+
|
|
|
|
|
+ case 'BARCODE':
|
|
|
|
|
+ $bcGen = new BarcodeGeneratorPNG();
|
|
|
|
|
+ $bcImg = $bcGen->getBarcode($prop['value'], $prop['type'], $prop['widthFactor'], $prop['h']);
|
|
|
|
|
+ $gdBcImg = imagecreatefromstring($bcImg);
|
|
|
|
|
+ imagecopy($this->image, $gdBcImg, $prop['x'], $prop['y'], 0, 0, imagesx($gdBcImg), imagesy($gdBcImg));
|
|
|
|
|
+ break;
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -77,16 +97,26 @@ class GDSupport
|
|
|
return $data;
|
|
return $data;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- public function Destroy()
|
|
|
|
|
|
|
+ /**
|
|
|
|
|
+ * @param string $colorStr
|
|
|
|
|
+ * @return false|int
|
|
|
|
|
+ */
|
|
|
|
|
+ private function getColor(string $colorStr)
|
|
|
{
|
|
{
|
|
|
- if ($this->image) {
|
|
|
|
|
- imagedestroy($this->image);
|
|
|
|
|
- $this->image = NULL;
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ list($r, $g, $b) = sscanf($colorStr, "#%02x%02x%02x");
|
|
|
|
|
+ return imagecolorallocate($this->image, $r, $g, $b);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
public function __destruct()
|
|
public function __destruct()
|
|
|
{
|
|
{
|
|
|
$this->Destroy();
|
|
$this->Destroy();
|
|
|
}
|
|
}
|
|
|
|
|
+
|
|
|
|
|
+ public function Destroy()
|
|
|
|
|
+ {
|
|
|
|
|
+ if ($this->image) {
|
|
|
|
|
+ imagedestroy($this->image);
|
|
|
|
|
+ $this->image = NULL;
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|