diff --git a/src/BarcodeGeneratorDynamicHTML.php b/src/BarcodeGeneratorDynamicHTML.php
index c08a4ed..5cebc2b 100644
--- a/src/BarcodeGeneratorDynamicHTML.php
+++ b/src/BarcodeGeneratorDynamicHTML.php
@@ -3,6 +3,7 @@
namespace Picqer\Barcode;
use Picqer\Barcode\Exceptions\UnknownTypeException;
+use Picqer\Barcode\Helpers\ColorHelper;
class BarcodeGeneratorDynamicHTML extends BarcodeGenerator
{
@@ -21,7 +22,7 @@ public function getBarcode(string $barcode, $type, string $foregroundColor = 'bl
$barcodeData = $this->getBarcodeData($barcode, $type);
$renderer = new \Picqer\Barcode\Renderers\DynamicHtmlRenderer();
- $renderer->setForegroundColor($foregroundColor);
+ $renderer->setForegroundColor(ColorHelper::getArrayFromColorString($foregroundColor));
return $renderer->render($barcodeData);
}
diff --git a/src/BarcodeGeneratorHTML.php b/src/BarcodeGeneratorHTML.php
index bc30f25..01b8b95 100644
--- a/src/BarcodeGeneratorHTML.php
+++ b/src/BarcodeGeneratorHTML.php
@@ -3,6 +3,7 @@
namespace Picqer\Barcode;
use Picqer\Barcode\Exceptions\UnknownTypeException;
+use Picqer\Barcode\Helpers\ColorHelper;
class BarcodeGeneratorHTML extends BarcodeGenerator
{
@@ -25,7 +26,7 @@ public function getBarcode(string $barcode, $type, int $widthFactor = 2, int $he
$width = round(($barcodeData->getWidth() * $widthFactor), 3);
$renderer = new \Picqer\Barcode\Renderers\HtmlRenderer();
- $renderer->setForegroundColor($foregroundColor);
+ $renderer->setForegroundColor(ColorHelper::getArrayFromColorString($foregroundColor));
return $renderer->render($barcodeData, $width, $height);
}
diff --git a/src/BarcodeGeneratorJPG.php b/src/BarcodeGeneratorJPG.php
index 2e27001..51eaf48 100644
--- a/src/BarcodeGeneratorJPG.php
+++ b/src/BarcodeGeneratorJPG.php
@@ -34,7 +34,7 @@ public function getBarcode(string $barcode, $type, int $widthFactor = 2, int $he
}
}
- return $renderer->render($barcodeData, $widthFactor, $height);
+ return $renderer->render($barcodeData, $barcodeData->getWidth() * $widthFactor, $height);
}
/**
diff --git a/src/BarcodeGeneratorPNG.php b/src/BarcodeGeneratorPNG.php
index 31edc56..f8f3d0c 100644
--- a/src/BarcodeGeneratorPNG.php
+++ b/src/BarcodeGeneratorPNG.php
@@ -34,7 +34,7 @@ public function getBarcode(string $barcode, $type, int $widthFactor = 2, int $he
}
}
- return $renderer->render($barcodeData, $widthFactor, $height);
+ return $renderer->render($barcodeData, $barcodeData->getWidth() * $widthFactor, $height);
}
/**
diff --git a/src/BarcodeGeneratorSVG.php b/src/BarcodeGeneratorSVG.php
index ef7d63f..64b725e 100644
--- a/src/BarcodeGeneratorSVG.php
+++ b/src/BarcodeGeneratorSVG.php
@@ -3,6 +3,7 @@
namespace Picqer\Barcode;
use Picqer\Barcode\Exceptions\UnknownTypeException;
+use Picqer\Barcode\Helpers\ColorHelper;
class BarcodeGeneratorSVG extends BarcodeGenerator
{
@@ -25,7 +26,7 @@ public function getBarcode(string $barcode, $type, float $widthFactor = 2, float
$width = round(($barcodeData->getWidth() * $widthFactor), 3);
$renderer = new \Picqer\Barcode\Renderers\SvgRenderer();
- $renderer->setForegroundColor($foregroundColor);
+ $renderer->setForegroundColor(ColorHelper::getArrayFromColorString($foregroundColor));
return $renderer->render($barcodeData, $width, $height);
}
diff --git a/src/Exceptions/UnknownColorException.php b/src/Exceptions/UnknownColorException.php
new file mode 100644
index 0000000..0401857
--- /dev/null
+++ b/src/Exceptions/UnknownColorException.php
@@ -0,0 +1,5 @@
+getBarcode('081231723897');
$renderer = new Picqer\Barcode\Renderers\HtmlRenderer();
- $renderer->setBackgroundColor('red');
+ $renderer->setBackgroundColor([255, 0, 0]);
$generated = $renderer->render($barcode, $barcode->getWidth() * 2);
$this->assertStringEqualsFile('tests/verified-files/081231723897-code128-red-background.html', $generated);
diff --git a/tests/JpgRendererTest.php b/tests/JpgRendererTest.php
index 46aa939..c6ca4c6 100644
--- a/tests/JpgRendererTest.php
+++ b/tests/JpgRendererTest.php
@@ -10,7 +10,7 @@ public function test_jpg_barcode_generator_can_generate_code_128_barcode()
$renderer = new Picqer\Barcode\Renderers\JpgRenderer();
$renderer->useGd();
- $generated = $renderer->render($barcode);
+ $generated = $renderer->render($barcode, $barcode->getWidth() * 2);
$imageInfo = getimagesizefromstring($generated);
@@ -27,7 +27,7 @@ public function test_jpg_barcode_generator_can_generate_code_39_barcode()
$renderer = new Picqer\Barcode\Renderers\JpgRenderer();
$renderer->useGd();
- $generated = $renderer->render($barcode, 1);
+ $generated = $renderer->render($barcode, $barcode->getWidth());
$imageInfo = getimagesizefromstring($generated);
@@ -43,7 +43,7 @@ public function test_jpg_barcode_generator_can_use_different_height()
$renderer = new Picqer\Barcode\Renderers\JpgRenderer();
$renderer->useGd();
- $generated = $renderer->render($barcode, 2, 45);
+ $generated = $renderer->render($barcode, $barcode->getWidth() * 2, 45);
$imageInfo = getimagesizefromstring($generated);
@@ -59,7 +59,7 @@ public function test_jpg_barcode_generator_can_use_different_width_factor()
$renderer = new Picqer\Barcode\Renderers\JpgRenderer();
$renderer->useGd();
- $generated = $renderer->render($barcode, 5);
+ $generated = $renderer->render($barcode, $barcode->getWidth() * 5);
$imageInfo = getimagesizefromstring($generated);
@@ -81,7 +81,7 @@ public function test_jpg_barcode_generator_can_generate_code_128_barcode_imagick
$renderer = new Picqer\Barcode\Renderers\JpgRenderer();
$renderer->useImagick();
- $generated = $renderer->render($barcode);
+ $generated = $renderer->render($barcode, $barcode->getWidth() * 2);
$imageInfo = getimagesizefromstring($generated);
@@ -101,7 +101,7 @@ public function test_jpg_barcode_generator_can_generate_code_39_barcode_imagick(
$renderer = new Picqer\Barcode\Renderers\JpgRenderer();
$renderer->useImagick();
- $generated = $renderer->render($barcode, 1);
+ $generated = $renderer->render($barcode, $barcode->getWidth());
$imageInfo = getimagesizefromstring($generated);
@@ -121,7 +121,7 @@ public function test_jpg_barcode_generator_can_use_different_height_imagick()
$renderer = new Picqer\Barcode\Renderers\JpgRenderer();
$renderer->useGd();
- $generated = $renderer->render($barcode, 2, 45);
+ $generated = $renderer->render($barcode, $barcode->getWidth() * 2, 45);
$imageInfo = getimagesizefromstring($generated);
@@ -141,7 +141,7 @@ public function test_jpg_barcode_generator_can_use_different_width_factor_imagic
$renderer = new Picqer\Barcode\Renderers\JpgRenderer();
$renderer->useGd();
- $generated = $renderer->render($barcode, 5);
+ $generated = $renderer->render($barcode, $barcode->getWidth() * 5);
$imageInfo = getimagesizefromstring($generated);
diff --git a/tests/PngRendererTest.php b/tests/PngRendererTest.php
index db253ce..fbb3e3c 100644
--- a/tests/PngRendererTest.php
+++ b/tests/PngRendererTest.php
@@ -22,7 +22,7 @@ public function test_png_barcode_generator_can_generate_code_39_barcode()
$renderer = new Picqer\Barcode\Renderers\PngRenderer();
$renderer->useGd();
- $generated = $renderer->render($barcode, 1);
+ $generated = $renderer->render($barcode, $barcode->getWidth());
$imageInfo = getimagesizefromstring($generated);
@@ -38,7 +38,7 @@ public function test_png_barcode_generator_can_use_different_height()
$renderer = new Picqer\Barcode\Renderers\PngRenderer();
$renderer->useGd();
- $generated = $renderer->render($barcode, 2, 45);
+ $generated = $renderer->render($barcode, $barcode->getWidth() * 2, 45);
$imageInfo = getimagesizefromstring($generated);
@@ -54,7 +54,7 @@ public function test_png_barcode_generator_can_use_different_width_factor()
$renderer = new Picqer\Barcode\Renderers\PngRenderer();
$renderer->useGd();
- $generated = $renderer->render($barcode, 5);
+ $generated = $renderer->render($barcode, $barcode->getWidth() * 5);
$imageInfo = getimagesizefromstring($generated);
@@ -76,7 +76,7 @@ public function test_png_barcode_generator_can_generate_code_128_barcode_imagick
$renderer = new Picqer\Barcode\Renderers\PngRenderer();
$renderer->useImagick();
- $generated = $renderer->render($barcode);
+ $generated = $renderer->render($barcode, $barcode->getWidth() * 2);
$this->assertEquals('PNG', substr($generated, 1, 3));
}
@@ -91,7 +91,7 @@ public function test_png_barcode_generator_can_generate_code_39_barcode_imagick(
$renderer = new Picqer\Barcode\Renderers\PngRenderer();
$renderer->useImagick();
- $generated = $renderer->render($barcode, 1);
+ $generated = $renderer->render($barcode, $barcode->getWidth());
$imageInfo = getimagesizefromstring($generated);
@@ -111,7 +111,7 @@ public function test_png_barcode_generator_can_use_different_height_imagick()
$renderer = new Picqer\Barcode\Renderers\PngRenderer();
$renderer->useGd();
- $generated = $renderer->render($barcode, 2, 45);
+ $generated = $renderer->render($barcode, $barcode->getWidth() * 2, 45);
$imageInfo = getimagesizefromstring($generated);
@@ -131,7 +131,7 @@ public function test_png_barcode_generator_can_use_different_width_factor_imagic
$renderer = new Picqer\Barcode\Renderers\PngRenderer();
$renderer->useGd();
- $generated = $renderer->render($barcode, 5);
+ $generated = $renderer->render($barcode, $barcode->getWidth() * 5);
$imageInfo = getimagesizefromstring($generated);
diff --git a/tests/SvgRendererTest.php b/tests/SvgRendererTest.php
index a8d73e6..984d034 100644
--- a/tests/SvgRendererTest.php
+++ b/tests/SvgRendererTest.php
@@ -62,7 +62,7 @@ public function test_svg_barcode_generator_can_use_background_color()
$barcode = (new Picqer\Barcode\Types\TypeEan13())->getBarcode('081231723897');
$renderer = new Picqer\Barcode\Renderers\SvgRenderer();
- $renderer->setBackgroundColor('red');
+ $renderer->setBackgroundColor([255, 0, 0]);
$generated = $renderer->render($barcode, 190);
$this->assertStringEqualsFile('tests/verified-files/081231723897-ean13-red-background.svg', $generated);