[TYPO3-mvc] looking for fluid viewhelper rendering barcode as image

Johannes C. Schulz - EnzephaloN IT-Solutions info at enzephalon.de
Fri Feb 3 14:49:11 CET 2012


Hello all!
I added the https://www.barcodephp.com/en/download in my extension, placed
it in Classes/Utility/Barcode and wrote a viewhelper for generating the
barcode image.
But the viewhelper does not work, in source of page only the fluid-tag is
shown.
Fluid-templte:
<img src="{psoa:barcode(barcode:'{person.aid}'}" width="150mm"
alt="{person.aid}" title="{person.aid}"/>
Barcode-viewhelper:
<?php
class Tx_PsoaAccredit_ViewHelpers_BarcodeViewHelper extends
Tx_Fluid_Core_ViewHelper_AbstractViewHelper {
	
	/**
	* converts integer to barcode
	*
	* @param int $barcode
	* @return blob
	*/
	public function render($barcode) {
		if ($barcode == 0 || empty($barcode)){
			return "";
		}
		else{
			// Including all required classes
	
require_once('../Utility/Barcode/class/BCGFontFile.php');
	
require_once('../Utility/Barcode/class/BCGColor.php');
	
require_once('../Utility/Barcode/class/BCGDrawing.php');
			
			// Including the barcode technology
	
require_once('../Utility/Barcode/class/BCGcode39.barcode.php');
			
			// Loading Font
			$font = new
BCGFontFile('../Utility/Barcode/class/font/Arial.ttf', 18);
			
			// The arguments are R, G, B for color.
			$color_black = new BCGColor(0, 0, 0);
			$color_white = new BCGColor(255, 255, 255);
			
			$drawException = null;
			try {
				$code = new BCGcode39();
				$code->setScale(3); // Resolution
				$code->setThickness(30); // Thickness
				$code->setForegroundColor($color_black); //
Color of bars
				$code->setBackgroundColor($color_white); //
Color of spaces
				$code->setFont($font); // Font (or 0)
				$code->parse($barcode); // Text
			} catch(Exception $exception) {
				$drawException = $exception;
			}
			
			/* Here is the list of the arguments
			1 - Filename (empty : display on screen)
			2 - Background color */
			$drawing = new BCGDrawing('', $color_white);
			if($drawException) {
				$drawing->drawException($drawException);
			} else {
				$drawing->setBarcode($code);
				$drawing->draw();
			}
			
			// Header that says it is an image (remove it if you
save the barcode to a file)
			header('Content-Type: image/png');
			
			// Draw (or save) the image into PNG format.

			return $drawing->finish(BCGDrawing::IMG_FORMAT_PNG);
		}
	}
	
}
?>

Does anyone knows what to do?

Kindly regards
Johannes



More information about the TYPO3-project-typo3v4mvc mailing list