当前位置: 首页>>代码示例>>PHP>>正文


PHP Barcode::factory方法代码示例

本文整理汇总了PHP中Zend\Barcode\Barcode::factory方法的典型用法代码示例。如果您正苦于以下问题:PHP Barcode::factory方法的具体用法?PHP Barcode::factory怎么用?PHP Barcode::factory使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Zend\Barcode\Barcode的用法示例。


在下文中一共展示了Barcode::factory方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: create

 /**
  * @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;
 }
开发者ID:adaoex,项目名称:zf2-phpbol,代码行数:33,代码来源:Codigobarra.php

示例2: prepare

 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;
 }
开发者ID:marcusvy,项目名称:PHP-Boleto-ZF2,代码行数:57,代码来源:Santander.php

示例3: getCodigoBarrasBase64

 /**
  * 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);
 }
开发者ID:pentagramacs,项目名称:sped-gnre,代码行数:18,代码来源:Barcode128.php

示例4: indexAction

 /**
  * 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]);
 }
开发者ID:shitikovkirill,项目名称:LearnZF2,代码行数:19,代码来源:BarcodeController.php

示例5: prepare

 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;
 }
开发者ID:jotjunior,项目名称:boletophp-zf2,代码行数:46,代码来源:Bancoob.php

示例6: prepare

 public function prepare()
 {
     /**
      * adicionando dados das instruções e demonstrativo no boleto
      */
     (new ClassMethods())->hydrate($this->config['php-zf2-boleto']['instrucoes'], $this->getBoleto());
     /**
      * 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);
     /**
      * Formatando os dados bancários do cedente para impressão
      */
     $this->getCedente()->setAgenciaCodigo($this->getCedente()->getAgencia() . '-' . $this->getCedente()->getAgenciaDv() . ' / ' . $this->getCedente()->getContaCorrente() . '-' . $this->getCedente()->getContaCorrenteDv());
     // usado quando convenio tem 7 digitos
     $livreZeros = '000000';
     switch ($this->getCedente()->getFormatacaoConvenio()) {
         case 8:
             $convenioProcessado = str_pad($this->getCedente()->getConvenio(), 8, '0', STR_PAD_LEFT);
             $nossoNumeroProcessado = str_pad($this->getBoleto()->getNossoNumero(), 9, '0', STR_PAD_LEFT);
             $DV = Util::modulo11($this->getBanco()->getCodigoBanco() . $this->getBanco()->getMoeda() . $fatorVencimento . $valorProcessado . $livreZeros . $convenioProcessado . $nossoNumeroProcessado . $this->getBanco()->getCarteira());
             $strLinha = $this->getBanco()->getCodigoBanco() . $this->getBanco()->getMoeda() . $DV . $fatorVencimento . $valorProcessado . $livreZeros . $convenioProcessado . $nossoNumeroProcessado . $this->getBanco()->getCarteira();
             $nossoNumeroFormatado = $convenioProcessado . $nossoNumeroProcessado . '-' . Util::modulo11($convenioProcessado . $nossoNumeroProcessado);
             break;
         case 7:
             $convenioProcessado = str_pad($this->getCedente()->getConvenio(), 7, '0', STR_PAD_LEFT);
             $nossoNumeroProcessado = str_pad($this->getBoleto()->getNossoNumero(), 10, '0', STR_PAD_LEFT);
             $DV = Util::modulo11($this->getBanco()->getCodigoBanco() . $this->getBanco()->getMoeda() . $fatorVencimento . $valorProcessado . $livreZeros . $convenioProcessado . $nossoNumeroProcessado . $this->getBanco()->getCarteira());
             $strLinha = $this->getBanco()->getCodigoBanco() . $this->getBanco()->getMoeda() . $DV . $fatorVencimento . $valorProcessado . $livreZeros . $convenioProcessado . $nossoNumeroProcessado . $this->getBanco()->getCarteira();
             $nossoNumeroFormatado = $convenioProcessado . $nossoNumeroProcessado;
             break;
         case 6:
             $convenioProcessado = str_pad($this->getCedente()->getConvenio(), 6, '0', STR_PAD_LEFT);
             switch ($this->getBoleto()->getFormatacaoNossoNumero()) {
                 case 1:
                     $nossoNumeroProcessado = str_pad($this->getBoleto()->getNossoNumero(), 5, '0', STR_PAD_LEFT);
                     $DV = Util::modulo11($this->getBanco()->getCodigoBanco() . $this->getBanco()->getMoeda() . $fatorVencimento . $valorProcessado . $convenioProcessado . $nossoNumeroProcessado . $this->getCedente()->getAgencia() . $this->getCedente()->getContaCorrente() . $this->getCedente()->getCarteira());
                     $strLinha = $this->getBanco()->getCodigoBanco() . $this->getBanco()->getMoeda() . $DV . $fatorVencimento . $valorProcessado . $convenioProcessado . $nossoNumeroProcessado . $this->getCedente()->getAgencia() . $this->getCedente()->getContaCorrente() . $this->getCedente()->getCarteira();
                     $nossoNumeroFormatado = $convenioProcessado . $nossoNumeroProcessado . '-' . Util::modulo11($convenioProcessado . $nossoNumeroProcessado);
                     break;
                 case 2:
                     $numeroServico = 21;
                     $nossoNumeroProcessado = str_pad($this->getBoleto()->getNossoNumero(), 17, '0', STR_PAD_LEFT);
                     $DV = Util::modulo11($this->getBanco()->getCodigoBanco() . $this->getBanco()->getMoeda() . $fatorVencimento . $valorProcessado . $convenioProcessado . $nossoNumeroProcessado . $numeroServico);
                     $strLinha = $this->getBanco()->getCodigoBanco() . $this->getBanco()->getMoeda() . $DV . $fatorVencimento . $valorProcessado . $convenioProcessado . $nossoNumeroProcessado . $numeroServico;
                     $nossoNumeroFormatado = $nossoNumeroProcessado;
                     break;
             }
             break;
     }
     /**
      * 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;
 }
开发者ID:AlysonRodrigo,项目名称:PHP-Boleto-ZF2,代码行数:70,代码来源:BB.php

示例7: ob_start

<?php

require '../vendor/autoload.php';
ob_start();
$text = '91910919190191091090109109190109';
$options = array('text' => (string) $text, 'barHeight' => 40, 'barWidth' => 100, 'imageType' => 'jpeg');
$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();
$barcodeGnre = new \Gnre\Render\Barcode128();
$barcodeGnre->setNumeroCodigoBarras('91910919190191091090109109190109');
?>

<img src="<?php 
echo 'data:image/jpeg;base64,' . $barcodeGnre->getCodigoBarrasBase64();
?>
"/>
<img src="<?php 
echo 'data:image/jpeg;base64,' . base64_encode($contents);
?>
"/>

开发者ID:pentagramacs,项目名称:sped-gnre,代码行数:25,代码来源:gerar-codigo-de-barras.php

示例8: testFactoryWithExistingBarcodeObject

 public function testFactoryWithExistingBarcodeObject()
 {
     $this->checkGDRequirement();
     $barcode = new Object\Code25();
     $renderer = Barcode\Barcode::factory($barcode);
     $this->assertSame($barcode, $renderer->getBarcode());
 }
开发者ID:navassouza,项目名称:zf2,代码行数:7,代码来源:FactoryTest.php

示例9: saveAs

 /**
  * @param $type
  * @param $text
  * @param $file
  * @param array $options
  * @return bool
  */
 public function saveAs($type, $text, $file, $options = array())
 {
     @unlink($file);
     switch ($type) {
         case $type == 'qr':
             include_once __DIR__ . DIRECTORY_SEPARATOR . ".." . DIRECTORY_SEPARATOR . "Resources" . DIRECTORY_SEPARATOR . "phpqrcode" . DIRECTORY_SEPARATOR . "qrlib.php";
             $level = isset($options['level']) ? $options['level'] : QR_ECLEVEL_L;
             $size = isset($options['size']) ? $options['size'] : 3;
             $margin = isset($options['margin']) ? $options['margin'] : 4;
             \QRcode::png($text, $file, $level, $size, $margin);
             if (isset($options['useOverlay']) && $options['useOverlay']) {
                 $this->addOverlay($file, $size);
             }
             break;
         case is_numeric($type):
             $type = $this->types[$type];
         default:
             $barcodeOptions = array_merge(isset($options['barcodeOptions']) ? $options['barcodeOptions'] : array(), array('text' => $text));
             $rendererOptions = isset($options['rendererOptions']) ? $options['rendererOptions'] : array();
             $rendererOptions['width'] = isset($rendererOptions['width']) ? $rendererOptions['width'] : 2233;
             $rendererOptions['height'] = isset($rendererOptions['height']) ? $rendererOptions['height'] : 649;
             $image = new Image($imageResource = Barcode::factory($type, 'image', $barcodeOptions, $rendererOptions)->draw());
             $image->save($file);
     }
     return true;
 }
开发者ID:kustov-vitalik,项目名称:MopaBarcodeBundle,代码行数:33,代码来源:BarcodeService.php

示例10: saveAs

 public function saveAs($type, $text, $file)
 {
     $fontfile = __DIR__ . DIRECTORY_SEPARATOR . ".." . DIRECTORY_SEPARATOR . "Resources" . DIRECTORY_SEPARATOR . "fonts" . DIRECTORY_SEPARATOR . 'Lato-Regular.ttf';
     @unlink($file);
     switch ($type) {
         case $type == 99:
             include_once __DIR__ . DIRECTORY_SEPARATOR . ".." . DIRECTORY_SEPARATOR . "Resources" . DIRECTORY_SEPARATOR . "phpqrcode" . DIRECTORY_SEPARATOR . "qrlib.php";
             \QRcode::png($text, $file, QR_ECLEVEL_L, 12);
             break;
         case $type == 90:
             $font = new \Imagine\Gd\Font($fontfile, 35, new \Imagine\Image\Color('fff', 100));
             $resource = imagecreatetruecolor(2000, 60);
             $color = new \Imagine\Image\Color('fff');
             $white = imagecolorallocate($resource, 255, 255, 255);
             $black = imagecolorallocate($resource, 0, 0, 0);
             if (false === $white) {
                 throw new RuntimeException('Unable to allocate color');
             }
             if (false === imagefill($resource, 0, 0, $white)) {
                 throw new RuntimeException('Could not set background color fill');
             }
             imagettftext($resource, 35, 0, 10, 50, $black, $fontfile, $text);
             $image = new Image($resource);
             $image->crop(new \Imagine\Image\Point(0, 0), new \Imagine\Image\Box(20 + $font->box($text)->getWidth(), 60));
             $image->save($file);
             break;
         case is_numeric($type):
             $type = $this->types[$type];
         default:
             $validator = new BarcodeValidator(array('adapter' => $type, 'usechecksum' => false));
             //                if (!$validator->isValid($text)) {
             //                    $message = implode("\n", $validator->getMessages());
             //                    throw new \Symfony\Component\HttpKernel\Exception\HttpException(401, $message, null);
             //                }
             //z apki dostaje barcody z
             //                if($type == 'ean13')
             //                {
             //                    $text = substr($text, 0, -1);
             //                }
             $barcodeOptions = array('text' => $text, 'factor' => 3, 'font' => __DIR__ . DIRECTORY_SEPARATOR . ".." . DIRECTORY_SEPARATOR . "Resources" . DIRECTORY_SEPARATOR . "fonts" . DIRECTORY_SEPARATOR . 'Lato-Regular.ttf');
             $rendererOptions = array();
             $imageRenderer = Barcode::factory($type, 'image', $barcodeOptions, $rendererOptions, false);
             //fix to not throw error when try to render barcode with code with checksum
             if ($imageRenderer->getBarcode()->getWithChecksum()) {
                 //maybe i got barcode without checksum need to test it by try cache :(
                 try {
                     $imageRenderer->getBarcode()->validateText($text);
                 } catch (\Exception $exc) {
                     //propably length error remove checksum
                     //when barcode have mandatoryChecksum and have default
                     //validateSpecificText then renderer waiting for code without checksum :(
                     $imageRenderer->getBarcode()->setText(substr($text, 0, -1));
                 }
             }
             //catch error and send http error 400 not 500 as default
             try {
                 $image = new Image($imageRenderer->draw());
             } catch (\Exception $exc) {
                 $message = $exc->getMessage();
                 throw new \Symfony\Component\HttpKernel\Exception\HttpException(400, $message, null);
             }
             $image->save($file);
     }
     return true;
 }
开发者ID:ramol,项目名称:MopaBarcodeBundle,代码行数:65,代码来源:BarcodeService.php

示例11: generatePdf

 public function generatePdf()
 {
     $config = $this->getServiceLocator()->get('Config');
     if (!extension_loaded('gd')) {
         throw new \Exception('PHP Extension gd needs to be loaded.');
     }
     /*
      * PDF creation
      */
     $paperSize = 'a4';
     $paperOrientation = 'portrait';
     $pdf = new PdfModel();
     $pdf->setOption("paperSize", $paperSize);
     //Defaults to 8x11
     $pdf->setOption("paperOrientation", $paperOrientation);
     //Defaults to portrait
     $name = $this->getParticipant()->getFirstname() . ' ' . $this->getParticipant()->getSurname();
     $code = $this->getPackage()->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 ($this->getPackage()->getItems() as $item) {
         if ($item->getStatus() == 'transferred') {
             continue;
         }
         $items[$item->getProductId()][] = $item;
     }
     /* 
      * generate PDF
      */
     $pdfView = new ViewModel();
     $pdfView->setTemplate('pdf/eticket_' . $this->getLanguage());
     $pdfView->setVariables(array('name' => $name, 'package' => $this->getPackage(), 'items' => $items, 'products' => $this->getProducts(), 'agegroup' => $this->getAgegroup(), 'code' => $code, 'qrcode' => $base64_qrcode, 'barcode' => $base64_barcode));
     $pdfRenderer = $this->getServiceLocator()->get('ViewPdfRenderer');
     $html = $pdfRenderer->getHtmlRenderer()->render($pdfView);
     $pdfEngine = $pdfRenderer->getEngine();
     $pdfEngine->set_paper($paperSize, $paperOrientation);
     $pdfEngine->set_base_path(getcwd() . '/');
     $pdfEngine->load_html($html);
     $pdfEngine->render();
     $pdfContent = $pdfEngine->output();
     $filename = $config['ERS']['name_short'] . "_e-Ticket_" . $this->getPackage()->getCode()->getValue() . '_' . $this->getLanguage();
     # TODO: make ticket_path configurable
     $ticket_path = getcwd() . '/data/etickets';
     \rtrim($onsitereg, '/\\');
     if (!is_dir($ticket_path)) {
         mkdir($ticket_path);
     }
     $filePath = $ticket_path . '/' . $filename . '.pdf';
     file_put_contents($filePath, $pdfContent);
     return $filePath;
 }
开发者ID:odegroot,项目名称:ers,代码行数:93,代码来源:ETicketService.php

示例12: eticketHtmlAction

 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;
 }
开发者ID:odegroot,项目名称:ers,代码行数:66,代码来源:TestController.php

示例13: getImage

 /**
  * @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;
 }
开发者ID:jmibla,项目名称:sgcl,代码行数:36,代码来源:Barcode.php

示例14: generatepdfAction

 public function generatepdfAction()
 {
     if (!extension_loaded('gd')) {
         throw new Exception('PHP Extension gd needs to be loaded.');
     }
     /*
      * PDF creation
      */
     $pdf = new PdfModel();
     $pdf->setOption("paperSize", "a4");
     //Defaults to 8x11
     $pdf->setOption("paperOrientation", "portrait");
     //Defaults to portrait
     $name = 'Andreas Nitsche';
     $code = 'AABBCCDD';
     /*
      * QR-Code creation
      */
     $qr = $this->getServiceLocator()->get('QRCode');
     $qr->isHttps();
     // or $qr->isHttp();
     $qr->setData('http://prereg.eja.net/onsite/register/' . \urlencode($code));
     $qr->setCorrectionLevel('H', 0);
     $qr->setDimensions(200, 200);
     $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(), $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);
     /*
      * Code creation
      */
     // Only the text to draw is required
     $barcodeOptions = array('text' => $code, 'barHeight' => 40, 'factor' => 1.1);
     // 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);
     /*
      * PDF generation to view
      */
     /*
     $pdf->setVariables(array(
         'name' => $name,
         'code' => $code,
         'qrcode' => $base64_qrcode,
         'barcode' => $base64_barcode,
     ));
     $filename = "EJC2015_e-ticket_".preg_replace('/\ /', '_', $name);
     $pdf->setOption("filename", $filename);
     return $pdf;
     */
     /***********************************/
     $pdfView = new ViewModel();
     $pdfView->setTemplate('pre-reg/test/generatepdf');
     $pdfView->setVariables(array('name' => $name, 'code' => $code, 'qrcode' => $base64_qrcode, 'barcode' => $base64_barcode));
     $pdfRenderer = $this->getServiceLocator()->get('ViewPdfRenderer');
     $html = $pdfRenderer->getHtmlRenderer()->render($pdfView);
     $pdfEngine = $pdfRenderer->getEngine();
     $pdfEngine->load_html($html);
     $pdfEngine->render();
     $pdfContent = $pdfEngine->output();
     $filename = "EJC2015_e-ticket_" . preg_replace('/\\ /', '_', $name);
     file_put_contents(getcwd() . '/public/img/' . $filename . '.pdf', $pdfContent);
     return new ViewModel();
 }
开发者ID:odegroot,项目名称:ers,代码行数:79,代码来源:TestController.php

示例15: setBarcodeImgBase64

 /**
  * Gera uma imagem com barras no formato base64
  * seta o parametro 'codigoBarra' das classe 'boletoData'
  */
 public function setBarcodeImgBase64()
 {
     try {
         /*
          * Opções do Zend\Barcode 
          *  text: valor para gerar as barras
          *  drawText:(false) mostrar o texto do código abaixo das barras
          */
         $barcodeOptions = array('text' => $this->getCodigoBarra(), 'drawText' => false);
         /* Desenha o código de barras em uma nova imagem
          *  $barcodeType = 'code25interleaved' - formato utilizado pelo 
          *      Banco do Brasil
          *  $type = 'image' - gera uma imagem
          */
         $imageResource = Barcode::factory('code25interleaved', 'image', $barcodeOptions, array())->draw();
         // habilitar saida buffering
         ob_start();
         imagepng($imageResource);
         imagedestroy($imageResource);
         // Capture a output
         $imagedata = ob_get_contents();
         // limpa saida buffer
         ob_end_clean();
         $img = base64_encode($imagedata);
         /* set */
         $this->offsetGet('boletoData')->setData(array('codigoBarra' => $img));
         return $this;
     } catch (Exception $e) {
         echo 'Erro: na geração de código de barra!';
         echo 'Código: ' . $e->getCode();
         echo 'Mensagem: ' . $e->getMessage();
         echo 'Trace: ' . $e->getTraceAsString();
         return false;
     }
 }
开发者ID:adaoex,项目名称:zf2-phpbol,代码行数:39,代码来源:BoletoBB.php


注:本文中的Zend\Barcode\Barcode::factory方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。