2010-01-19 115 views
9

我需要一個能夠生成條形碼圖像文件的類,最好與最常見的標準兼容。PHP條碼圖像生成器

我在尋找基於個人經驗的建議/建議。

非常感謝

回答

2

如果你仍然在尋找解決方案,我已經與this(適應ASP.NET版本)合作,它生成的EAN代碼沒有問題。

+0

它不是免費的用於商業用途。 – SAMPro 2014-01-28 07:48:00

8

這裏是產生barocdes一個簡單的PHP腳本:

<?php 
//For displaying barcodes 

//Arguments are: 
// code Number you want outputted as a barcode 

//You can use this script in two ways: 
// From a webpage/PHP script <img src='/images/barcode.php?code=12345'/> 
// Directly in your web browser http://www.example.com/images/barcode.php?code=12345 

//Outputs the code as a barcode, surrounded by an asterisk (as per standard) 
//Will only output numbers, text will appear as gaps 
//Image width is dynamic, depending on how much data there is 

//Get the barcode font (called 'free3of9') from here http://www.barcodesinc.com/free-barcode-font/ 

header("Content-type: image/png"); 
$file = "images/barcode.png"; // path to base png image 
$im = imagecreatefrompng($file); // open the blank image 
$string = $_GET['code']; // get the code from URL 
imagealphablending($im, true); // set alpha blending on 
imagesavealpha($im, true); // save alphablending setting (important) 

$black = imagecolorallocate($im, 0, 0, 0); // colour of barcode 

$font_height=40; // barcode font size. anything smaller and it will appear jumbled and will not be able to be read by scanners 

$newwidth=((strlen($string)*20)+41); // allocate width of barcode. each character is 20px across, plus add in the asterisk's 
$thumb = imagecreatetruecolor($newwidth, 40); // generate a new image with correct dimensions 

imagecopyresized($thumb, $im, 0, 0, 0, 0, $newwidth, 40, 10, 10); // copy image to thumb 
imagettftext($thumb, $font_height, 0, 1, 40, $black, 'c:\windows\fonts\free3of9.ttf', '*'.$string.'*'); // add text to image 

//show the image 
imagepng($thumb); 
imagedestroy($thumb); 
?> 

希望這有助於你。

+1

我正在開發一個簡單的機票條碼掃描項目。你知道所有的手持掃描儀是否會讀回相同的號碼嗎? ps:我還沒有手持掃描儀。 – alex 2013-01-28 13:27:02

+0

@alex本答案引用字體'3的9'。 3或9,或代碼39,是一個廣泛接受的條碼標準,幾乎可以通過任何條碼掃描儀閱讀。所有掃描儀將讀取相同的值。 – BinaryTox1n 2013-02-07 17:25:40

+0

如果我們需要將圖像保存在光盤中,在某個文件夾中,那麼我們可以稍後獲取對它的引用? – 2015-04-20 21:39:13

1

這裏有一個免費的圖書館,有php類,jQuery插件和原型插件。它也有很好的 很好的例子visit