/**
  * Calculate the left and top offset of the barcode in the
  * rendering support
  *
  * @param  float $supportHeight
  * @param  float $supportWidth
  * @return void
  */
 protected function adjustPosition($supportHeight, $supportWidth)
 {
     $barcodeHeight = $this->barcode->getHeight(true) * $this->moduleSize;
     if ($barcodeHeight != $supportHeight && $this->topOffset == 0) {
         switch ($this->verticalPosition) {
             case 'middle':
                 $this->topOffset = floor(($supportHeight - $barcodeHeight) / 2);
                 break;
             case 'bottom':
                 $this->topOffset = $supportHeight - $barcodeHeight;
                 break;
             case 'top':
             default:
                 $this->topOffset = 0;
                 break;
         }
     }
     $barcodeWidth = $this->barcode->getWidth(true) * $this->moduleSize;
     if ($barcodeWidth != $supportWidth && $this->leftOffset == 0) {
         switch ($this->horizontalPosition) {
             case 'center':
                 $this->leftOffset = floor(($supportWidth - $barcodeWidth) / 2);
                 break;
             case 'right':
                 $this->leftOffset = $supportWidth - $barcodeWidth;
                 break;
             case 'left':
             default:
                 $this->leftOffset = 0;
                 break;
         }
     }
 }
Esempio n. 2
0
 protected function doDrawBarcode($x, $y, Barcode $barcode)
 {
     $renderer = new \Zend\Barcode\Renderer\Image(array());
     $imageResource = imagecreate($barcode->getWidth(true) + 1, $barcode->getHeight(true) + 1);
     $renderer->setResource($imageResource);
     $renderer->setBarcode($barcode);
     $renderer->draw();
     ob_start();
     imagepng($imageResource);
     $image = ob_get_clean();
     @imagedestroy($image);
     $image = $this->imagine->load($image);
     $image = $image->resize(new Box($image->getSize()->getWidth() / 2, $image->getSize()->getHeight() / 2));
     list($currentImage, $point) = $this->getCurrentClip();
     $currentImage->paste($image, $this->translatePoint($point, $x, $this->convertYCoord($y)));
 }