From 6bccdc4b563af7385a59c2cd687aee00f316a229 Mon Sep 17 00:00:00 2001 From: Oskar Stark Date: Fri, 22 Sep 2017 09:50:35 +0200 Subject: [PATCH] throw exception instead of returning false if gd-lib or imagick are not installed --- src/BarcodeGeneratorJPG.php | 5 ++++- src/BarcodeGeneratorPNG.php | 4 +++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/src/BarcodeGeneratorJPG.php b/src/BarcodeGeneratorJPG.php index 694b1fa..b1cb72c 100644 --- a/src/BarcodeGeneratorJPG.php +++ b/src/BarcodeGeneratorJPG.php @@ -2,6 +2,8 @@ namespace Picqer\Barcode; +use Picqer\Barcode\Exceptions\BarcodeException; + class BarcodeGeneratorJPG extends BarcodeGenerator { @@ -15,6 +17,7 @@ class BarcodeGeneratorJPG extends BarcodeGenerator * @param array $color RGB (0-255) foreground color for bar elements (background is transparent). * @return string image data or false in case of error. * @public + * @throws BarcodeException */ public function getBarcode($code, $type, $widthFactor = 2, $totalHeight = 30, $color = array(0, 0, 0)) { @@ -39,7 +42,7 @@ public function getBarcode($code, $type, $widthFactor = 2, $totalHeight = 30, $c $imageMagickObject = new \imagickdraw(); $imageMagickObject->setFillColor($colorForeground); } else { - return false; + throw new BarcodeException('Neither gd-lib or imagick are installed!'); } // print bars diff --git a/src/BarcodeGeneratorPNG.php b/src/BarcodeGeneratorPNG.php index 4a67ee4..f788392 100644 --- a/src/BarcodeGeneratorPNG.php +++ b/src/BarcodeGeneratorPNG.php @@ -2,6 +2,8 @@ namespace Picqer\Barcode; +use Picqer\Barcode\Exceptions\BarcodeException; + class BarcodeGeneratorPNG extends BarcodeGenerator { @@ -39,7 +41,7 @@ public function getBarcode($code, $type, $widthFactor = 2, $totalHeight = 30, $c $imageMagickObject = new \imagickdraw(); $imageMagickObject->setFillColor($colorForeground); } else { - return false; + throw new BarcodeException('Neither gd-lib or imagick are installed!'); } // print bars