Click here to Skip to main content
15,881,967 members
Home / Discussions / Linux, Apache, MySQL, PHP
   

Linux, Apache, MySQL, PHP

 
GeneralRe: IDE Pin
N a v a n e e t h9-Nov-09 15:39
N a v a n e e t h9-Nov-09 15:39 
AnswerRe: IDE Pin
Iranian MM7-Sep-11 9:38
Iranian MM7-Sep-11 9:38 
GeneralRe: IDE Pin
__erfan__7-Sep-11 18:55
__erfan__7-Sep-11 18:55 
Questionhow to link a php code to mysql database Pin
Akinsanya Oyinkan6-Nov-09 20:17
Akinsanya Oyinkan6-Nov-09 20:17 
AnswerRe: how to link a php code to mysql database Pin
Marc Firth8-Nov-09 21:57
Marc Firth8-Nov-09 21:57 
AnswerRe: how to link a php code to mysql database Pin
DmiNi8-Mar-10 9:21
DmiNi8-Mar-10 9:21 
Questionput skype and yahoomessenger nick into website Pin
sharkbc5-Nov-09 1:09
sharkbc5-Nov-09 1:09 
QuestionBarCode 128 generated via PHP and GD library Pin
cjoki4-Nov-09 12:21
cjoki4-Nov-09 12:21 
Hello all,


I am working on a php script to generate an image with the barcode 128 B (I will not be using the A or C).

I have it displaying a barcode in firefox. When I print it it looks close to one generanted by a barcode application. The diference is that mine is slightly longer. Anyways given the same string the app generate code scans and mine does not. I believe everything is in order...but I must be missing something simple here...suggestions?

This is the hash_code_128.php script referenced in the main script. The source for the codes came from wikipedia http://en.wikipedia.org/wiki/Code_128[^]

<?php
	$b_chr = array();	// character lookup
	$b_enc = array();	// encoding lookup
	$stop = "11000111010";
	$term_bar = "11";
	$b_chr['00'] = " ";
	$b_chr['01'] = "!";
	$b_chr['02'] = '"';
	$b_chr['03'] = "#";
	$b_chr['04'] = "$";
	$b_chr['05'] = "%";
	$b_chr['06'] = "&";
	$b_chr['07'] = "'";
	$b_chr['08'] = "(";
	$b_chr['09'] = ")";
	$b_chr['10'] = "*";
	$b_chr['11'] = "+";
	$b_chr['12'] = ",";
	$b_chr['13'] = "-";
	$b_chr['14'] = ".";
	$b_chr['15'] = "/";
	$b_chr['16'] = "0";
	$b_chr['17'] = "1";
	$b_chr['18'] = "2";
	$b_chr['19'] = "3";
	$b_chr['20'] = "4";
	$b_chr['21'] = "5";
	$b_chr['22'] = "6";
	$b_chr['23'] = "7";
	$b_chr['24'] = "8";
	$b_chr['25'] = "9";
	$b_chr['26'] = ":";
	$b_chr['27'] = ";";
	$b_chr['28'] = "<";
	$b_chr['29'] = "=";
	$b_chr['30'] = ">";
	$b_chr['31'] = "?";
	$b_chr['32'] = "@";
	$b_chr['33'] = "A";
	$b_chr['34'] = "B";
	$b_chr['35'] = "C";
	$b_chr['36'] = "D";
	$b_chr['37'] = "E";
	$b_chr['38'] = "F";
	$b_chr['39'] = "G";
	$b_chr['40'] = "H";
	$b_chr['41'] = "I";
	$b_chr['42'] = "J";
	$b_chr['43'] = "K";
	$b_chr['44'] = "L";
	$b_chr['45'] = "M";
	$b_chr['46'] = "N";
	$b_chr['47'] = "O";
	$b_chr['48'] = "P";
	$b_chr['49'] = "Q";
	$b_chr['50'] = "R";
	$b_chr['51'] = "S";
	$b_chr['52'] = "T";
	$b_chr['53'] = "U";
	$b_chr['54'] = "V";
	$b_chr['55'] = "W";
	$b_chr['56'] = "X";
	$b_chr['57'] = "Y";
	$b_chr['58'] = "Z";
	$b_chr['59'] = "[";
	$b_chr['60'] = "\\";
	$b_chr['61'] = "]";
	$b_chr['62'] = "^";
	$b_chr['63'] = "_";
	$b_chr['64'] = "`";
	$b_chr['65'] = "a";
	$b_chr['66'] = "b";
	$b_chr['67'] = "c";
	$b_chr['68'] = "d";
	$b_chr['69'] = "e";
	$b_chr['70'] = "f";
	$b_chr['71'] = "g";
	$b_chr['72'] = "h";
	$b_chr['73'] = "i";
	$b_chr['74'] = "j";
	$b_chr['75'] = "k";
	$b_chr['76'] = "l";
	$b_chr['77'] = "m";
	$b_chr['78'] = "n";
	$b_chr['79'] = "o";
	$b_chr['80'] = "p";
	$b_chr['81'] = "q";
	$b_chr['82'] = "r";
	$b_chr['83'] = "s";
	$b_chr['84'] = "t";
	$b_chr['85'] = "u";
	$b_chr['86'] = "v";
	$b_chr['87'] = "w";
	$b_chr['88'] = "x";
	$b_chr['89'] = "y";
	$b_chr['90'] = "z";
	$b_chr['91'] = "{";
	$b_chr['92'] = "|";
	$b_chr['93'] = "}";
	$b_chr['94'] = "~";
	$b_chr['95'] = "DEL";
	$b_chr['96'] = "FNC3";
	$b_chr['97'] = "FNC2";
	$b_chr['98'] = "SHIFT";
	$b_chr['99'] = "Code C";
	$b_chr['100'] = "FNC4";
	$b_chr['101'] = "Code A";
	$b_chr['102'] = "FNC1";
	$b_chr['103'] = "START A";
	$b_chr['104'] = "START B";
	$b_chr['105'] = "START C";
	
	
	$b_enc['00'] = "11011001100";
	$b_enc['01'] = "11001101100";
	$b_enc['02'] = "11001100110";
	$b_enc['03'] = "10010011000";
	$b_enc['04'] = "10010001100";
	$b_enc['05'] = "10001001100";
	$b_enc['06'] = "10011001000";
	$b_enc['07'] = "10011000100";
	$b_enc['08'] = "10001100100";
	$b_enc['09'] = "11001001000";
	$b_enc['10'] = "11001000100";
	$b_enc['11'] = "11000100100";
	$b_enc['12'] = "10110011100";
	$b_enc['13'] = "10011011100";
	$b_enc['14'] = "10011001110";
	$b_enc['15'] = "10111001100";
	$b_enc['16'] = "10011101100";
	$b_enc['17'] = "10011100110";
	$b_enc['18'] = "11001110010";
	$b_enc['19'] = "11001011100";
	$b_enc['20'] = "11001001110";
	$b_enc['21'] = "11011100100";
	$b_enc['22'] = "11001110100";
	$b_enc['23'] = "11101101110";
	$b_enc['24'] = "11101001100";
	$b_enc['25'] = "11100101100";
	$b_enc['26'] = "11100100110";
	$b_enc['27'] = "11101100100";
	$b_enc['28'] = "11100110100";
	$b_enc['29'] = "11100110010";
	$b_enc['30'] = "11011011000";
	$b_enc['31'] = "11011000110";
	$b_enc['32'] = "11000110110";
	$b_enc['33'] = "10100011000";
	$b_enc['34'] = "10001011000";
	$b_enc['35'] = "10001000110";
	$b_enc['36'] = "10110001000";
	$b_enc['37'] = "10001101000";
	$b_enc['38'] = "10001100010";
	$b_enc['39'] = "11010001000";
	$b_enc['40'] = "11000101000";
	$b_enc['41'] = "11000100010";
	$b_enc['42'] = "10110111000";
	$b_enc['43'] = "10110001110";
	$b_enc['44'] = "10001101110";
	$b_enc['45'] = "10111011000";
	$b_enc['46'] = "10111000110";
	$b_enc['47'] = "10001110110";
	$b_enc['48'] = "11101110110";
	$b_enc['49'] = "11010001110";
	$b_enc['50'] = "11000101110";
	$b_enc['51'] = "11011101000";
	$b_enc['52'] = "11011100010";
	$b_enc['53'] = "11011101110";
	$b_enc['54'] = "11101011000";
	$b_enc['55'] = "11101000110";
	$b_enc['56'] = "11100010110";
	$b_enc['57'] = "11101101000";
	$b_enc['58'] = "11101100010";
	$b_enc['59'] = "11100011010";
	$b_enc['60'] = "11101111010";
	$b_enc['61'] = "11001000010";
	$b_enc['62'] = "11110001010";
	$b_enc['63'] = "10100110000";
	$b_enc['64'] = "10100001100";
	$b_enc['65'] = "10010110000";
	$b_enc['66'] = "10010000110";
	$b_enc['67'] = "10000101100";
	$b_enc['68'] = "10000100110";
	$b_enc['69'] = "10110010000";
	$b_enc['70'] = "10110000100";
	$b_enc['71'] = "10011010000";
	$b_enc['72'] = "10011000010";
	$b_enc['73'] = "10000110100";
	$b_enc['74'] = "10000110010";
	$b_enc['75'] = "11000010010";
	$b_enc['76'] = "11001010000";
	$b_enc['77'] = "11110111010";
	$b_enc['78'] = "11000010100";
	$b_enc['79'] = "10001111010";
	$b_enc['80'] = "10100111100";
	$b_enc['81'] = "10010111100";
	$b_enc['82'] = "10010011110";
	$b_enc['83'] = "10111100100";
	$b_enc['84'] = "10011110100";
	$b_enc['85'] = "10011110010";
	$b_enc['86'] = "11110100100";
	$b_enc['87'] = "11110010100";
	$b_enc['88'] = "11110010010";
	$b_enc['89'] = "11011011110";
	$b_enc['90'] = "11011110110";
	$b_enc['91'] = "11110110110";
	$b_enc['92'] = "10101111000";
	$b_enc['93'] = "10100011110";
	$b_enc['94'] = "10001011110";
	$b_enc['95'] = "10111101000";
	$b_enc['96'] = "10111100010";
	$b_enc['97'] = "11110101000";
	$b_enc['98'] = "11110100010";
	$b_enc['99'] = "10111011110";
	$b_enc['100'] = "10111101110";
	$b_enc['101'] = "11101011110";
	$b_enc['102'] = "11110101110";
	$b_enc['103'] = "11010000100";
	$b_enc['104'] = "11010010000";
	$b_enc['105'] = "11010011100";
?>


This is the main code page it is called from another page using a html img tags src attribute, like <img src='gen_code_128b.php?string=BarCode 1&size=2&height=50'>

<?php
	/*
		This is a program to generate a code 128B barcode and returns an image.
		
		Chris J, 2009-11-04
	*/
	
	
	$string=urldecode($_GET['string']);
	$size=urldecode($_GET['size']);
	$height=urldecode($_GET['height']);
	
	// $string is string to convert to bar code
		
	// $size is the pixel width of the bar code and is used as a base unit for each barcode/space
	// based on the # of 0's or 1's in a row.
	// for example the stop bar code hash is 11000111010. This is drawn as a bar 2 units wide, a space 3 units wide, a bar 
	// 3 units wide, a space 1 unit wide, a bar 1 unit wide followed by a space 1 unit wide. If the size is equal to 3 (for 3 pixels)
	//	this will mean the barcode for the stop is bar 6 pixels, space 9 pixels, bar 9 pixels, space 3 pixels, bar 3 pixels and space
	// 3 pixels. The entire code will messure 33 pixels in width. of course that is just for the stop (the end of the code 128 barcode).
	
	// $height is the height of the barcode in pixels. There must be room for for some padding on the top and bottom and room for
	// the text of $string to be printed just under the barcode.
	
	// at the front and back of a code 128 barcode is a blank space called the quiet zone. It should be 10 times the unit ($size in my function)
	include('hash_code_128.php');
	$bcstring = '';
	$cnt = strlen($string) ;
	
	$quiet_zone 	= 10*$size-1;
	$pad_top 			= 5;
	$pad_text 		= 3;
	$font_size 		= 5;
	$pad_bottom 	= 5;
	$font_left 		= $quiet_zone;
	$font_top 		= $pad_text + $height; 
	$ttl_width		= ($quiet_zone*2)+($size*($cnt+3)*11)+2; // include string length + start + stop + checksum + front and back quiet zones
	$ttl_height		= $pad_top + $pad_text + $font_size + $pad_bottom + $height; 
	
	$running_checksum = 104; // START B hardcoded...
	$bcstring.=$b_enc['104'];
	// build the barcode
	for($i=0;$i<$cnt;$i++)
	{
		$position = $i+1;
		$key = array_search($string[$i],$b_chr,true);
		$bcstring.=$b_enc[$key];
		$running_checksum+=($position*$key);
	}
	$checksum = $running_checksum%103;
	$bcstring.=$b_enc[$checksum].$stop.$term_bar;

	
	header ('Content-type: image/png');
	$im = @imagecreatetruecolor($ttl_width, $ttl_height) or die('Cannot Initialize new GD image stream');
	$white = imagecolorallocate($im, 255, 255, 255);
	$black = imagecolorallocate($im, 0, 0, 0);
	
	imagefill($im, 0, 0, $white);
	
	$start_x = 0;
	$stop_x = 1;
	$last_char = '0';
	$bc_cnt = strlen($bcstring);
	
	for($i=0;$i<$bc_cnt;$i++)
	{
		if($bcstring[$i]==1 && $bcstring[$i]!=$last_char)
		{
			// starting new bar
			$start_x = $quiet_zone+($i*$size);
		}
		if($bcstring[$i]==1 && $bcstring[$i]==$last_char)
		{
			// continuing new bar
			$stop_x++;
		}
		if($bcstring[$i]==0 && $bcstring[$i]!=$last_char)
		{
			// stopping new bar
			// bool imagefilledrectangle  ( resource $image  , int $x1  , int $y1  , int $x2  , int $y2  , int $color  )
			imagefilledrectangle($im, $start_x, $pad_top, $start_x+($stop_x*$size)-1, $height, $black);
			$stop_x = 1;
		}
		$last_char = $bcstring[$i];
	}
	// bool imagestring  ( resource $image  , int $font  , int $x  , int $y  , string $string  , int $color  )
	//imagestring($im, 3, $font_left, $font_top, $bcstring, $black);
	imagestring($im, 3, $font_left, $font_top, $string, $black);
	imagepng($im);
	imagedestroy($im);
?>

AnswerRe: BarCode 128 generated via PHP and GD library Pin
Marc Firth4-Nov-09 23:58
Marc Firth4-Nov-09 23:58 
AnswerRe: BarCode 128 generated via PHP and GD library Pin
cjoki5-Nov-09 5:38
cjoki5-Nov-09 5:38 
AnswerRe: BarCode 128 generated via PHP and GD library Pin
Spadino7012-May-11 21:28
Spadino7012-May-11 21:28 
GeneralRe: BarCode 128 generated via PHP and GD library Pin
cjoki13-May-11 8:24
cjoki13-May-11 8:24 
Questioninstall exe files Pin
messages31-Oct-09 4:01
messages31-Oct-09 4:01 
AnswerRe: install exe files Pin
khomeyni4-Nov-09 6:39
khomeyni4-Nov-09 6:39 
Questiontime and using linux app Pin
khomeyni30-Oct-09 2:32
khomeyni30-Oct-09 2:32 
AnswerRe: time and using linux app Pin
Mon R. Santos16-Nov-09 18:00
Mon R. Santos16-Nov-09 18:00 
GeneralRe: time and using linux app Pin
khomeyni17-Nov-09 8:31
khomeyni17-Nov-09 8:31 
GeneralRe: time and using linux app Pin
Mon R. Santos17-Nov-09 16:20
Mon R. Santos17-Nov-09 16:20 
GeneralRe: time and using linux app Pin
khomeyni18-Nov-09 0:25
khomeyni18-Nov-09 0:25 
GeneralRe: time and using linux app Pin
Mon R. Santos18-Nov-09 10:51
Mon R. Santos18-Nov-09 10:51 
GeneralRe: time and using linux app Pin
khomeyni26-Nov-09 7:11
khomeyni26-Nov-09 7:11 
GeneralRe: time and using linux app Pin
Rob9-Dec-09 8:19
Rob9-Dec-09 8:19 
GeneralRe: time and using linux app Pin
khomeyni10-Dec-09 7:56
khomeyni10-Dec-09 7:56 
GeneralRe: time and using linux app Pin
Rob11-Dec-09 4:13
Rob11-Dec-09 4:13 
GeneralRe: time and using linux app Pin
khomeyni11-Dec-09 8:29
khomeyni11-Dec-09 8:29 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.