作者:haoyanfe
项目:zf
public function testNoFontWithOrientation()
{
$this->setExpectedException('\\Zend\\Barcode\\Renderer\\Exception\\ExceptionInterface');
Barcode\Barcode::setBarcodeFont(null);
$barcode = new Object\Code39(array('text' => '0123456789'));
$barcode->setOrientation(1);
$this->renderer->setBarcode($barcode);
$this->renderer->draw();
}
作者:rcastard
项目:zf
public function tearDown()
{
Barcode\Barcode::setBarcodeFont(null);
if (!empty($this->originaltimezone)) {
date_default_timezone_set($this->originaltimezone);
}
}
作者:adaoe
项目:zf2-phpbo
/**
* @return Boolean Sucesso na criação da imagem
*/
public function create($value, $options = array(), $barcodeType = 'code25interleaved', $type = 'image')
{
$bol_ret = true;
$value = trim($value);
try {
/* Junta a configuração padrão com $options informado */
$barcodeOptions = array_merge(array('text' => $value, 'drawText' => false), $options);
/* Não há opções necessárias */
$rendererOptions = array();
// Desenha o código de barras em uma nova imagem,
// enviar os cabeçalhos e a imagem
$imageResource = Barcode::factory($barcodeType, $type, $barcodeOptions, $rendererOptions)->draw();
// Enable output buffering
ob_start();
imagepng($imageResource);
imagedestroy($imageResource);
// Capture the output
$imagedata = ob_get_contents();
// Clear the output buffer
ob_end_clean();
return base64_encode($imagedata);
} catch (Exception $e) {
$bol_ret = false;
echo 'Erro: na geraçãod e código de barra!';
echo 'Código: ' . $e->getCode();
echo 'Mensagem: ' . $e->getMessage();
echo 'Trace: ' . $e->getTraceAsString();
}
return $bol_ret;
}
作者:marcusv
项目:PHP-Boleto-ZF
public function prepare()
{
$nummoeda = "9";
$fixo = "9";
// Numero fixo para a posição 05-05
$ios = "0";
/**
* adicionando dados das instruções e demonstrativo no boleto
*/
(new ClassMethods())->hydrate($this->config['php-zf2-boleto']['instrucoes'], $this->getBoleto());
/**
* Compondo o Nosso Número e seu dígito verificador
*/
$nossoNumeroProcessado = \str_pad($this->getBoleto()->getNossoNumero(), 13, '0', STR_PAD_LEFT);
$nossoNumeroDV = Util::digitoVerificadorNossoNumero($nossoNumeroProcessado);
/**
* Calcula o fator do vencimento (número inteiro que representa a data de vencimento na linha digitavel)
*/
$fatorVencimento = Util::fatorVencimento($this->getBoleto()->getDataVencimento()->format("d/m/Y"));
/**
* Processando o valor para aplicação na linha digitável e no código de barras
*/
$valor = preg_replace("/[^0-9]/", "", $this->getBoleto()->getValor());
// removendo formatação do número
$valorProcessado = \str_pad($valor, 10, '0', STR_PAD_LEFT);
/**
* Calcula o dígito verificador do código de barras
*/
// $barra = "$codigobanco$nummoeda$fator_vencimento$valor$fixo$codigocliente$nossonumero$ios$carteira";
$DV = Util::digitoVerificadorBarra($this->getBanco()->getCodigoBanco() . $this->getBanco()->getMoeda() . $fatorVencimento . $valorProcessado . $fixo . $this->getCedente()->getCodigocliente() . $nossoNumeroProcessado . $ios . $this->getCedente()->getCarteira());
$barra = $this->getBanco()->getCodigoBanco() . $this->getBanco()->getMoeda() . $fatorVencimento . $valorProcessado . $fixo . $this->getCedente()->getCodigocliente() . $nossoNumeroProcessado . $ios . $this->getCedente()->getCarteira();
/**
* Compondo a linha base para formação da Linha Digitável e do Código de Barras
*/
$strLinha = substr($barra, 0, 4) . $DV . substr($barra, 4);
/**
* Formatando o Nosso Número para impressão
*/
$nossoNumeroFormatado = $nossoNumeroProcessado;
/**
* Formatando os dados bancários do cedente para impressão
*/
$this->getCedente()->setAgenciaCodigo($this->getCedente()->getAgencia() . '-' . $this->getCedente()->getAgenciaDv() . ' / ' . $this->getCedente()->getContaCedente() . '-' . $this->getCedente()->getContaCedenteDv());
/**
* Iniciando opções para criação do Código de Barras
*/
$barcodeOptions = array('text' => $strLinha);
/**
* Criando o código de barras em uma imagem e retornando seu base64
*/
$codigoDeBarras = Barcode::factory('Code25interleaved', 'PhpBoletoZf2\\Lib\\Barcode\\Renderer\\Base64', $barcodeOptions, array());
/**
* Termina de hidratar o objetodo boleto
*/
$this->getBoleto()->setCodigoDeBarras($codigoDeBarras)->setLinhaDigitavel(Util::montaLinhaDigitavel($strLinha))->setNossoNumeroFormatado($nossoNumeroFormatado);
return $this;
}
作者:stunt
项目:zf
public function testStaticFontAsNumber()
{
for ($i = 1; $i < 5; $i++) {
Barcode\Barcode::setBarcodeFont($i);
$this->assertEquals('', $this->_object->getFont());
$object = $this->_getBarcodeObject();
$this->assertEquals($i, $object->getFont());
Barcode\Barcode::setBarcodeFont('');
}
}
作者:rajanlami
项目:IntTes
public function testDrawWithExistantResourceReturnResource()
{
Barcode\Barcode::setBarcodeFont(__DIR__ . '/../Object/_fonts/Vera.ttf');
$barcode = new Object\Code39(array('text' => '0123456789'));
$this->renderer->setBarcode($barcode);
$pdfResource = new Pdf\PdfDocument();
$this->renderer->setResource($pdfResource);
$resource = $this->renderer->draw();
$this->assertTrue($resource instanceof Pdf\PdfDocument);
$this->assertSame($resource, $pdfResource);
Barcode\Barcode::setBarcodeFont('');
}
作者:xjtuwangk
项目:laravel-cod
public function barcode($code, $type = 'code128')
{
if (!in_array($type, ['code128', 'code25', 'code25interleaved', 'code39', 'ean13', 'ean2', 'ean5', 'ean8', 'identcode', 'itf14', 'leitcode', 'planet', 'postnet', 'royalmail', 'upca', 'upce'])) {
\App::abort(404);
}
//Barcode::setBarcodeFont( storage_path( 'pdf/fonts/yahei/normal.ttf' ) );
$barcodeOptions = array('text' => $code, 'factor' => 1);
$rendererOptions = array();
Barcode::render($type, 'image', $barcodeOptions, $rendererOptions);
$response = \Response::make('', 200);
$response->header('Content-Type', 'image/png', true);
return $response;
}
作者:pentagramac
项目:sped-gnr
/**
* Gera a imagem do código de barras e o transforma em base64
* @return string Retorna a imagem gerada no formato base64
*/
public function getCodigoBarrasBase64()
{
ob_start();
$text = $this->getNumeroCodigoBarras();
$options = array('text' => (string) $text, 'imageType' => 'jpeg', 'drawText' => false);
$barcode = new \Zend\Barcode\Object\Code128();
$barcode->setOptions($options);
$barcodeOBj = \Zend\Barcode\Barcode::factory($barcode);
$imageResource = $barcodeOBj->draw();
imagejpeg($imageResource);
$contents = ob_get_contents();
ob_end_clean();
return base64_encode($contents);
}
作者:shitikovkiril
项目:LearnZF
/**
* Use the form to get barcode image from selected barcode object.
*/
public function indexAction()
{
$request = $this->getRequest();
//default value without post parameter
$barcodeOptions = ['text' => '123456789'];
$barcode = Barcode::factory('codabar', 'image', $barcodeOptions);
if ($request->isPost()) {
$this->form->setData($request->getPost());
if ($this->form->isValid()) {
$barcodeOptions = ['text' => $this->form->getData()['barcode-object-text']];
$barcode = Barcode::factory($this->form->getData()['barcode-object-select'], 'image', $barcodeOptions);
}
}
imagegif($barcode->draw(), './data/barcode.gif');
return new ViewModel(['form' => $this->form]);
}
作者:jotjunio
项目:boletophp-zf
public function prepare()
{
// adicionando dados das instruções e demonstrativo no boleto
(new ClassMethods())->hydrate($this->config['php-zf2-boleto']['instrucoes'], $this->getBoleto());
// adicionando valores default de configuração do cedente
(new ClassMethods())->hydrate($this->config['php-zf2-boleto'][$this->banco->getCodigoBanco()]['dados_cedente'], $this->getCedente());
$nossoNumeroProcessado = (int) $this->getBoleto()->getNossoNumero();
$nossoNumeroProcessado = \str_pad($nossoNumeroProcessado, 7, '0', STR_PAD_LEFT);
// Calcula o fator do vencimento (número inteiro que representa a data de vencimento na linha digitavel)
$fatorVencimento = Util::fatorVencimento($this->getBoleto()->getDataVencimento()->format("d/m/Y"));
$fatorVencimento = \str_pad($fatorVencimento, 4, '0', STR_PAD_LEFT);
// Processando o valor para aplicação na linha digitável e no código de barras
$valor = preg_replace("/[^0-9]/", "", $this->getBoleto()->getValor());
// removendo formatação do número
$valorProcessado = \str_pad($valor, 10, '0', STR_PAD_LEFT);
$parcela = $this->getBoleto()->getQuantidade();
$parcela = \str_pad($parcela ? $parcela : 1, 3, '0', STR_PAD_LEFT);
$numeroCliente = (int) $this->getCedente()->getConvenio();
$numeroCliente = \str_pad($numeroCliente, 7, '0', STR_PAD_LEFT);
/**
* Calcula digito verificador nosso número boletos Bancoob
* 3197 regra sicoob
*/
$sequencia = $this->getCedente()->getAgencia() . \str_pad($numeroCliente, 10, '0', STR_PAD_LEFT) . $nossoNumeroProcessado;
$dvNossoNumero = Util::digitoVerificadorNossoNumeroBancoob($sequencia, '3197');
$nossoNumeroFormatado = "{$nossoNumeroProcessado}{$dvNossoNumero}";
// modalidade de cobranca
$variacao = $this->getCedente()->getVariacaoCarteira();
$variacao = \str_pad($variacao ? $variacao : 2, 2, '0', STR_PAD_LEFT);
$campoLivre = "{$variacao}{$numeroCliente}{$nossoNumeroFormatado}{$parcela}";
// Calcula o dígito verificador do código de barras
$DV = Util::digitoVerificadorBarra($this->getBanco()->getCodigoBanco() . $this->getBanco()->getMoeda() . $fatorVencimento . $valorProcessado . $this->getBanco()->getCarteira() . $this->getCedente()->getAgencia() . $campoLivre);
/**
* Compondo a linha base para formação da Linha Digitável e do Código de Barras
*/
$strLinha = $this->getBanco()->getCodigoBanco() . $this->getBanco()->getMoeda() . $DV . $fatorVencimento . $valorProcessado . $this->getBanco()->getCarteira() . $this->getCedente()->getAgencia() . $campoLivre;
// Formatando os dados bancários do cedente para impressão
$this->getCedente()->setAgenciaCodigo($this->getCedente()->getAgenciaDv() . ' / ' . $this->getCedente()->getCodigocliente());
// Iniciando opções para criação do Código de Barras
$barcodeOptions = array('text' => $strLinha);
// Criando o código de barras em uma imagem e retornando seu base64
$codigoDeBarras = Barcode::factory('Code25interleaved', 'PhpBoletoZf2\\Lib\\Barcode\\Renderer\\Base64', $barcodeOptions, array());
// Termina de hidratar o objetodo boleto
$this->getBoleto()->setCodigoDeBarras($codigoDeBarras)->setLinhaDigitavel(Util::montaLinhaDigitavel($strLinha))->setNossoNumeroFormatado($nossoNumeroFormatado);
return $this;
}
作者:LurkerAtTheGat
项目:BarcodeBundl
/**
* Creates and draws a barcode (wrapping the Zend Barcode component).
*
* @param mixed $barcode String name of barcode class, or Traversable object.
* @param mixed $barcodeConfig An array or Traversable object with barcode parameters.
* @param mixed $rendererConfig An array or Traversable object with renderer parameters.
* @param boolean $automaticRenderError Set the automatic rendering of exception
* @return resource
**/
public function create($barcode, $barcodeConfig = array(), $rendererConfig = array(), $automaticRenderError = true)
{
$renderer = new ImageRenderer($rendererConfig);
//make sure Zend object plugin manager does not share created barcode object
$objectPluginManager = Barcode::getObjectPluginManager();
$originallySharedByDefault = $objectPluginManager->shareByDefault();
if ($originallySharedByDefault) {
$objectPluginManager->setShareByDefault(false);
}
$barcodeObject = $objectPluginManager->get($barcode, $barcodeConfig);
if ($originallySharedByDefault) {
//reset object plugin manager
$objectPluginManager->setShareByDefault(true);
}
$renderer->setBarcode($barcodeObject);
return new GdImage($renderer->draw(), new RGB(), new MetadataBag());
}
作者:heiglandrea
项目:zf
public function testDrawWithExistantResourceReturnResource()
{
Barcode\Barcode::setBarcodeFont(__DIR__ . '/../Object/_fonts/Vera.ttf');
$barcode = new Code39(array('text' => '0123456789'));
$this->_renderer->setBarcode($barcode);
$svgResource = new \DOMDocument();
$rootElement = $svgResource->createElement('svg');
$rootElement->setAttribute('xmlns', "http://www.w3.org/2000/svg");
$rootElement->setAttribute('version', '1.1');
$rootElement->setAttribute('width', 500);
$rootElement->setAttribute('height', 300);
$svgResource->appendChild($rootElement);
$this->_renderer->setResource($svgResource);
$resource = $this->_renderer->draw();
$this->assertTrue($resource instanceof \DOMDocument);
$this->assertSame($resource, $svgResource);
Barcode\Barcode::setBarcodeFont('');
}
作者:bradley-hol
项目:zf
/**
* Constructor
* @param array|\Zend\Config\Config $options
* @return void
*/
public function __construct($options = null)
{
$this->_getDefaultOptions();
if (Barcode\Barcode::getBarcodeFont() !== null) {
$this->_font = Barcode\Barcode::getBarcodeFont();
}
if ($options instanceof Config\Config) {
$options = $options->toArray();
}
if (is_array($options)) {
$this->setOptions($options);
}
/** @todo check if conversion is correct */
// $this->_type = strtolower(substr(get_class($this), strlen($this->_barcodeNamespace) + 1));
$this->_type = substr(strrchr(get_class($this), '\\'), 1);
if ($this->_mandatoryChecksum) {
$this->_withChecksum = true;
$this->_withChecksumInText = true;
}
}
作者:niallmccrudde
项目:zf
public function tearDown()
{
Barcode\Barcode::setBarcodeFont(null);
}
作者:navassouz
项目:zf
public function testProxyBarcodeObjectFont()
{
Barcode\Barcode::setBarcodeFont('my_font.ttf');
$barcode = new Object\Code25();
$this->assertSame('my_font.ttf', $barcode->getFont());
Barcode\Barcode::setBarcodeFont('');
}
作者:raZ3
项目:zf
/**
* Constructor
* @param array|Traversable $options
* @return void
*/
public function __construct($options = null)
{
$this->getDefaultOptions();
$this->font = Barcode\Barcode::getBarcodeFont();
if ($options instanceof Traversable) {
$options = ArrayUtils::iteratorToArray($options);
}
if (is_array($options)) {
$this->setOptions($options);
}
$this->type = strtolower(substr(get_called_class(), strlen($this->barcodeNamespace) + 1));
if ($this->mandatoryChecksum) {
$this->withChecksum = true;
$this->withChecksumInText = true;
}
}
作者:stunt
项目:zf
/**
* @expectedException \Zend\Barcode\Renderer\Exception
*/
public function testNoFontWithOrientation()
{
Barcode\Barcode::setBarcodeFont(null);
$barcode = new Object\Code39(array('text' => '0123456789'));
$barcode->setOrientation(1);
$this->_renderer->setBarcode($barcode);
$this->_renderer->draw();
}
作者:odegroo
项目:er
public function eticketHtmlAction()
{
$em = $this->getServiceLocator()->get('Doctrine\\ORM\\EntityManager');
$package = $em->getRepository("ErsBase\\Entity\\Package")->findOneBy(array('id' => 52));
$products = $em->getRepository("ErsBase\\Entity\\Product")->findAll();
$config = $this->getServiceLocator()->get('Config');
$name = $package->getParticipant()->getFirstname() . ' ' . $package->getParticipant()->getSurname();
$code = $package->getCode()->getValue();
/*
* QR-Code creation
*/
$qr = $this->getServiceLocator()->get('QRCode');
$qr->isHttps();
// or $qr->isHttp();
#$qr->setData('http://prereg.eja.net/onsite/register/'. \urlencode($code));
$onsitereg = $config['ERS']['onsitereg'];
# ensure the url has no trailing slash
\rtrim($onsitereg, '/\\');
$qr->setData($onsitereg . '/' . \urlencode($code));
$qr->setCorrectionLevel('H', 0);
$qr->setDimensions(200, 200);
$qr_config = array('adapter' => 'Zend\\Http\\Client\\Adapter\\Socket', 'ssltransport' => 'tls', 'sslcapath' => '/etc/ssl/certs/', 'sslverifypeer' => false);
// Instantiate a client object
$client = new \Zend\Http\Client($qr->getResult(), $qr_config);
// The following request will be sent over a TLS secure connection.
$response = $client->send();
$qr_content = $response->getContent();
$base64_qrcode = "data:image/png;base64," . \base64_encode($qr_content);
#file_put_contents(getcwd().'/public/img/qrcode.png', $qr_content);
/*
* Barcode creation
*/
// Only the text to draw is required
$barcodeOptions = array('text' => $code, 'barHeight' => 40, 'factor' => 1.1, 'drawText' => false);
// No required options
$rendererOptions = array();
// Draw the barcode in a new image,
$imageResource = \Zend\Barcode\Barcode::factory('code39', 'image', $barcodeOptions, $rendererOptions)->draw();
ob_start();
//Start output buffer.
imagejpeg($imageResource);
//This will normally output the image, but because of ob_start(), it won't.
$contents = ob_get_contents();
//Instead, output above is saved to $contents
ob_end_clean();
//End the output buffer.
#file_put_contents(getcwd().'/public/img/barcode2.jpg', $contents);
$base64_barcode = "data:image/png;base64," . \base64_encode($contents);
/*
* prepare items
*/
$items = array();
foreach ($package->getItems() as $item) {
$items[$item->getProductId()][] = $item;
}
$agegroupService = $this->getServiceLocator()->get('PreReg\\Service\\AgegroupService:ticket');
$agegroup = $agegroupService->getAgegroupByUser($package->getParticipant());
/*
* generate PDF
*/
$viewModel = new ViewModel();
#$viewModel->setTemplate('pdf/eticket_'.$this->getLanguage());
$viewModel->setTemplate('pdf/eticket_en');
$viewModel->setVariables(array('name' => $name, 'package' => $package, 'items' => $items, 'products' => $products, 'agegroup' => $agegroup, 'code' => $code, 'qrcode' => $base64_qrcode, 'barcode' => $base64_barcode));
return $viewModel;
}
作者:jmibl
项目:sgc
/**
* @return string
*
* This function returns the barcode represented in a PNG image.
* The Zend\Barcode library is used, and receives a string with the barcode
* excluding the check digit (checksum).
* This function only generates GTIN-12, GTIN-13 and GTIN-14 codes.
*/
public function getImage()
{
$subCode = substr($this->getCode(), 0, -1);
$code_type = '';
if ($this->getType() == 'TYPECODE_GTIN_12') {
$code_type = 'upca';
}
if ($this->getType() == 'TYPECODE_GTIN_13') {
$code_type = 'ean13';
}
if ($this->getType() == 'TYPECODE_GTIN_14') {
$code_type = 'itf14';
}
//When working with type code ITF, it should be framed.
if ($this->getType() == 'TYPECODE_GTIN_14') {
$barcodeOptions = array('text' => $subCode, 'withBorder' => true, 'factor' => 1);
} else {
$barcodeOptions = array('text' => $subCode, 'factor' => 1);
}
$rendererOptions = array();
/** @var Gd $image */
$image = \Zend\Barcode\Barcode::factory($code_type, 'image', $barcodeOptions, $rendererOptions)->draw();
ob_start();
imagepng($image);
$contents = ob_get_contents();
ob_end_clean();
return $contents;
}
作者:alab100110
项目:zf
public function tearDown()
{
Barcode\Barcode::setBarcodeFont(null);
date_default_timezone_set($this->_originaltimezone);
}