BarCodeTest.php 4.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. <?php
  2. namespace Test\CpChart;
  3. use Codeception\Test\Unit;
  4. use CpChart\Barcode\Barcode128;
  5. use CpChart\Barcode\Barcode39;
  6. use CpChart\Image;
  7. use UnitTester;
  8. class BarCodeTest extends Unit
  9. {
  10. /**
  11. * @var UnitTester
  12. */
  13. protected $tester;
  14. public function test39Code()
  15. {
  16. $image = new Image(700,230);
  17. $settings = ["R" => 170, "G" => 183, "B" => 87, "Dash" => 1, "DashR" => 190, "DashG" => 203, "DashB" => 107];
  18. $image->drawFilledRectangle(0, 0, 700, 230, $settings);
  19. $settings = ["StartR" => 219, "StartG" => 231, "StartB" => 139, "EndR" => 1, "EndG" => 138, "EndB" => 68, "Alpha" => 50];
  20. $image->drawGradientArea(0, 0, 700, 230, DIRECTION_VERTICAL, $settings);
  21. $image->drawGradientArea(0, 0, 700, 20, DIRECTION_VERTICAL, ["StartR" => 0, "StartG" => 0, "StartB" => 0, "EndR" => 50, "EndG" => 50, "EndB" => 50, "Alpha" => 80]);
  22. $image->drawRectangle(0, 0, 699, 229, ["R" => 0, "G" => 0, "B" => 0]);
  23. $image->setFontProperties(["FontName" => "Silkscreen.ttf", "FontSize" => 6]);
  24. $image->drawText(10, 13, "Barcode 39 - Add barcode to your pictures", ["R" => 255, "G" => 255, "B" => 255]);
  25. $barcode = new Barcode39();
  26. $image->setFontProperties(["FontName" => "pf_arma_five.ttf", "FontSize" => 6]);
  27. $settings = ["ShowLegend" => true, "DrawArea" => true];
  28. $barcode->draw($image, "pChart Rocks!", 50, 50, $settings);
  29. $image->setFontProperties(["FontName" => "Forgotte.ttf", "FontSize" => 12]);
  30. $settings = ["ShowLegend" => true, "DrawArea" => true, "Angle" => 90];
  31. $barcode->draw($image, "Turn me on", 650, 50, $settings);
  32. $image->setFontProperties(["FontName" => "Forgotte.ttf", "FontSize" => 12]);
  33. $settings = ["R" => 255, "G" => 255, "B" => 255, "AreaR" => 150, "AreaG" => 30, "AreaB" => 27, "ShowLegend" => true, "DrawArea" => true, "Angle" => 350, "AreaBorderR" => 70, "AreaBorderG" => 20, "AreaBorderB" => 20];
  34. $barcode->draw($image, "Do what you want !", 290, 140, $settings);
  35. $filename = $this->tester->getOutputPathForChart('drawBarcode39.png');
  36. $barcode->pChartObject->render($filename);
  37. $barcode->pChartObject->stroke();
  38. $this->tester->seeFileFound($filename);
  39. }
  40. public function test128Code()
  41. {
  42. $image = new Image(700, 230);
  43. $settings = ["R" => 170, "G" => 183, "B" => 87, "Dash" => 1, "DashR" => 190, "DashG" => 203, "DashB" => 107];
  44. $image->drawFilledRectangle(0, 0, 700, 230, $settings);
  45. $settings = ["StartR" => 219, "StartG" => 231, "StartB" => 139, "EndR" => 1, "EndG" => 138, "EndB" => 68, "Alpha" => 50];
  46. $image->drawGradientArea(0, 0, 700, 230, DIRECTION_VERTICAL, $settings);
  47. $image->drawGradientArea(0, 0, 700, 20, DIRECTION_VERTICAL, ["StartR" => 0, "StartG" => 0, "StartB" => 0, "EndR" => 50, "EndG" => 50, "EndB" => 50, "Alpha" => 80]);
  48. $image->drawGradientArea(0, 0, 700, 20, DIRECTION_VERTICAL, ["StartR" => 0, "StartG" => 0, "StartB" => 0, "EndR" => 50, "EndG" => 50, "EndB" => 50, "Alpha" => 100]);
  49. $image->drawRectangle(0, 0, 699, 229, ["R" => 0, "G" => 0, "B" => 0]);
  50. $image->setFontProperties(["FontName" => "Silkscreen.ttf", "FontSize" => 6]);
  51. $image->drawText(10, 13, "Barcode 128 - Add barcode to your pictures", ["R" => 255, "G" => 255, "B" => 255]);
  52. $barcode = new Barcode128();
  53. $image->setFontProperties(["FontName" => "pf_arma_five.ttf", "FontSize" => 6]);
  54. $settings = ["ShowLegend" => true, "DrawArea" => true];
  55. $barcode->draw($image, "pChart Rocks!", 50, 50, $settings);
  56. $image->setFontProperties(["FontName" => "Forgotte.ttf", "FontSize" => 12]);
  57. $settings = ["ShowLegend" => true, "DrawArea" => true, "Angle" => 90];
  58. $barcode->draw($image, "Turn me on", 650, 50, $settings);
  59. $image->setFontProperties(["FontName" => "Forgotte.ttf", "FontSize" => 12]);
  60. $settings = ["R" => 255, "G" => 255, "B" => 255, "AreaR" => 150, "AreaG" => 30, "AreaB" => 27, "ShowLegend" => true, "DrawArea" => true, "Angle" => 350, "AreaBorderR" => 70, "AreaBorderG" => 20, "AreaBorderB" => 20];
  61. $barcode->draw($image, "Do what you want !", 290, 140, $settings);
  62. $filename = $this->tester->getOutputPathForChart('drawBarcode128.png');
  63. $barcode->pChartObject->render($filename);
  64. $barcode->pChartObject->stroke();
  65. $this->tester->seeFileFound($filename);
  66. }
  67. }