Advertisement
contatowellington

Untitled

May 9th, 2019
123
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.27 KB | None | 0 0
  1. <?php
  2. /**
  3. @author: Raj Trivedi (India), 2009-10-14
  4. @modify: Taylor Lopes (Brazil), 2012-04-06
  5. */
  6. class barCodeGenrator {
  7. private $file;
  8. private $into;
  9. private $digitArray = array(0=>"00110",1=>"10001",2=>"01001",3=>"11000",4=>"00101",5=>"10100",6=>"01100",7=>"00011",8=>"10010",9=>"01010");
  10. function __construct($value,$into=1, $filename = 'barcode.gif', $width_bar=300, $height_bar=65, $show_codebar=false) {
  11.  
  12. $lower = 1 ; $hight = 50;
  13. $this->into = $into;
  14. $this->file = $filename;
  15. for($count1=9;$count1>=0;$count1--){
  16. for($count2=9;$count2>=0;$count2--){
  17. $count = ($count1 * 10) + $count2 ;
  18. $text = "" ;
  19. for($i=1;$i<6;$i++){
  20. $text .= substr($this->digitArray[$count1],($i-1),1) . substr($this->digitArray[$count2],($i-1),1);
  21. }
  22. $this->digitArray[$count] = $text;
  23. }
  24. }
  25.  
  26.  
  27. $height_bar_max = $height_bar;
  28. $width_bar_max = $width_bar;
  29.  
  30. $img = imagecreate($width_bar_max,$height_bar_max);
  31. if ($show_codebar) {
  32. $height_bar -= 25;
  33. }
  34.  
  35. $cl_black = imagecolorallocate($img, 0, 0, 0);
  36. $cl_white = imagecolorallocate($img, 255, 255, 255);
  37.  
  38. #imagefilledrectangle($img, 0, 0, $lower*95+1000, $hight+300, $cl_white);
  39. imagefilledrectangle($img, 0, 0, $width_bar_max, $height_bar_max, $cl_white);
  40. imagefilledrectangle($img, 5,5,5,$height_bar,$cl_black);
  41. imagefilledrectangle($img, 6,5,6,$height_bar,$cl_white);
  42. imagefilledrectangle($img, 7,5,7,$height_bar,$cl_black);
  43. imagefilledrectangle($img, 8,5,8,$height_bar,$cl_white);
  44. $thin = 1 ;
  45. if(substr_count(strtoupper($_SERVER['SERVER_SOFTWARE']),"WIN32")){
  46. $wide = 3;
  47. } else {
  48. $wide = 2.72;
  49. }
  50. $pos = 9 ;
  51. $text = $value ;
  52. if((strlen($text) % 2) <> 0){
  53. $text = "0" . $text;
  54. }
  55.  
  56.  
  57. while (strlen($text) > 0) {
  58. $i = round($this->JSK_left($text,2));
  59. $text = $this->JSK_right($text,strlen($text)-2);
  60.  
  61. $f = $this->digitArray[$i];
  62.  
  63. for($i=1;$i<11;$i+=2){
  64. if (substr($f,($i-1),1) == "0") {
  65. $f1 = $thin ;
  66. }else{
  67. $f1 = $wide ;
  68. }
  69. imagefilledrectangle($img, $pos,5,$pos-1+$f1,$height_bar,$cl_black) ;
  70. $pos = $pos + $f1 ;
  71.  
  72. if (substr($f,$i,1) == "0") {
  73. $f2 = $thin ;
  74. }else{
  75. $f2 = $wide ;
  76. }
  77. imagefilledrectangle($img, $pos,5,$pos-1+$f2,$height_bar,$cl_white) ;
  78. $pos = $pos + $f2 ;
  79. }
  80. }
  81. imagefilledrectangle($img, $pos,5,$pos-1+$wide,$height_bar,$cl_black);
  82. $pos=$pos+$wide;
  83.  
  84. imagefilledrectangle($img, $pos,5,$pos-1+$thin,$height_bar,$cl_white);
  85. $pos=$pos+$thin;
  86.  
  87.  
  88. imagefilledrectangle($img, $pos,5,$pos-1+$thin,$height_bar,$cl_black);
  89. $pos=$pos+$thin;
  90.  
  91. if ($show_codebar) {
  92. imagestring($img, 5, 0, $height_bar+5, " ".$value, imagecolorallocate($img, 0, 0, 0));
  93. }
  94.  
  95. $this->put_img($img);
  96. }
  97.  
  98. function JSK_left($input,$comp){
  99. return substr($input,0,$comp);
  100. }
  101.  
  102. function JSK_right($input,$comp){
  103. return substr($input,strlen($input)-$comp,$comp);
  104. }
  105. function put_img($image,$file='test.gif'){
  106. if($this->into){
  107. imagegif($image,$this->file);
  108. } else {
  109. header("Content-type: image/gif");
  110. imagegif($image);
  111. }
  112. imagedestroy($image);
  113. }
  114. }
  115.  
  116. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement