PHP5產生條碼的簡單一實例_PHP教程

來源:互聯網
上載者:User
該軟體支援PHP4和PHP5兩個版本,本文中使用的是PHP5的版本。在使用前注意要將PHP的GD模組開啟。在Windows中為php_gd2.dll,Linux中為gd.so。將壓縮檔解壓到Apache,執行http://localhost/barcode/index.php。PHP5產生條碼見:

1. Type:選擇條碼類型

2. Output:輸出的圖片格式

3. Thickness:條碼高度

4. Resolution:條碼大小

5. Font:條碼下方的文字大小,也可不顯示文字

6. Text:條碼列印的內容

498)this.width=498;' onmousewheel = 'javascript:return big(this)' alt=條碼效果 src="http://www.bkjia.com/uploadfile/2013/0904/20130904094617982.jpg" width=615 height=557>

當然,這個PHP5產生條碼程式只是將文字產生為條碼,但使用時不能靈活將其嵌入其他PHP程式,我將壓縮包裡面的test.php做了一些調整,使其能靈活的用於其他程式。運行時只需將條碼類型和文字傳給test.php即可,例如:
http://localhost/barcode/test.php?codebar=BCGcode39&text=20090729

或運行 http://localhost/barcode/mytest.php

mytest.php代碼:

  
  1. <img src="test.php?codebar=BCGcode39&text=20090729">
PHP5產生條碼:

498)this.width=498;' onmousewheel = 'javascript:return big(this)' alt=運行執行個體 src="http://www.bkjia.com/uploadfile/2013/0904/20130904094617379.jpg" width=665 height=186>

PHP5產生條碼test.php代碼:

  
  1. // Including all required classes
  2. require('class/BCGFont.php');
  3. require('class/BCGColor.php');
  4. require('class/BCGDrawing.php');
  5. /*'BCGcodabar','BCGcode11','BCGcode39','BCGcode39extended','BCGcode93',
  6. 'BCGcode128','BCGean8','BCGean13','BCGisbn','BCGi25','BCGs25','BCGmsi',
  7. 'BCGupca','BCGupce','BCGupcext2','BCGupcext5','BCGpostnet','BCGothercode'*/
  8. $codebar = $_REQUEST['codebar']; //該軟體支援的所有編碼,只需調整$codebar參數即可。
  9. // Including the barcode technology
  10. include('class/'.$codebar.'.barcode.php');
  11. // Loading Font
  12. $font = new BCGFont('./class/font/Arial.ttf', 10);
  13. // The arguments are R, G, B for color.
  14. $color_black = new BCGColor(0, 0, 0);
  15. $color_white = new BCGColor(255, 255, 255);
  16. $code = new $codebar();
  17. $code->setScale(2); // Resolution
  18. $code->setThickness(30); // Thickness
  19. $code->setForegroundColor($color_black); // Color of bars
  20. $code->setBackgroundColor($color_white); // Color of spaces
  21. $code->setFont($font); // Font (or 0)
  22. $text = $_REQUEST['text']; //PHP5產生條碼將要資料的內容
  23. $code->parse($text);
  24. /* Here is the list of the arguments
  25. 1 - Filename (empty : display on screen)
  26. 2 - Background color */
  27. $drawing = new BCGDrawing('', $color_white);
  28. $drawing->setBarcode($code);
  29. $drawing->draw();
  30. // Header that says it is an image (remove it if you save the barcode to a file)
  31. header('Content-Type: image/png');
  32. // Draw (or save) the image into PNG format.
  33. $drawing->finish(BCGDrawing::IMG_FORMAT_PNG);
  34. ?>
在運行過程中出現異常";
throw $e; //重擲異常
}
}
?﹥


http://www.bkjia.com/PHPjc/446609.htmlwww.bkjia.comtruehttp://www.bkjia.com/PHPjc/446609.htmlTechArticle該軟體支援PHP4和PHP5兩個版本,本文中使用的是PHP5的版本。在使用前注意要將PHP的GD模組開啟。在Windows中為php_gd2.dll,Linux中為gd.so。將壓縮...

  • 聯繫我們

    該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

    如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.