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

Linux, Apache, MySQL, PHP

 
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 
GeneralRe: BarCode 128 generated via PHP and GD library Pin
cjoki13-May-11 8:24
cjoki13-May-11 8:24 
here is the full code that is in production still. maybe this will help. cjoki

<?php
	/*
		This is a program to generate a code 128B barcode and returns an image.
		
		Chris J, 2009-11-04
	*/
	function gen_code128($string, $fid, $size = 1, $height = 50, $show_text = true)
	{
	
		// $string is string to convert to bar code
		
		// $fid is the filename, it will default to the $string if no is provided
		
		// $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)
		
		// the $show_text parameter determines if a string will display under the barcode, this string will be the text version of the barcode.
		
		include('hash_code_128.php');
		$bcstring = '';
		$cnt = strlen($string) ;
		
		$quiet_zone 	= 10*$size-1;
		$pad_top 			= 5;
		$pad_bottom 	= 5;
		$ttl_width		= ($quiet_zone*2)+($size*($cnt+3)*11)+2; // include string length + start + stop + checksum + front and back quiet zones
		
		if($show_text)
		{
			$pad_text 		= 3;
			$font_size 		= 5;
			$font_left 		= $quiet_zone;
			$font_top 		= $pad_text + $height; 
			$ttl_height		= $pad_top + $pad_text + $font_size + $pad_bottom + $height;
		}
		else
		{
			$ttl_height		= $pad_top + $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);
			//	echo "<p>pos: ".$position."<br>char: ".$string[$i]."<br>key: ".$key."<br>bcstring: ".$bcstring."<br>run checksum: ".$running_checksum."</p>";
		}
		
		$checksum = $running_checksum%103;
		/*
			Important!!!!
			--------------
			if the checksum is over 94 just send the raw value down to make the key.
			if it is under 95 add 32 and grab the ascii character to lookup the key of the hash array for that character.
		*/
		if($checksum<95)
		{
			$checksum = $checksum + 32;
			$checksum2 = chr($checksum);
			$key = array_search($checksum2,$b_chr,true);
		}
		else
		{
			$key = $checksum;
		}
		//echo "<p>key: ".$key."<br></p>";
		$bcstring.=$b_enc[$key].$stop.$term_bar;
		
		// header ('Content-type: image/jpeg'); <-- only need when send the image back to the browser directly.
		// we will be saving the image, via the string sent.
		$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);
		
		$current_pos = $quiet_zone;
		$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 || $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;
			}
			$last_char = $bcstring[$i];
		}
		// bool imagestring( resource $image  , int $font  , int $x  , int $y  , string $string  , int $color  )
		$filename = '';
		if($show_text)
		{
			imagestring($im, 3, $font_left, $font_top, $string, $black);
		}
		//echo $_SERVER['SERVER_NAME']."\n";
		if($_SERVER['SERVER_NAME']=='localhost')
		{
			$filename = $fid.".jpg";
		}
		else
		{
			$filename = "/var/www/barcodes/".$fid.".jpg";
		}
		imagejpeg($im, $filename);
		imagedestroy($im);
		
		return $filename;
	}
?>

Chris J
www.redash.org

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 
AnswerRe: what is wrong that i get this error with nasm Pin
Covean9-Nov-09 22:44
Covean9-Nov-09 22:44 

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.