recreate project
@@ -0,0 +1,34 @@
|
||||
<?php
|
||||
error_reporting(E_ALL);
|
||||
ini_set('display_errors', 1);
|
||||
|
||||
$composer_autoload = __DIR__ . "/../vendor/autoload.php";
|
||||
require_once($composer_autoload);
|
||||
|
||||
/**
|
||||
* Used in many of the tests to to output known-correct
|
||||
* strings for use in tests.
|
||||
*/
|
||||
function friendlyBinary($in)
|
||||
{
|
||||
if (is_array($in)) {
|
||||
$out = array();
|
||||
foreach ($in as $line) {
|
||||
$out[] = friendlyBinary($line);
|
||||
}
|
||||
return "[" . implode(", ", $out) . "]";
|
||||
}
|
||||
if (strlen($in) == 0) {
|
||||
return $in;
|
||||
}
|
||||
/* Print out binary data with PHP \x00 escape codes,
|
||||
for builting test cases. */
|
||||
$chars = str_split($in);
|
||||
foreach ($chars as $i => $c) {
|
||||
$code = ord($c);
|
||||
if ($code < 32 || $code > 126) {
|
||||
$chars[$i] = "\\x" . bin2hex($c);
|
||||
}
|
||||
}
|
||||
return implode($chars);
|
||||
}
|
||||
@@ -0,0 +1,200 @@
|
||||
<?php
|
||||
use Mike42\Escpos\EscposImage;
|
||||
|
||||
class ExampleTest extends PHPUnit\Framework\TestCase
|
||||
{
|
||||
/* Verify that the examples don't fizzle out with fatal errors */
|
||||
private $exampleDir;
|
||||
|
||||
public function setUp(): void
|
||||
{
|
||||
$this -> exampleDir = dirname(__FILE__) . "/../../example/";
|
||||
}
|
||||
|
||||
/**
|
||||
* @medium
|
||||
*/
|
||||
public function testBitImage()
|
||||
{
|
||||
$this->markTestSkipped('Not repeatable on Travis CI.');
|
||||
$this -> requireGraphicsLibrary();
|
||||
$outp = $this -> runExample("bit-image.php");
|
||||
$this -> outpTest($outp, "bit-image.bin");
|
||||
}
|
||||
|
||||
/**
|
||||
* @medium
|
||||
*/
|
||||
public function testCharacterEncodings()
|
||||
{
|
||||
$outp = $this -> runExample("character-encodings.php");
|
||||
$this -> outpTest($outp, "character-encodings.bin");
|
||||
}
|
||||
|
||||
/**
|
||||
* @medium
|
||||
*/
|
||||
public function testCharacterTables()
|
||||
{
|
||||
$outp = $this -> runExample("character-tables.php");
|
||||
$this -> outpTest($outp, "character-tables.bin");
|
||||
}
|
||||
|
||||
private function outpTest($outp, $fn)
|
||||
{
|
||||
$file = dirname(__FILE__) . "/resources/output/".$fn;
|
||||
if (!file_exists($file)) {
|
||||
file_put_contents($file, $outp);
|
||||
}
|
||||
$this -> assertEquals($outp, file_get_contents($file));
|
||||
}
|
||||
|
||||
/**
|
||||
* @medium
|
||||
*/
|
||||
public function testDemo()
|
||||
{
|
||||
$this->markTestSkipped('Not repeatable on Travis CI.');
|
||||
$this -> requireGraphicsLibrary();
|
||||
$outp = $this -> runExample("demo.php");
|
||||
$this -> outpTest($outp, "demo.bin");
|
||||
}
|
||||
|
||||
/**
|
||||
* @medium
|
||||
*/
|
||||
public function testGraphics()
|
||||
{
|
||||
$this->markTestSkipped('Not repeatable on Travis CI.');
|
||||
$this -> requireGraphicsLibrary();
|
||||
$outp = $this -> runExample("graphics.php");
|
||||
$this -> outpTest($outp, "graphics.bin");
|
||||
}
|
||||
|
||||
/**
|
||||
* @medium
|
||||
*/
|
||||
public function testReceiptWithLogo()
|
||||
{
|
||||
$this->markTestSkipped('Not repeatable on Travis CI.');
|
||||
$this -> requireGraphicsLibrary();
|
||||
$outp = $this -> runExample("receipt-with-logo.php");
|
||||
$this -> outpTest($outp, "receipt-with-logo.bin");
|
||||
}
|
||||
|
||||
/**
|
||||
* @medium
|
||||
*/
|
||||
public function testQrCode()
|
||||
{
|
||||
$outp = $this -> runExample("qr-code.php");
|
||||
$this -> outpTest($outp, "qr-code.bin");
|
||||
}
|
||||
|
||||
/**
|
||||
* @medium
|
||||
*/
|
||||
public function testBarcode()
|
||||
{
|
||||
$outp = $this -> runExample("barcode.php");
|
||||
$this -> outpTest($outp, "barcode.bin");
|
||||
}
|
||||
|
||||
/**
|
||||
* @medium
|
||||
*/
|
||||
public function testTextSize()
|
||||
{
|
||||
$outp = $this -> runExample("text-size.php");
|
||||
$this -> outpTest($outp, "text-size.bin");
|
||||
}
|
||||
|
||||
/**
|
||||
* @medium
|
||||
*/
|
||||
public function testMarginsAndSpacing()
|
||||
{
|
||||
$outp = $this -> runExample("margins-and-spacing.php");
|
||||
$this -> outpTest($outp, "margins-and-spacing.bin");
|
||||
}
|
||||
|
||||
/**
|
||||
* @medium
|
||||
*/
|
||||
public function testPdf417Code()
|
||||
{
|
||||
$outp = $this -> runExample("pdf417-code.php");
|
||||
$this -> outpTest($outp, "pdf417-code.bin");
|
||||
}
|
||||
|
||||
/**
|
||||
* @medium
|
||||
*/
|
||||
public function testUnifontPrintBuffer()
|
||||
{
|
||||
$this->markTestSkipped('Not repeatable on Travis CI.');
|
||||
if(!file_exists("/usr/share/unifont/unifont.hex")) {
|
||||
$this -> markTestSkipped("Test only repeatable w/ unifont installed");
|
||||
}
|
||||
$outp = $this -> runExample("unifont-print-buffer.php");
|
||||
$this -> outpTest($outp, "unifont-print-buffer.bin");
|
||||
}
|
||||
|
||||
public function testInterfaceCups()
|
||||
{
|
||||
$outp = $this -> runSyntaxCheck("interface/cups.php");
|
||||
}
|
||||
|
||||
public function testInterfaceEthernet()
|
||||
{
|
||||
$outp = $this -> runSyntaxCheck("interface/ethernet.php");
|
||||
}
|
||||
|
||||
public function testInterfaceLinuxUSB()
|
||||
{
|
||||
$outp = $this -> runSyntaxCheck("interface/linux-usb.php");
|
||||
}
|
||||
|
||||
public function testInterfaceWindowsUSB()
|
||||
{
|
||||
$outp = $this -> runSyntaxCheck("interface/windows-usb.php");
|
||||
}
|
||||
|
||||
public function testInterfaceSMB()
|
||||
{
|
||||
$outp = $this -> runSyntaxCheck("interface/smb.php");
|
||||
}
|
||||
|
||||
public function testInterfaceWindowsLPT()
|
||||
{
|
||||
$outp = $this -> runSyntaxCheck("interface/windows-lpt.php");
|
||||
}
|
||||
|
||||
private function runSyntaxCheck($fn)
|
||||
{
|
||||
$this -> runExample($fn, true);
|
||||
}
|
||||
|
||||
private function runExample($fn, $syntaxCheck = false)
|
||||
{
|
||||
// Change directory and check script
|
||||
chdir($this -> exampleDir);
|
||||
$this -> assertTrue(file_exists($fn), "Script $fn not found.");
|
||||
// Run command and save output
|
||||
$php = "php" . ($syntaxCheck ? " -l" : "");
|
||||
ob_start();
|
||||
passthru($php . " " . escapeshellarg($fn), $retval);
|
||||
$outp = ob_get_contents();
|
||||
ob_end_clean();
|
||||
// Check return value
|
||||
$this -> assertEquals(0, $retval, "Example $fn exited with status $retval");
|
||||
return $outp;
|
||||
}
|
||||
|
||||
protected function requireGraphicsLibrary()
|
||||
{
|
||||
if (!EscposImage::isGdLoaded() && !EscposImage::isImagickLoaded()) {
|
||||
$this -> markTestSkipped("gd or imagick plugin is required for this test");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,76 @@
|
||||
<?php
|
||||
|
||||
use Mike42\Escpos\Devices\AuresCustomerDisplay;
|
||||
use Mike42\Escpos\PrintConnectors\DummyPrintConnector;
|
||||
use Mike42\Escpos\CapabilityProfile;
|
||||
|
||||
class AuresCustomerDisplayTest extends PHPUnit\Framework\TestCase
|
||||
{
|
||||
protected $printer;
|
||||
protected $outputConnector;
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
/* Print to nowhere- for testing which inputs are accepted */
|
||||
$this -> outputConnector = new DummyPrintConnector();
|
||||
$profile = CapabilityProfile::load('OCD-300');
|
||||
$this -> printer = new AuresCustomerDisplay($this -> outputConnector, $profile);
|
||||
}
|
||||
|
||||
protected function checkOutput($expected = null)
|
||||
{
|
||||
/* Check those output strings */
|
||||
$outp = $this -> outputConnector -> getData();
|
||||
if ($expected === null) {
|
||||
echo "\nOutput was:\n\"" . friendlyBinary($outp) . "\"\n";
|
||||
}
|
||||
$this -> assertEquals($expected, $outp);
|
||||
}
|
||||
|
||||
protected function tearDown(): void
|
||||
{
|
||||
$this -> outputConnector -> finalize();
|
||||
}
|
||||
|
||||
public function testInitializeOutput()
|
||||
{
|
||||
$this -> checkOutput("\x02\x05C1\x03\x1b@\x1bt\x00\x1f\x02");
|
||||
}
|
||||
|
||||
public function testselectTextScrollMode() {
|
||||
$this -> outputConnector -> clear();
|
||||
$this -> printer -> selectTextScrollMode(AuresCustomerDisplay::TEXT_OVERWRITE);
|
||||
$this -> checkOutput("\x1f\x01");
|
||||
}
|
||||
|
||||
public function testClear() {
|
||||
$this -> outputConnector -> clear();
|
||||
$this -> printer -> clear();
|
||||
$this -> checkOutput("\x0c");
|
||||
}
|
||||
|
||||
public function testShowFirmwareVersion() {
|
||||
$this -> outputConnector -> clear();
|
||||
$this -> printer -> showFirmwareVersion();
|
||||
$this -> checkOutput("\x02\x05V\x01\x03");
|
||||
}
|
||||
|
||||
public function testSelfTest() {
|
||||
$this -> outputConnector -> clear();
|
||||
$this -> printer -> selfTest();
|
||||
$this -> checkOutput("\x02\x05D\x08\x03");
|
||||
}
|
||||
|
||||
public function testShowLogo() {
|
||||
$this -> outputConnector -> clear();
|
||||
$this -> printer -> showLogo();
|
||||
$this -> checkOutput("\x02\xfcU\xaaU\xaa");
|
||||
}
|
||||
|
||||
public function testTest() {
|
||||
$this -> outputConnector -> clear();
|
||||
// Handling of line-endings differs to regular printers, need to use \r\n
|
||||
$this -> printer -> text("Hello\nWorld\n");
|
||||
$this -> checkOutput("Hello\x0d\x0aWorld\x0d\x0a");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,59 @@
|
||||
<?php
|
||||
use Mike42\Escpos\CapabilityProfile;
|
||||
|
||||
class CapabilityProfileTest extends PHPUnit\Framework\TestCase
|
||||
{
|
||||
|
||||
public function testNames()
|
||||
{
|
||||
// Default is on the list
|
||||
$names = CapabilityProfile::getProfileNames();
|
||||
$this->assertFalse(array_search('simple', $names) === false);
|
||||
$this->assertFalse(array_search('default', $names) === false);
|
||||
$this->assertTrue(array_search('lalalalala', $names) === false);
|
||||
}
|
||||
|
||||
public function testLoadDefault()
|
||||
{
|
||||
// Just load the default profile and check it out
|
||||
$profile = CapabilityProfile::load('default');
|
||||
$this->assertEquals("default", $profile->getId());
|
||||
$this->assertEquals("Default", $profile->getName());
|
||||
$this->assertTrue($profile->getSupportsBarcodeB());
|
||||
$this->assertTrue($profile->getSupportsBitImageRaster());
|
||||
$this->assertTrue($profile->getSupportsGraphics());
|
||||
$this->assertTrue($profile->getSupportsQrCode());
|
||||
$this->assertTrue($profile->getSupportsPdf417Code());
|
||||
$this->assertFalse($profile->getSupportsStarCommands());
|
||||
$this->assertArrayHasKey('0', $profile->getCodePages());
|
||||
}
|
||||
|
||||
public function testCodePageCacheKey()
|
||||
{
|
||||
$default = CapabilityProfile::load('default');
|
||||
$simple = CapabilityProfile::load('simple');
|
||||
$this->assertNotEquals($default->getCodePageCacheKey(), $simple->getCodePageCacheKey());
|
||||
}
|
||||
|
||||
public function testBadProfileNameSuggestion()
|
||||
{
|
||||
$this->expectException(InvalidArgumentException::class);
|
||||
$profile = CapabilityProfile::load('simpel');
|
||||
}
|
||||
|
||||
public function testBadFeatureNameSuggestion()
|
||||
{
|
||||
$this->expectException(InvalidArgumentException::class);
|
||||
$profile = CapabilityProfile::load('default');
|
||||
$profile->getFeature('graphicx');
|
||||
}
|
||||
|
||||
public function testSuggestions()
|
||||
{
|
||||
$input = "orangee";
|
||||
$choices = array("apple", "orange", "pear");
|
||||
$suggestions = CapabilityProfile::suggestNearest($input, $choices, 1);
|
||||
$this->assertEquals(1, count($suggestions));
|
||||
$this->assertEquals("orange", $suggestions[0]);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,76 @@
|
||||
<?php
|
||||
use Mike42\Escpos\CodePage;
|
||||
|
||||
class CodePageTest extends PHPUnit\Framework\TestCase
|
||||
{
|
||||
public function testDataGenerated()
|
||||
{
|
||||
// Set up CP437
|
||||
$cp = new CodePage("CP437", array(
|
||||
"name" => "CP437",
|
||||
"iconv" => "CP437"
|
||||
));
|
||||
$dataArray = $cp->getDataArray();
|
||||
$this->assertEquals(128, count($dataArray));
|
||||
$expected = "ÇüéâäàåçêëèïîìÄÅÉæÆôöòûùÿÖÜ¢£¥₧ƒáíóúñѪº¿⌐¬½¼¡«»░▒▓│┤╡╢╖╕╣║╗╝╜╛┐└┴┬├─┼╞╟╚╔╩╦╠═╬╧╨╤╥╙╘╒╓╫╪┘┌█▄▌▐▀αßΓπΣσμτΦΘΩδ∞φε∩≡±≥≤⌠⌡÷≈°∙·√ⁿ²■ ";
|
||||
$this->assertEquals($expected, self::dataArrayToString($dataArray));
|
||||
}
|
||||
|
||||
public function testDataGenerateFailed()
|
||||
{
|
||||
// No errors raised, you just get an empty list of supported characters if you try to compute a fake code page
|
||||
$cp = new CodePage("foo", array(
|
||||
"name" => "foo",
|
||||
"iconv" => "foo"
|
||||
));
|
||||
$this->assertTrue($cp->isEncodable());
|
||||
$this->assertEquals($cp->getIconv(), "foo");
|
||||
$this->assertEquals($cp->getName(), "foo");
|
||||
$this->assertEquals($cp->getId(), "foo");
|
||||
$this->assertEquals($cp->getNotes(), null);
|
||||
$dataArray = $cp->getDataArray();
|
||||
$expected = str_repeat(" ", 128);
|
||||
$this->assertEquals($expected, self::dataArrayToString($dataArray));
|
||||
// Do this twice (caching behaviour)
|
||||
$dataArray = $cp->getDataArray();
|
||||
$this->assertEquals($expected, self::dataArrayToString($dataArray));
|
||||
}
|
||||
|
||||
public function testDataDefined()
|
||||
{
|
||||
// A made up code page called "baz", which is the same as CP437 but with some unmapped values at the start.
|
||||
$cp = new CodePage("baz", array(
|
||||
"name" => "baz",
|
||||
"iconv" => "baz",
|
||||
"data" => [
|
||||
" âäàåçêëèïîìÄÅ",
|
||||
"ÉæÆôöòûùÿÖÜ¢£¥₧ƒ",
|
||||
"áíóúñѪº¿⌐¬½¼¡«»",
|
||||
"░▒▓│┤╡╢╖╕╣║╗╝╜╛┐",
|
||||
"└┴┬├─┼╞╟╚╔╩╦╠═╬╧",
|
||||
"╨╤╥╙╘╒╓╫╪┘┌█▄▌▐▀",
|
||||
"αßΓπΣσμτΦΘΩδ∞φε∩",
|
||||
"≡±≥≤⌠⌡÷≈°∙·√ⁿ²■ "]
|
||||
));
|
||||
$dataArray = $cp->getDataArray();
|
||||
$this->assertEquals(128, count($dataArray));
|
||||
$expected = " âäàåçêëèïîìÄÅÉæÆôöòûùÿÖÜ¢£¥₧ƒáíóúñѪº¿⌐¬½¼¡«»░▒▓│┤╡╢╖╕╣║╗╝╜╛┐└┴┬├─┼╞╟╚╔╩╦╠═╬╧╨╤╥╙╘╒╓╫╪┘┌█▄▌▐▀αßΓπΣσμτΦΘΩδ∞φε∩≡±≥≤⌠⌡÷≈°∙·√ⁿ²■ ";
|
||||
$this->assertEquals($expected, self::dataArrayToString($dataArray));
|
||||
}
|
||||
|
||||
public function testDataCannotEncode()
|
||||
{
|
||||
$this->expectException(InvalidArgumentException::class);
|
||||
$cp = new CodePage("foo", array(
|
||||
"name" => "foo"
|
||||
));
|
||||
$this->assertFalse($cp->isEncodable());
|
||||
$cp->getDataArray();
|
||||
}
|
||||
|
||||
private static function dataArrayToString(array $codePoints) : string
|
||||
{
|
||||
// Assemble into character string so that the assertion is more compact
|
||||
return implode(array_map("IntlChar::chr", $codePoints));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
<?php
|
||||
use Mike42\Escpos\PrintConnectors\CupsPrintConnector;
|
||||
|
||||
class CupsPrintConnectorTest extends PHPUnit\Framework\TestCase
|
||||
{
|
||||
private $connector;
|
||||
public function testPrinterExists()
|
||||
{
|
||||
$connector = $this->getMockConnector("FooPrinter", array("FooPrinter"));
|
||||
$connector->expects($this->once())->method('getCmdOutput')->with($this->stringContains("lp -d 'FooPrinter' "));
|
||||
$connector->finalize();
|
||||
}
|
||||
public function testPrinterDoesntExist()
|
||||
{
|
||||
$this -> expectException(BadMethodCallException::class);
|
||||
$connector = $this->getMockConnector("FooPrinter", array("OtherPrinter"));
|
||||
$connector->expects($this->once())->method('getCmdOutput')->with($this->stringContains("lp -d 'FooPrinter' "));
|
||||
$connector->finalize();
|
||||
}
|
||||
public function testNoPrinter()
|
||||
{
|
||||
$this -> expectException(BadMethodCallException::class);
|
||||
$connector = $this->getMockConnector("FooPrinter", array(""));
|
||||
}
|
||||
private function getMockConnector($path, array $printers)
|
||||
{
|
||||
$stub = $this->getMockBuilder('Mike42\Escpos\PrintConnectors\CupsPrintConnector')->setMethods(array (
|
||||
'getCmdOutput',
|
||||
'getLocalPrinters'
|
||||
))->disableOriginalConstructor()->getMock();
|
||||
$stub->method('getCmdOutput')->willReturn("");
|
||||
$stub->method('getLocalPrinters')->willReturn($printers);
|
||||
$stub->__construct($path);
|
||||
return $stub;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
<?php
|
||||
use Mike42\Escpos\EscposImage;
|
||||
|
||||
class EscposImageTest extends PHPUnit\Framework\TestCase
|
||||
{
|
||||
public function testImageMissingException()
|
||||
{
|
||||
$this -> expectException(Exception::class);
|
||||
$img = EscposImage::load('not-a-real-file.png');
|
||||
}
|
||||
public function testImageNotSupportedException()
|
||||
{
|
||||
$this -> expectException(InvalidArgumentException::class);
|
||||
$img = EscposImage::load('/dev/null', false, array());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,197 @@
|
||||
<?php
|
||||
/**
|
||||
* Example strings are pangrams using different character sets, and are
|
||||
* testing correct code-table switching.
|
||||
*
|
||||
* When printed, they should appear the same as in this source file.
|
||||
*
|
||||
* Many of these test strings are from:
|
||||
* - http://www.cl.cam.ac.uk/~mgk25/ucs/examples/quickbrown.txt
|
||||
* - http://clagnut.com/blog/2380/ (mirrored from the English Wikipedia)
|
||||
*/
|
||||
use Mike42\Escpos\Printer;
|
||||
use Mike42\Escpos\PrintConnectors\DummyPrintConnector;
|
||||
|
||||
class EscposPrintBufferTest extends PHPUnit\Framework\TestCase
|
||||
{
|
||||
protected $buffer;
|
||||
protected $outputConnector;
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
$this -> outputConnector = new DummyPrintConnector();
|
||||
$printer = new Printer($this -> outputConnector);
|
||||
$this -> buffer = $printer -> getPrintBuffer();
|
||||
}
|
||||
|
||||
protected function checkOutput($expected = null)
|
||||
{
|
||||
/* Check those output strings */
|
||||
$outp = $this -> outputConnector -> getData();
|
||||
if ($expected === null) {
|
||||
echo "\nOutput was:\n\"" . friendlyBinary($outp) . "\"\n";
|
||||
}
|
||||
$this -> assertEquals($expected, $outp);
|
||||
}
|
||||
|
||||
protected function tearDown(): void
|
||||
{
|
||||
$this -> outputConnector -> finalize();
|
||||
}
|
||||
|
||||
public function testNotUtf8() {
|
||||
$this -> expectException(Exception::class);
|
||||
$this -> buffer -> writeText("Not valid UTF-8 can it be printed? \xc3\x28");
|
||||
}
|
||||
|
||||
public function testRawTextNonprintable()
|
||||
{
|
||||
$this -> buffer -> writeTextRaw("Test" . Printer::ESC . "v1\n");
|
||||
$this -> checkOutput("\x1b@Test?v1\x0a"); // ASCII ESC character is substituted for '?'
|
||||
}
|
||||
|
||||
public function testDanish()
|
||||
{
|
||||
$this -> buffer -> writeText("Quizdeltagerne spiste jordbær med fløde, mens cirkusklovnen Wolther spillede på xylofon.\n");
|
||||
$this -> checkOutput("\x1b@Quizdeltagerne spiste jordb\x91r med fl\x1bt\x02\x9bde, mens cirkusklovnen Wolther spillede p\x86 xylofon.\x0a");
|
||||
}
|
||||
|
||||
public function testGerman()
|
||||
{
|
||||
$this -> buffer -> writeText("Falsches Üben von Xylophonmusik quält jeden größeren Zwerg.\n");
|
||||
$this -> checkOutput("\x1b@Falsches \x9aben von Xylophonmusik qu\x84lt jeden gr\x94\xe1eren Zwerg.\x0a");
|
||||
}
|
||||
|
||||
public function testGreek()
|
||||
{
|
||||
$this -> buffer -> writeText("Ξεσκεπάζω την ψυχοφθόρα βδελυγμία");
|
||||
$this -> checkOutput("\x1b@\x1bt\x0e\x8d\x9c\xa9\xa1\x9c\xa7\xe1\x9d\xe0 \xab\x9e\xa4 \xaf\xac\xae\xa6\xad\x9f\xe6\xa8\x98 \x99\x9b\x9c\xa2\xac\x9a\xa3\xe5\x98");
|
||||
}
|
||||
|
||||
public function testGreekWithDiacritics()
|
||||
{
|
||||
// This is a string which is known to be un-printable in ESC/POS (the grave-accented letters are not in any code page),
|
||||
// so we are checking the substitution '?' for unknown characters.
|
||||
$this -> buffer -> writeText("Γαζέες καὶ μυρτιὲς δὲν θὰ βρῶ πιὰ στὸ χρυσαφὶ ξέφωτο.\n");
|
||||
$this -> checkOutput("\x1b@\xe2\xe0\x1bt\x0e\x9d\xe2\x9c\xaa \xa1\x98? \xa3\xac\xa8\xab\xa0?\xaa \x9b?\xa4 \x9f? \x99\xa8? \xa7\xa0? \xa9\xab? \xae\xa8\xac\xa9\x98\xad? \xa5\xe2\xad\xe0\xab\xa6.\x0a");
|
||||
}
|
||||
|
||||
public function testEnglish()
|
||||
{
|
||||
$this -> buffer -> writeText("The quick brown fox jumps over the lazy dog.\n");
|
||||
$this -> checkOutput("\x1b@The quick brown fox jumps over the lazy dog.\n");
|
||||
}
|
||||
|
||||
public function testSpanish()
|
||||
{
|
||||
// This one does not require changing code-pages at all, so characters are just converted from Unicode to CP437.
|
||||
$this -> buffer -> writeText("El pingüino Wenceslao hizo kilómetros bajo exhaustiva lluvia y frío, añoraba a su querido cachorro.\n");
|
||||
$this -> checkOutput("\x1b@El ping\x81ino Wenceslao hizo kil\xa2metros bajo exhaustiva lluvia y fr\xa1o, a\xa4oraba a su querido cachorro.\x0a");
|
||||
}
|
||||
|
||||
public function testFrench()
|
||||
{
|
||||
$this -> buffer -> writeText("Le cœur déçu mais l'âme plutôt naïve, Louÿs rêva de crapaüter en canoë au delà des îles, près du mälström où brûlent les novæ.\n");
|
||||
$this -> checkOutput("\x1b@Le c\x1bt\x10\x9cur d\xe9\xe7u mais l'\xe2me plut\xf4t na\xefve, Lou\xffs r\xeava de crapa\xfcter en cano\xeb au del\xe0 des \xeeles, pr\xe8s du m\xe4lstr\xf6m o\xf9 br\xfblent les nov\xe6.\x0a");
|
||||
}
|
||||
|
||||
public function testIrishGaelic()
|
||||
{
|
||||
// Note that some letters with diacritics cannot be printed for Irish Gaelic text, so text may need to be simplified.
|
||||
$this -> buffer -> writeText("D'fhuascail Íosa, Úrmhac na hÓighe Beannaithe, pór Éava agus Ádhaimh.\n");
|
||||
$this -> checkOutput("\x1b@D'fhuascail \x1bt\x02\xd6osa, \xe9rmhac na h\xe0ighe Beannaithe, p\xa2r \x90ava agus \xb5dhaimh.\x0a");
|
||||
}
|
||||
|
||||
public function testHungarian()
|
||||
{
|
||||
$this -> buffer -> writeText("Árvíztűrő tükörfúrógép.\n");
|
||||
$this -> checkOutput("\x1b@\x1bt\x02\xb5rv\xa1zt\x1bt\x12\xfbr\x8b t\x81k\x94rf\xa3r\xa2g\x82p.\x0a");
|
||||
}
|
||||
|
||||
public function testIcelandic()
|
||||
{
|
||||
$this -> buffer -> writeText("Kæmi ný öxi hér ykist þjófum nú bæði víl og ádrepa.");
|
||||
$this -> checkOutput("\x1b@K\x91mi n\x1bt\x02\xec \x94xi h\x82r ykist \xe7j\xa2fum n\xa3 b\x91\xd0i v\xa1l og \xa0drepa.");
|
||||
}
|
||||
|
||||
public function testJapaneseHiragana()
|
||||
{
|
||||
$this -> markTestIncomplete("Non-ASCII character sets not yet supported.");
|
||||
$this -> buffer -> writeText(implode("\n", array("いろはにほへとちりぬるを", " わかよたれそつねならむ", "うゐのおくやまけふこえて", "あさきゆめみしゑひもせす")) . "\n");
|
||||
$this -> checkOutput();
|
||||
}
|
||||
|
||||
public function testJapaneseKatakana()
|
||||
{
|
||||
$this -> markTestIncomplete("Non-ASCII character sets not yet supported.");
|
||||
$this -> buffer -> writeText(implode("\n", array("イロハニホヘト チリヌルヲ ワカヨタレソ ツネナラム", "ウヰノオクヤマ ケフコエテ アサキユメミシ ヱヒモセスン")) . "\n");
|
||||
$this -> checkOutput("\x1b@\x1bt\x01\xb2\xdb\xca\xc6\xce\xcd\xc4 \xc1\xd8\xc7\xd9\xa6 \xdc\xb6\xd6\xc0\xda\xbf \xc2\xc8\xc5\xd7\xd1\x0a\xb3\xb2\xc9\xb5\xb8\xd4\xcf \xb9\xcc\xba\xb4\xc3 \xb1\xbb\xb7\xd5\xd2\xd0\xbc \xb4\xcb\xd3\xbe\xbd\xdd\x0a");
|
||||
}
|
||||
|
||||
public function testJapaneseKataKanaHalfWidth()
|
||||
{
|
||||
$this -> buffer -> writeText(implode("\n", array("イロハニホヘト チリヌルヲ ワカヨタレソ ツネナラム", "ウイノオクヤマ ケフコエテ アサキユメミシ エヒモセスン")) . "\n");
|
||||
$this -> checkOutput("\x1b@\x1bt\x01\xb2\xdb\xca\xc6\xce\xcd\xc4 \xc1\xd8\xc7\xd9\xa6 \xdc\xb6\xd6\xc0\xda\xbf \xc2\xc8\xc5\xd7\xd1\x0a\xb3\xb2\xc9\xb5\xb8\xd4\xcf \xb9\xcc\xba\xb4\xc3 \xb1\xbb\xb7\xd5\xd2\xd0\xbc \xb4\xcb\xd3\xbe\xbd\xdd\x0a");
|
||||
}
|
||||
|
||||
public function testLatvian()
|
||||
{
|
||||
$this -> buffer -> writeText("Glāžšķūņa rūķīši dzērumā čiepj Baha koncertflīģeļu vākus.\n");
|
||||
$this -> checkOutput("\x1b@Gl\x1bt!\x83\xd8\xd5\xe9\xd7\xeca r\xd7\xe9\x8c\xd5i dz\x89rum\x83 \xd1iepj Baha koncertfl\x8c\x85e\xebu v\x83kus.\x0a");
|
||||
}
|
||||
|
||||
public function testPolish()
|
||||
{
|
||||
$this -> buffer -> writeText("Pchnąć w tę łódź jeża lub ośm skrzyń fig.\n");
|
||||
$this -> checkOutput("\x1b@Pchn\x1bt\x12\xa5\x86 w t\xa9 \x88\xa2d\xab je\xbea lub o\x98m skrzy\xe4 fig.\x0a");
|
||||
}
|
||||
|
||||
public function testRussian()
|
||||
{
|
||||
$this -> buffer -> writeText("В чащах юга жил бы цитрус? Да, но фальшивый экземпляр!\n");
|
||||
$this -> checkOutput("\x1b@\x1bt\x11\x82 \xe7\xa0\xe9\xa0\xe5 \xee\xa3\xa0 \xa6\xa8\xab \xa1\xeb \xe6\xa8\xe2\xe0\xe3\xe1? \x84\xa0, \xad\xae \xe4\xa0\xab\xec\xe8\xa8\xa2\xeb\xa9 \xed\xaa\xa7\xa5\xac\xaf\xab\xef\xe0!\x0a");
|
||||
}
|
||||
|
||||
public function testThai()
|
||||
{
|
||||
$this -> markTestIncomplete("Non-ASCII character sets not yet supported.");
|
||||
$this -> buffer -> writeText("นายสังฆภัณฑ์ เฮงพิทักษ์ฝั่ง ผู้เฒ่าซึ่งมีอาชีพเป็นฅนขายฃวด ถูกตำรวจปฏิบัติการจับฟ้องศาล ฐานลักนาฬิกาคุณหญิงฉัตรชฎา ฌานสมาธิ\n"); // Quotation from Wikipedia
|
||||
$this -> checkOutput();
|
||||
}
|
||||
|
||||
public function testTurkish()
|
||||
{
|
||||
$this -> buffer -> writeText("Pijamalı hasta, yağız şoföre çabucak güvendi.\n");
|
||||
$this -> checkOutput("\x1b@Pijamal\x1bt\x02\xd5 hasta, ya\x1bt\x0d\xa7\x8dz \x9fof\x94re \x87abucak g\x81vendi.\x0a");
|
||||
}
|
||||
|
||||
public function testArabic()
|
||||
{
|
||||
$this -> markTestIncomplete("Right-to-left text not yet supported.");
|
||||
$this -> buffer -> writeText("صِف خَلقَ خَودِ كَمِثلِ الشَمسِ إِذ بَزَغَت — يَحظى الضَجيعُ بِها نَجلاءَ مِعطارِ" . "\n"); // Quotation from Wikipedia
|
||||
$this -> checkOutput();
|
||||
}
|
||||
|
||||
public function testHebrew()
|
||||
{
|
||||
// RTL text is more complex than the above.
|
||||
$this -> markTestIncomplete("Right-to-left text not yet supported.");
|
||||
$this -> buffer -> writeText("דג סקרן שט בים מאוכזב ולפתע מצא לו חברה איך הקליטה" . "\n");
|
||||
$this -> checkOutput();
|
||||
}
|
||||
|
||||
public function testVietnamese() {
|
||||
$this -> buffer -> writeText("Tiếng Việt, còn gọi tiếng Việt Nam hay Việt ngữ, là ngôn ngữ của người Việt (người Kinh) và là ngôn ngữ chính thức tại Việt Nam.\n");
|
||||
$this -> checkOutput("\x1b@Ti\x1bt\x1e\xd5ng Vi\xd6t, c\xdfn g\xe4i ti\xd5ng Vi\xd6t Nam hay Vi\xd6t ng\xf7, l\xb5 ng\xabn ng\xf7 c\xf1a ng\xad\xeai Vi\xd6t (ng\xad\xeai Kinh) v\xb5 l\xb5 ng\xabn ng\xf7 ch\xddnh th\xf8c t\xb9i Vi\xd6t Nam.\x0a");
|
||||
}
|
||||
|
||||
public function testWindowsLineEndings() {
|
||||
$this -> buffer -> writeText("Hello World!\r\n");
|
||||
$this -> checkOutput("\x1b@Hello World!\x0a");
|
||||
}
|
||||
|
||||
public function testWindowsLineEndingsRaw() {
|
||||
$this -> buffer -> writeTextRaw("Hello World!\r\n");
|
||||
$this -> checkOutput("\x1b@Hello World!\x0a");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,49 @@
|
||||
<?php
|
||||
|
||||
namespace Mike42\Escpos\Experimental\Unifont;
|
||||
|
||||
use Mike42\Escpos\PrintConnectors\DummyPrintConnector;
|
||||
use Mike42\Escpos\Printer;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
class UnifontPrintBufferTest extends TestCase
|
||||
{
|
||||
protected $printer;
|
||||
protected $outputConnector;
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
$this -> outputConnector = new DummyPrintConnector();
|
||||
$this -> printer = new Printer($this -> outputConnector);
|
||||
$filename = tempnam(sys_get_temp_dir(), "escpos-php-");
|
||||
$glyphs = [
|
||||
"0020:00000000000000000000000000000000", // space is guessed
|
||||
"0041:0000000018242442427E424242420000" // Letter "A" from Wikipedia
|
||||
];
|
||||
file_put_contents($filename, implode("\n", $glyphs));
|
||||
$printBuffer = new UnifontPrintBuffer($filename);
|
||||
$this -> printer -> setPrintBuffer($printBuffer);
|
||||
}
|
||||
|
||||
protected function checkOutput($expected = null)
|
||||
{
|
||||
/* Check those output strings */
|
||||
$outp = $this -> outputConnector -> getData();
|
||||
if ($expected === null) {
|
||||
echo "\nOutput was:\n\"" . friendlyBinary($outp) . "\"\n";
|
||||
}
|
||||
$this -> assertEquals($expected, $outp);
|
||||
}
|
||||
|
||||
protected function tearDown(): void
|
||||
{
|
||||
$this -> outputConnector -> finalize();
|
||||
}
|
||||
|
||||
public function testString()
|
||||
{
|
||||
// Render the text "AA A" rendered via used-defined font.
|
||||
$this -> printer -> text("AA A\r\n");
|
||||
$this -> checkOutput("\x1b@\x1b!1\x1b%\x01\x1b&\x03 \x08\x00\x00\x00\x01\xfc\x00\x06@\x00\x08@\x00\x08@\x00\x06@\x00\x01\xfc\x00\x00\x00\x00 \x1b&\x03!!\x08\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00! \x0a");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
<?php
|
||||
use Mike42\Escpos\PrintConnectors\FilePrintConnector;
|
||||
|
||||
class FilePrintConnectorTest extends PHPUnit\Framework\TestCase
|
||||
{
|
||||
public function testTmpfile()
|
||||
{
|
||||
// Should attempt to send data to the local printer by writing to it
|
||||
$tmpfname = tempnam("/tmp", "php");
|
||||
$connector = new FilePrintConnector($tmpfname);
|
||||
$connector -> finalize();
|
||||
$connector -> finalize(); // Silently do nothing if printer already closed
|
||||
$this -> assertEquals("", file_get_contents($tmpfname));
|
||||
unlink($tmpfname);
|
||||
}
|
||||
|
||||
public function testReadAfterClose()
|
||||
{
|
||||
// Should attempt to send data to the local printer by writing to it
|
||||
$this -> expectException(Exception::class);
|
||||
$tmpfname = tempnam("/tmp", "php");
|
||||
$connector = new FilePrintConnector($tmpfname);
|
||||
$connector -> finalize();
|
||||
$connector -> write("Test");
|
||||
unlink($tmpfname);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,101 @@
|
||||
<?php
|
||||
use Mike42\Escpos\GdEscposImage;
|
||||
use Mike42\Escpos\EscposImage;
|
||||
|
||||
class GdEscposImageTest extends PHPUnit\Framework\TestCase
|
||||
{
|
||||
|
||||
/**
|
||||
* Gd tests - Load tiny images and check how they are printed
|
||||
* These are skipped if you don't have imagick
|
||||
*/
|
||||
public function testGdBadFilename()
|
||||
{
|
||||
$this -> expectException(Exception::class);
|
||||
$this -> loadAndCheckImg('not a real file.png', 1, 1, null, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* @medium
|
||||
*/
|
||||
public function testGdEmpty()
|
||||
{
|
||||
$this -> loadAndCheckImg(null, 0, 0, "", array());
|
||||
}
|
||||
|
||||
/**
|
||||
* @medium
|
||||
*/
|
||||
public function testGdBlack()
|
||||
{
|
||||
foreach (array('png', 'jpg', 'gif') as $format) {
|
||||
$this -> loadAndCheckImg('canvas_black.' . $format, 1, 1, "\x80", array("\x80"));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @medium
|
||||
*/
|
||||
public function testGdBlackTransparent()
|
||||
{
|
||||
foreach (array('png', 'gif') as $format) {
|
||||
$this -> loadAndCheckImg('black_transparent.' . $format, 2, 2, "\xc0\x00", array("\x80\x80"));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @medium
|
||||
*/
|
||||
public function testGdBlackWhite()
|
||||
{
|
||||
foreach (array('png', 'jpg', 'gif') as $format) {
|
||||
$this -> loadAndCheckImg('black_white.' . $format, 2, 2, "\xc0\x00", array("\x80\x80"));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @medium
|
||||
*/
|
||||
public function testGdWhite()
|
||||
{
|
||||
foreach (array('png', 'jpg', 'gif') as $format) {
|
||||
$this -> loadAndCheckImg('canvas_white.' . $format, 1, 1, "\x00", array("\x00"));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Load an EscposImage with (optionally) certain libraries disabled and run a check.
|
||||
*/
|
||||
private function loadAndCheckImg($fn, $width, $height, $rasterFormat = null, $columnFormat = null)
|
||||
{
|
||||
if (!EscposImage::isGdLoaded()) {
|
||||
$this -> markTestSkipped("gd plugin is required for this test");
|
||||
}
|
||||
$onDisk = ($fn === null ? null : (dirname(__FILE__) . "/resources/$fn"));
|
||||
// With optimisations
|
||||
$imgOptimised = new GdEscposImage($onDisk, true);
|
||||
$this -> checkImg($imgOptimised, $width, $height, $rasterFormat, $columnFormat);
|
||||
// ... and without
|
||||
$imgUnoptimised = new GdEscposImage($onDisk, false);
|
||||
$this -> checkImg($imgUnoptimised, $width, $height, $rasterFormat, $columnFormat);
|
||||
}
|
||||
|
||||
/**
|
||||
* Check image against known width, height, output.
|
||||
*/
|
||||
private function checkImg(EscposImage $img, $width, $height, $rasterFormatExpected = null, $columnFormatExpected = null)
|
||||
{
|
||||
$rasterFormatActual = $img -> toRasterFormat();
|
||||
$columnFormatActual = $img -> toColumnFormat();
|
||||
if ($rasterFormatExpected === null) {
|
||||
echo "\nImage was: " . $img -> getWidth() . "x" . $img -> getHeight() . ", raster data \"" . friendlyBinary($rasterFormatActual) . "\"";
|
||||
}
|
||||
if ($columnFormatExpected === null) {
|
||||
echo "\nImage was: " . $img -> getWidth() . "x" . $img -> getHeight() . ", column data \"" . friendlyBinary($columnFormatActual) . "\"";
|
||||
}
|
||||
$this -> assertTrue($img -> getHeight() == $height);
|
||||
$this -> assertTrue($img -> getWidth() == $width);
|
||||
$this -> assertTrue($rasterFormatExpected === $rasterFormatActual);
|
||||
$this -> assertTrue($columnFormatExpected === $columnFormatActual);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,148 @@
|
||||
<?php
|
||||
use Mike42\Escpos\ImagickEscposImage;
|
||||
use Mike42\Escpos\EscposImage;
|
||||
|
||||
class ImagickEscposImageTest extends PHPUnit\Framework\TestCase
|
||||
{
|
||||
|
||||
/**
|
||||
* Imagick tests - Load tiny images and check how they are printed
|
||||
* These are skipped if you don't have imagick
|
||||
*/
|
||||
public function testImagickBadFilename()
|
||||
{
|
||||
$this -> expectException(Exception::class);
|
||||
$this -> loadAndCheckImg('not a real file.png', 1, 1, null, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* @medium
|
||||
*/
|
||||
public function testImagickEmpty()
|
||||
{
|
||||
$this -> loadAndCheckImg(null, 0, 0, "", array());
|
||||
}
|
||||
|
||||
/**
|
||||
* @medium
|
||||
*/
|
||||
public function testImagickBlack()
|
||||
{
|
||||
foreach (array('png', 'jpg', 'gif') as $format) {
|
||||
$this -> loadAndCheckImg('canvas_black.' . $format, 1, 1, "\x80", array("\x80"));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @medium
|
||||
*/
|
||||
public function testImagickBlackTransparent()
|
||||
{
|
||||
foreach (array('png', 'gif') as $format) {
|
||||
$this -> loadAndCheckImg('black_transparent.' . $format, 2, 2, "\xc0\x00", array("\x80\x80"));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @medium
|
||||
*/
|
||||
public function testImagickBlackWhite()
|
||||
{
|
||||
foreach (array('png', 'jpg', 'gif') as $format) {
|
||||
$this -> loadAndCheckImg('black_white.' . $format, 2, 2, "\xc0\x00", array("\x80\x80"));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @medium
|
||||
*/
|
||||
public function testImagickBlackWhiteTall()
|
||||
{
|
||||
// We're very interested in correct column format chopping here at 8 pixels
|
||||
$this -> loadAndCheckImg('black_white_tall.png', 2, 16,
|
||||
"\xc0\xc0\xc0\xc0\xc0\xc0\xc0\xc0\x00\x00\x00\x00\x00\x00\x00\x00", array("\xff\xff", "\x00\x00"));
|
||||
}
|
||||
|
||||
/**
|
||||
* @medium
|
||||
*/
|
||||
public function testImagickWhite()
|
||||
{
|
||||
foreach (array('png', 'jpg', 'gif') as $format) {
|
||||
$this -> loadAndCheckImg('canvas_white.' . $format, 1, 1, "\x00", array("\x00"));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* PDF test - load tiny PDF and check for well-formedness
|
||||
* These are also skipped if you don't have imagick
|
||||
* @medium
|
||||
*/
|
||||
public function testPdfAllPages()
|
||||
{
|
||||
// This is expected to fail on many distributions with an error, due to GhostScript defaults.
|
||||
// 'Exception: not authorized `/path/to/doc.pdf' @error/constitute.c/ReadImage/412'
|
||||
// The defaults were changed to prevent a vulnerability (arbitrary code execution), and can be bypassed if you
|
||||
// trust the source of PDF files.
|
||||
// https://stackoverflow.com/a/52661288/1808534
|
||||
$this -> markTestSkipped('unsupported feature');
|
||||
$this -> loadAndCheckPdf('doc.pdf', 1, 1, array("\x00", "\x80"), array(array("\x00"), array("\x80")));
|
||||
}
|
||||
|
||||
public function testPdfBadFilename()
|
||||
{
|
||||
$this -> expectException(Exception::class);
|
||||
$this -> loadAndCheckPdf('not a real file', 1, 1, array(), array());
|
||||
}
|
||||
|
||||
/**
|
||||
* Load an EscposImage and run a check.
|
||||
*/
|
||||
private function loadAndCheckImg($fn, $width, $height, $rasterFormat = null, $columnFormat = null)
|
||||
{
|
||||
if (!EscposImage::isImagickLoaded()) {
|
||||
$this -> markTestSkipped("imagick plugin is required for this test");
|
||||
}
|
||||
$onDisk = ($fn === null ? null : (dirname(__FILE__) . "/resources/$fn"));
|
||||
// With optimisations
|
||||
$imgOptimised = new ImagickEscposImage($onDisk, true);
|
||||
$this -> checkImg($imgOptimised, $width, $height, $rasterFormat, $columnFormat);
|
||||
// ... and without
|
||||
$imgUnoptimised = new ImagickEscposImage($onDisk, false);
|
||||
$this -> checkImg($imgUnoptimised, $width, $height, $rasterFormat, $columnFormat);
|
||||
}
|
||||
|
||||
/**
|
||||
* Same as above, loading document and checking pages against some expected values.
|
||||
*/
|
||||
private function loadAndCheckPdf($fn, $width, $height, array $rasterFormat = null, array $columnFormat = null)
|
||||
{
|
||||
if (!EscposImage::isImagickLoaded()) {
|
||||
$this -> markTestSkipped("imagick plugin required for this test");
|
||||
}
|
||||
$pdfPages = ImagickEscposImage::loadPdf(dirname(__FILE__) . "/resources/$fn", $width);
|
||||
$this -> assertTrue(count($pdfPages) == count($rasterFormat), "Got back wrong number of pages");
|
||||
foreach ($pdfPages as $id => $img) {
|
||||
$this -> checkImg($img, $width, $height, $rasterFormat[$id], $columnFormat[$id]);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Check image against known width, height, output.
|
||||
*/
|
||||
private function checkImg(EscposImage $img, $width, $height, $rasterFormatExpected = null, $columnFormatExpected = null)
|
||||
{
|
||||
$rasterFormatActual = $img -> toRasterFormat();
|
||||
$columnFormatActual = $img -> toColumnFormat();
|
||||
if ($rasterFormatExpected === null) {
|
||||
echo "\nImage was: " . $img -> getWidth() . "x" . $img -> getHeight() . ", raster data \"" . friendlyBinary($rasterFormatActual) . "\"";
|
||||
}
|
||||
if ($columnFormatExpected === null) {
|
||||
echo "\nImage was: " . $img -> getWidth() . "x" . $img -> getHeight() . ", column data \"" . friendlyBinary($columnFormatActual) . "\"";
|
||||
}
|
||||
$this -> assertEquals($height , $img -> getHeight());
|
||||
$this -> assertEquals($width, $img -> getWidth());
|
||||
$this -> assertEquals($rasterFormatExpected, $rasterFormatActual, "Raster format did not match expected");
|
||||
$this -> assertEquals($columnFormatExpected, $columnFormatActual, "Column format did not match expected");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
<?php
|
||||
|
||||
use Mike42\Escpos\PrintConnectors\DummyPrintConnector;
|
||||
use Mike42\Escpos\PrintConnectors\MultiplePrintConnector;
|
||||
use Mike42\Escpos\Printer;
|
||||
|
||||
class MultiplePrintConnectorTest extends PHPUnit\Framework\TestCase
|
||||
{
|
||||
public function testOnePrinter()
|
||||
{
|
||||
// Set up connector which goes to multiple printers
|
||||
$kitchenPrinter = new DummyPrintConnector();
|
||||
$barPrinter = new DummyPrintConnector();
|
||||
$connector = new MultiplePrintConnector($kitchenPrinter, $barPrinter);
|
||||
// Print something
|
||||
$printer = new Printer($connector);
|
||||
$printer->text("Hello World\n");
|
||||
$printer->cut();
|
||||
// Get data out and close the printer
|
||||
$kitchenText = $kitchenPrinter->getData();
|
||||
$barText = $barPrinter->getData();
|
||||
$printer->close();
|
||||
// Should have matching prints to each printer
|
||||
$this->assertEquals("\x1b@Hello World\x0a\x1dVA\x03", $kitchenText);
|
||||
$this->assertEquals("\x1b@Hello World\x0a\x1dVA\x03", $barText);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,99 @@
|
||||
<?php
|
||||
use Mike42\Escpos\NativeEscposImage;
|
||||
use Mike42\Escpos\EscposImage;
|
||||
|
||||
class NativeEscposImageTest extends PHPUnit\Framework\TestCase
|
||||
{
|
||||
/**
|
||||
* Native tests - Load tiny images and check how they are printed
|
||||
* These are skipped if you don't have Native
|
||||
*/
|
||||
public function testBadFilename()
|
||||
{
|
||||
$this -> expectException(Exception::class);
|
||||
$this -> loadAndCheckImg('not a real file.png', 1, 1, null, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* @medium
|
||||
*/
|
||||
public function testBlack()
|
||||
{
|
||||
foreach (array('bmp', 'gif', 'png') as $format) {
|
||||
$this -> loadAndCheckImg('canvas_black.' . $format, 1, 1, "\x80", array("\x80"));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @medium
|
||||
*/
|
||||
public function testBlackTransparent()
|
||||
{
|
||||
foreach (array('gif', 'png') as $format) {
|
||||
$this -> loadAndCheckImg('black_transparent.' . $format, 2, 2, "\xc0\x00", array("\x80\x80"));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @medium
|
||||
*/
|
||||
public function testBlackWhite()
|
||||
{
|
||||
foreach (array('bmp', 'png', 'gif') as $format) {
|
||||
$this -> loadAndCheckImg('black_white.' . $format, 2, 2, "\xc0\x00", array("\x80\x80"));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @medium
|
||||
*/
|
||||
public function testBlackWhiteTall()
|
||||
{
|
||||
// We're very interested in correct column format chopping here at 8 pixels
|
||||
$this -> loadAndCheckImg('black_white_tall.png', 2, 16,
|
||||
"\xc0\xc0\xc0\xc0\xc0\xc0\xc0\xc0\x00\x00\x00\x00\x00\x00\x00\x00", array("\xff\xff", "\x00\x00"));
|
||||
}
|
||||
|
||||
/**
|
||||
* @medium
|
||||
*/
|
||||
public function testWhite()
|
||||
{
|
||||
foreach (array('bmp', 'png', 'gif') as $format) {
|
||||
$this -> loadAndCheckImg('canvas_white.' . $format, 1, 1, "\x00", array("\x00"));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Load an EscposImage and run a check.
|
||||
*/
|
||||
private function loadAndCheckImg($fn, $width, $height, $rasterFormat = null, $columnFormat = null)
|
||||
{
|
||||
$onDisk = ($fn === null ? null : (dirname(__FILE__) . "/resources/$fn"));
|
||||
// With optimisations
|
||||
$imgOptimised = new NativeEscposImage($onDisk, true);
|
||||
$this -> checkImg($imgOptimised, $width, $height, $rasterFormat, $columnFormat);
|
||||
// ... and without
|
||||
$imgUnoptimised = new NativeEscposImage($onDisk, false);
|
||||
$this -> checkImg($imgUnoptimised, $width, $height, $rasterFormat, $columnFormat);
|
||||
}
|
||||
|
||||
/**
|
||||
* Check image against known width, height, output.
|
||||
*/
|
||||
private function checkImg(EscposImage $img, $width, $height, $rasterFormatExpected = null, $columnFormatExpected = null)
|
||||
{
|
||||
$rasterFormatActual = $img -> toRasterFormat();
|
||||
$columnFormatActual = $img -> toColumnFormat();
|
||||
if ($rasterFormatExpected === null) {
|
||||
echo "\nImage was: " . $img -> getWidth() . "x" . $img -> getHeight() . ", raster data \"" . friendlyBinary($rasterFormatActual) . "\"";
|
||||
}
|
||||
if ($columnFormatExpected === null) {
|
||||
echo "\nImage was: " . $img -> getWidth() . "x" . $img -> getHeight() . ", column data \"" . friendlyBinary($columnFormatActual) . "\"";
|
||||
}
|
||||
$this -> assertEquals($height , $img -> getHeight());
|
||||
$this -> assertEquals($width, $img -> getWidth());
|
||||
$this -> assertEquals($rasterFormatExpected, $rasterFormatActual, "Raster format did not match expected");
|
||||
$this -> assertEquals($columnFormatExpected, $columnFormatActual, "Column format did not match expected");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,52 @@
|
||||
<?php
|
||||
use Mike42\Escpos\PrintConnectors\UriPrintConnector;
|
||||
use PHPUnit\Framework\Error\Notice;
|
||||
|
||||
class UriPrintConnectorTest extends PHPUnit\Framework\TestCase
|
||||
{
|
||||
public function testFile()
|
||||
{
|
||||
$filename = tempnam(sys_get_temp_dir(), "escpos-php-");
|
||||
// Make connector, write some data
|
||||
$connector = UriPrintConnector::get("file://" . $filename);
|
||||
$connector -> write("AAA");
|
||||
$connector -> finalize();
|
||||
$this -> assertEquals("AAA", file_get_contents($filename));
|
||||
$this -> assertEquals('Mike42\Escpos\PrintConnectors\FilePrintConnector', get_class($connector));
|
||||
unlink($filename);
|
||||
}
|
||||
|
||||
public function testSmb()
|
||||
{
|
||||
$this->expectNotice();
|
||||
$this->expectNoticeMessage("not finalized");
|
||||
$connector = UriPrintConnector::get("smb://windows/printer");
|
||||
$this -> assertEquals('Mike42\Escpos\PrintConnectors\WindowsPrintConnector', get_class($connector));
|
||||
// We expect that this will throw an exception, we can't
|
||||
// realistically print to a real printer in this test though... :)
|
||||
$connector -> __destruct();
|
||||
}
|
||||
|
||||
public function testBadUri()
|
||||
{
|
||||
$this->expectException(InvalidArgumentException::class);
|
||||
$this->expectExceptionMessage("Malformed connector URI");
|
||||
$connector = UriPrintConnector::get("foooooo");
|
||||
}
|
||||
|
||||
public function testNetwork()
|
||||
{
|
||||
$this->expectExceptionMessage("Connection refused");
|
||||
$this->expectException(Exception::class);
|
||||
// Port should be closed so we can catch an error and move on
|
||||
$connector = UriPrintConnector::get("tcp://localhost:45987/");
|
||||
}
|
||||
|
||||
public function testUnsupportedUri()
|
||||
{
|
||||
$this->expectExceptionMessage("URI sheme is not supported: ldap://");
|
||||
$this->expectException(InvalidArgumentException::class);
|
||||
// Try to print to something silly
|
||||
$connector = UriPrintConnector::get("ldap://host:1234/");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,304 @@
|
||||
<?php
|
||||
use Mike42\Escpos\PrintConnectors\WindowsPrintConnector;
|
||||
|
||||
class WindowsPrintConnectorTest extends PHPUnit\Framework\TestCase
|
||||
{
|
||||
private $connector;
|
||||
|
||||
public function testLptWindows()
|
||||
{
|
||||
// Should attempt to send data to the local printer by writing to it
|
||||
$connector = $this -> getMockConnector("LPT1", WindowsPrintConnector::PLATFORM_WIN);
|
||||
$connector -> expects($this -> once())
|
||||
-> method('runWrite')
|
||||
-> with($this -> equalTo(''), $this -> equalTo("LPT1"));
|
||||
$connector -> expects($this -> exactly(0))
|
||||
-> method('runCommand');
|
||||
$connector -> expects($this -> exactly(0))
|
||||
-> method('runCopy');
|
||||
$connector -> finalize();
|
||||
}
|
||||
|
||||
public function testLptMac()
|
||||
{
|
||||
// Cannot print to local printer on Mac with this connector
|
||||
$this -> expectException(BadMethodCallException::class);
|
||||
$connector = $this -> getMockConnector("LPT1", WindowsPrintConnector::PLATFORM_MAC);
|
||||
$connector -> expects($this -> exactly(0))
|
||||
-> method('runWrite');
|
||||
$connector -> expects($this -> exactly(0))
|
||||
-> method('runCommand');
|
||||
$connector -> expects($this -> exactly(0))
|
||||
-> method('runCopy');
|
||||
$connector -> finalize();
|
||||
}
|
||||
|
||||
public function testLptLinux()
|
||||
{
|
||||
// Cannot print to local printer on Linux with this connector
|
||||
$this -> expectException(BadMethodCallException::class);
|
||||
$connector = $this -> getMockConnector("LPT1", WindowsPrintConnector::PLATFORM_LINUX);
|
||||
$connector -> expects($this -> exactly(0))
|
||||
-> method('runWrite');
|
||||
$connector -> expects($this -> exactly(0))
|
||||
-> method('runCommand');
|
||||
$connector -> expects($this -> exactly(0))
|
||||
-> method('runCopy');
|
||||
$connector -> finalize();
|
||||
}
|
||||
|
||||
public function testComWindows()
|
||||
{
|
||||
// Simple file write
|
||||
$connector = $this -> getMockConnector("COM1", WindowsPrintConnector::PLATFORM_WIN);
|
||||
$connector -> expects($this -> once())
|
||||
-> method('runWrite')
|
||||
-> with($this -> equalTo(''), $this -> equalTo("COM1"));
|
||||
$connector -> expects($this -> exactly(0))
|
||||
-> method('runCommand');
|
||||
$connector -> expects($this -> exactly(0))
|
||||
-> method('runCopy');
|
||||
$connector -> finalize();
|
||||
}
|
||||
|
||||
public function testComMac()
|
||||
{
|
||||
// Cannot print to local printer on Mac with this connector
|
||||
$this -> expectException(BadMethodCallException::class);
|
||||
$connector = $this -> getMockConnector("COM1", WindowsPrintConnector::PLATFORM_MAC);
|
||||
$connector -> expects($this -> exactly(0))
|
||||
-> method('runWrite');
|
||||
$connector -> expects($this -> exactly(0))
|
||||
-> method('runCommand');
|
||||
$connector -> expects($this -> exactly(0))
|
||||
-> method('runCopy');
|
||||
$connector -> finalize();
|
||||
}
|
||||
|
||||
public function testComLinux()
|
||||
{
|
||||
// Cannot print to local printer on Linux with this connector
|
||||
$this -> expectException(BadMethodCallException::class);
|
||||
$connector = $this -> getMockConnector("COM1", WindowsPrintConnector::PLATFORM_LINUX);
|
||||
$connector -> expects($this -> exactly(0))
|
||||
-> method('runWrite');
|
||||
$connector -> expects($this -> exactly(0))
|
||||
-> method('runCommand');
|
||||
$connector -> expects($this -> exactly(0))
|
||||
-> method('runCopy');
|
||||
$connector -> finalize();
|
||||
}
|
||||
|
||||
public function testLocalShareWindows()
|
||||
{
|
||||
$connector = $this -> getMockConnector("Printer", WindowsPrintConnector::PLATFORM_WIN);
|
||||
$connector -> expects($this -> exactly(0))
|
||||
-> method('runCommand');
|
||||
$connector -> expects($this -> exactly(0))
|
||||
-> method('runWrite');
|
||||
$connector -> expects($this -> once())
|
||||
-> method('runCopy')
|
||||
-> with($this -> anything(), $this -> stringContains('\\Printer'));
|
||||
$connector -> finalize();
|
||||
}
|
||||
|
||||
public function testSharedPrinterWindows()
|
||||
{
|
||||
$connector = $this -> getMockConnector("smb://example-pc/Printer", WindowsPrintConnector::PLATFORM_WIN);
|
||||
$connector -> expects($this -> exactly(0))
|
||||
-> method('runCommand');
|
||||
$connector -> expects($this -> exactly(0))
|
||||
-> method('runWrite');
|
||||
$connector -> expects($this -> once())
|
||||
-> method('runCopy')
|
||||
-> with($this -> anything(), $this -> equalTo('\\\\example-pc\\Printer'));
|
||||
$connector -> finalize();
|
||||
}
|
||||
|
||||
public function testSharedPrinterWindowsUsername()
|
||||
{
|
||||
$connector = $this -> getMockConnector("smb://bob@example-pc/Printer", WindowsPrintConnector::PLATFORM_WIN);
|
||||
$connector -> expects($this -> once())
|
||||
-> method('runCommand')
|
||||
-> with($this -> equalTo('net use \'\\\\example-pc\\Printer\' \'/user:bob\''));
|
||||
$connector -> expects($this -> exactly(0))
|
||||
-> method('runWrite');
|
||||
$connector -> expects($this -> once())
|
||||
-> method('runCopy')
|
||||
-> with($this -> anything(), $this -> equalTo('\\\\example-pc\\Printer'));
|
||||
$connector -> finalize();
|
||||
}
|
||||
|
||||
public function testSharedPrinterWindowsUsernameDomain()
|
||||
{
|
||||
$connector = $this -> getMockConnector("smb://bob@example-pc/home/Printer", WindowsPrintConnector::PLATFORM_WIN);
|
||||
$connector -> expects($this -> once())
|
||||
-> method('runCommand')
|
||||
-> with($this -> equalTo('net use \'\\\\example-pc\\Printer\' \'/user:home\\bob\''));
|
||||
$connector -> expects($this -> exactly(0))
|
||||
-> method('runWrite');
|
||||
$connector -> expects($this -> once())
|
||||
-> method('runCopy')
|
||||
-> with($this -> anything(), $this -> equalTo('\\\\example-pc\\Printer'));
|
||||
$connector -> finalize();
|
||||
}
|
||||
|
||||
public function testSharedPrinterWindowsUsernamePassword()
|
||||
{
|
||||
$connector = $this -> getMockConnector("smb://bob:secret@example-pc/Printer", WindowsPrintConnector::PLATFORM_WIN);
|
||||
$connector -> expects($this -> once())
|
||||
-> method('runCommand')
|
||||
-> with($this -> equalTo('net use \'\\\\example-pc\\Printer\' \'/user:bob\' \'secret\''));
|
||||
$connector -> expects($this -> exactly(0))
|
||||
-> method('runWrite');
|
||||
$connector -> expects($this -> once())
|
||||
-> method('runCopy')
|
||||
-> with($this -> anything(), $this -> equalTo('\\\\example-pc\\Printer'));
|
||||
$connector -> finalize();
|
||||
}
|
||||
|
||||
public function testSharedPrinterMac()
|
||||
{
|
||||
// Not implemented
|
||||
$this -> expectException(Exception::class);
|
||||
$connector = $this -> getMockConnector("smb://Guest@example-pc/Printer", WindowsPrintConnector::PLATFORM_MAC);
|
||||
$connector -> expects($this -> exactly(0))
|
||||
-> method('runWrite');
|
||||
$connector -> expects($this -> exactly(0))
|
||||
-> method('runCommand');
|
||||
$connector -> expects($this -> exactly(0))
|
||||
-> method('runCopy');
|
||||
$connector -> finalize();
|
||||
}
|
||||
|
||||
public function testSharedPrinterLinux()
|
||||
{
|
||||
$connector = $this -> getMockConnector("smb://example-pc/Printer", WindowsPrintConnector::PLATFORM_LINUX);
|
||||
$connector -> expects($this -> once())
|
||||
-> method('runCommand')
|
||||
-> with($this -> equalTo('smbclient \'//example-pc/Printer\' -c \'print -\' -N -m SMB2'));
|
||||
$connector -> expects($this -> exactly(0))
|
||||
-> method('runCopy');
|
||||
$connector -> expects($this -> exactly(0))
|
||||
-> method('runWrite');
|
||||
$connector -> finalize();
|
||||
}
|
||||
|
||||
public function testSharedPrinterLinuxUsername()
|
||||
{
|
||||
$connector = $this -> getMockConnector("smb://bob@example-pc/Printer", WindowsPrintConnector::PLATFORM_LINUX);
|
||||
$connector -> expects($this -> once())
|
||||
-> method('runCommand')
|
||||
-> with($this -> equalTo('smbclient \'//example-pc/Printer\' -U \'bob\' -c \'print -\' -N -m SMB2'));
|
||||
$connector -> expects($this -> exactly(0))
|
||||
-> method('runCopy');
|
||||
$connector -> expects($this -> exactly(0))
|
||||
-> method('runWrite');
|
||||
$connector -> finalize();
|
||||
}
|
||||
|
||||
public function testSharedPrinterLinuxUsernameDomain()
|
||||
{
|
||||
$connector = $this -> getMockConnector("smb://bob@example-pc/home/Printer", WindowsPrintConnector::PLATFORM_LINUX);
|
||||
$connector -> expects($this -> once())
|
||||
-> method('runCommand')
|
||||
-> with($this -> equalTo('smbclient \'//example-pc/Printer\' -U \'home\\bob\' -c \'print -\' -N -m SMB2'));
|
||||
$connector -> expects($this -> exactly(0))
|
||||
-> method('runCopy');
|
||||
$connector -> expects($this -> exactly(0))
|
||||
-> method('runWrite');
|
||||
$connector -> finalize();
|
||||
}
|
||||
|
||||
public function testSharedPrinterLinuxUsernamePassword()
|
||||
{
|
||||
$connector = $this -> getMockConnector("smb://bob:secret@example-pc/Printer", WindowsPrintConnector::PLATFORM_LINUX);
|
||||
$connector -> expects($this -> once())
|
||||
-> method('runCommand')
|
||||
-> with($this -> equalTo('smbclient \'//example-pc/Printer\' \'secret\' -U \'bob\' -c \'print -\' -m SMB2'));
|
||||
$connector -> expects($this -> exactly(0))
|
||||
-> method('runCopy');
|
||||
$connector -> expects($this -> exactly(0))
|
||||
-> method('runWrite');
|
||||
$connector -> finalize();
|
||||
}
|
||||
|
||||
private function getMockConnector($path, $platform)
|
||||
{
|
||||
$stub = $this -> getMockBuilder('Mike42\Escpos\PrintConnectors\WindowsPrintConnector')
|
||||
-> setMethods(array('runCopy', 'runCommand', 'getCurrentPlatform', 'runWrite'))
|
||||
-> disableOriginalConstructor()
|
||||
-> getMock();
|
||||
$stub -> method('runCommand')
|
||||
-> willReturn(0);
|
||||
$stub -> method('runCopy')
|
||||
-> willReturn(true);
|
||||
$stub -> method('runWrite')
|
||||
-> willReturn(true);
|
||||
$stub -> method('getCurrentPlatform')
|
||||
-> willReturn($platform);
|
||||
$stub -> __construct($path);
|
||||
return $stub;
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for correct identification of bogus or non-supported Samba strings.
|
||||
*/
|
||||
public function testSambaRegex()
|
||||
{
|
||||
$good = array("smb://foo/bar",
|
||||
"smb://foo/bar baz",
|
||||
"smb://bob@foo/bar",
|
||||
"smb://bob:secret@foo/bar",
|
||||
"smb://foo-computer/FooPrinter",
|
||||
"smb://foo-computer/workgroup/FooPrinter",
|
||||
"smb://foo-computer/Foo-Printer",
|
||||
"smb://foo-computer/workgroup/Foo-Printer",
|
||||
"smb://foo-computer/Foo Printer",
|
||||
"smb://foo-computer.local/Foo Printer",
|
||||
"smb://127.0.0.1/abcd"
|
||||
);
|
||||
$bad = array("",
|
||||
"http://google.com",
|
||||
"smb:/foo/bar",
|
||||
"smb://",
|
||||
"smb:///bar",
|
||||
"smb://@foo/bar",
|
||||
"smb://bob:@foo/bar",
|
||||
"smb://:secret@foo/bar",
|
||||
"smb://foo/bar/baz/quux",
|
||||
"smb://foo-computer//FooPrinter");
|
||||
foreach ($good as $item) {
|
||||
$this -> assertTrue(preg_match(WindowsPrintConnector::REGEX_SMB, $item) == 1, "Windows samba regex should pass '$item'.");
|
||||
}
|
||||
foreach ($bad as $item) {
|
||||
$this -> assertTrue(preg_match(WindowsPrintConnector::REGEX_SMB, $item) != 1, "Windows samba regex should fail '$item'.");
|
||||
}
|
||||
}
|
||||
|
||||
public function testPrinterNameRegex()
|
||||
{
|
||||
$good = array("a",
|
||||
"ab",
|
||||
"a b",
|
||||
"a-b",
|
||||
"Abcd Efg-",
|
||||
"-a",
|
||||
"OK1"
|
||||
);
|
||||
$bad = array("",
|
||||
" ",
|
||||
"a ",
|
||||
" a",
|
||||
" a ",
|
||||
"a/B",
|
||||
"A:b"
|
||||
);
|
||||
foreach ($good as $item) {
|
||||
$this -> assertTrue(preg_match(WindowsPrintConnector::REGEX_PRINTERNAME, $item) == 1, "Windows printer name regex should pass '$item'.");
|
||||
}
|
||||
foreach ($bad as $item) {
|
||||
$this -> assertTrue(preg_match(WindowsPrintConnector::REGEX_PRINTERNAME, $item) != 1, "Windows printer name regex should fail '$item'.");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
After Width: | Height: | Size: 65 B |
|
After Width: | Height: | Size: 167 B |
|
After Width: | Height: | Size: 138 B |
|
After Width: | Height: | Size: 65 B |
|
After Width: | Height: | Size: 175 B |
|
After Width: | Height: | Size: 156 B |
|
After Width: | Height: | Size: 162 B |
|
After Width: | Height: | Size: 142 B |
|
After Width: | Height: | Size: 72 B |
|
After Width: | Height: | Size: 160 B |
|
After Width: | Height: | Size: 239 B |
|
After Width: | Height: | Size: 142 B |
|
After Width: | Height: | Size: 72 B |
|
After Width: | Height: | Size: 160 B |
|
After Width: | Height: | Size: 239 B |
@@ -0,0 +1,18 @@
|
||||
<?php
|
||||
$im = new Imagick();
|
||||
try {
|
||||
$im -> readImage("doc.pdf[5]");
|
||||
$im -> destroy();
|
||||
} catch (ImagickException $e) {
|
||||
echo "Error: " . $e -> getMessage() . "\n";
|
||||
}
|
||||
|
||||
$im = new Imagick();
|
||||
try {
|
||||
ob_start();
|
||||
@$im -> readImage("doc.pdf[5]");
|
||||
ob_end_clean();
|
||||
$im -> destroy();
|
||||
} catch (ImagickException $e) {
|
||||
echo "Error: " . $e -> getMessage() . "\n";
|
||||
}
|
||||