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

Linux, Apache, MySQL, PHP

 
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 
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 
Hello cjoki,
I try to explain, but not very practical with English (I'm Italian) and I just started with php ...

I am trying your code but you probably have not entered correctly the last few lines of code that you posted, because the barcode is almost always correct but sometimes lack a little bit. Here how I use it, if you can help me.

Thanks

<?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;
  
  $checksum = $checksum + 32;
  $checksum2 = chr($checksum);
  $key = array_search($checksum2,$b_chr,true);
  $bcstring.=$b_enc[$key].$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;
		}
    //pezzo aggiunto
		$last_char = $bcstring[$i];
    if($bcstring[$i]==0 && $bcstring[$i]!=$last_char || $i == $bc_cnt-1){
      // 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;
    }
	}
	// 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, "", $black);
	imagepng($im);
	imagedestroy($im);
?>

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 
GeneralRe: time and using linux app Pin
Rob14-Dec-09 5:33
Rob14-Dec-09 5:33 
GeneralRe: time and using linux app Pin
khomeyni14-Dec-09 19:46
khomeyni14-Dec-09 19:46 
Questionwhat is wrong that i get this error with nasm Pin
Aljaz11128-Oct-09 4:07
Aljaz11128-Oct-09 4:07 

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.