Ir para conteúdo

Arquivado

Este tópico foi arquivado e está fechado para novas respostas.

Cacio Renato

Codigo de barras

Recommended Posts

Boa tarde galera, estou com uma função que peguei na web e dei uma ajustada simples só que ele gera varias imagens uma dificuldade que estou encontrando é como eu faço para juntar essas imagem deixar uma só e salvar em um local que eu possa pegar .

<?php
	function geraCodigoBarra($numero){
		$fino = 1;
		$largo = 3;
		$altura = 50;
		$img = '';
		
		$barcodes[0] = '00110';
		$barcodes[1] = '10001';
		$barcodes[2] = '01001';
		$barcodes[3] = '11000';
		$barcodes[4] = '00101';
		$barcodes[5] = '10100';
		$barcodes[6] = '01100';
		$barcodes[7] = '00011';
		$barcodes[8] = '10010';
		$barcodes[9] = '01010';
		
		for($f1 = 9; $f1 >= 0; $f1--){
			for($f2 = 9; $f2 >= 0; $f2--){
				$f = ($f1*10)+$f2;
				$texto = '';
				for($i = 1; $i < 6; $i++){
					$texto .= substr($barcodes[$f1], ($i-1), 1).substr($barcodes[$f2] ,($i-1), 1);
				}
				$barcodes[$f] = $texto;
			}
		}
		
		$img .= '<img src="imagens/p.bmp" width="'.$fino.'" height="'.$altura.'" border="0" />';
		$img .= '<img src="imagens/b.bmp" width="'.$fino.'" height="'.$altura.'" border="0" />';
		$img .='<img src="imagens/p.bmp" width="'.$fino.'" height="'.$altura.'" border="0" />';
		$img .= '<img src="imagens/b.bmp" width="'.$fino.'" height="'.$altura.'" border="0" />';
		
		$img .='<img ';
		
		$texto = $numero;
		
		if((strlen($texto) % 2) <> 0){
			$texto = '0'.$texto;
		}
		
		while(strlen($texto) > 0){
			$i = round(substr($texto, 0, 2));
			$texto = substr($texto, strlen($texto)-(strlen($texto)-2), (strlen($texto)-2));
			
			if(isset($barcodes[$i])){
				$f = $barcodes[$i];
			}
			
			for($i = 1; $i < 11; $i+=2){
				if(substr($f, ($i-1), 1) == '0'){
  					$f1 = $fino ;
  				}else{
  					$f1 = $largo ;
  				}
  				
  				$img .= 'src="imagens/p.bmp" width="'.$f1.'" height="'.$altura.'" border="0">';
  				$img .= '<img ';
  				
  				if(substr($f, $i, 1) == '0'){
					$f2 = $fino ;
				}else{
					$f2 = $largo ;
				}
				
				$img .= 'src="imagens/b.bmp" width="'.$f2.'" height="'.$altura.'" border="0">';
				$img .= '<img ';
			}
		}
		$img .= 'src="imagens/p.bmp" width="'.$largo.'" height="'.$altura.'" border="0" />';
		$img .= '<img src="imagens/b.bmp" width="'.$fino.'" height="'.$altura.'" border="0" />';
		$img .= '<img src="imagens/p.bmp" width="1" height="'.$altura.'" border="0" />';
		
		return $img;
		
		
	}

	echo geraCodigoBarra('0123456789');

	
?>

Compartilhar este post


Link para o post
Compartilhar em outros sites

×

Informação importante

Ao usar o fórum, você concorda com nossos Termos e condições.