public function __construct() { if (!EscposImage::isImagickLoaded()) { throw new Exception("ImagePrintBuffer requires the imagick extension"); } $this->font = null; $this->fontSize = 24; }
function __construct() { if (!EscposImage::isImagickLoaded()) { throw new Exception("ImagePrintBuffer requires the imagick extension"); } }
protected function requireGraphicsLibrary() { if (!EscposImage::isGdLoaded() && !EscposImage::isImagickLoaded()) { $this->markTestSkipped("This test requires a graphics library."); } }
/** * Load a PDF for use on the printer * * @param string $pdfFile * The file to load * @param string $pageWidth * The width, in pixels, of the printer's output. The first page of the * PDF will be scaled to approximately fit in this area. * @throws Exception Where Imagick is not loaded, or where a missing file * or invalid page number is requested. * @return multitype:EscposImage Array of images, retrieved from the PDF file. */ public static function loadPdf($pdfFile, $pageWidth = 550) { if (!EscposImage::isImagickLoaded()) { throw new Exception(__FUNCTION__ . " requires imagick extension."); } /* * Load first page at very low density (resolution), to figure out what * density to use to achieve $pageWidth */ try { $image = new \Imagick(); $testRes = 2; // Test resolution $image->setresolution($testRes, $testRes); /* Load document just to measure geometry */ $image->readimage($pdfFile); $geo = $image->getimagegeometry(); $image->destroy(); $width = $geo['width']; $newRes = $pageWidth / $width * $testRes; /* Load entire document in */ $image->setresolution($newRes, $newRes); $image->readImage($pdfFile); $pages = $image->getNumberImages(); /* Convert images to Escpos objects */ $ret = array(); for ($i = 0; $i < $pages; $i++) { $image->setIteratorIndex($i); $ep = new ImagickEscposImage(); $ep->readImageFromImagick($image); $ret[] = $ep; } return $ret; } catch (\ImagickException $e) { /* Wrap in normal exception, so that classes which call this do not * themselves require imagick as a dependency. */ throw new Exception($e); } }