W jaki sposób dla poniższej klasy mogę dodać tło w generowanym kodzie kreskowym lub - najlepsze rozwiązanie - całość była generowana na tle innego pliku PNG, GIF lub JPEG?
class barCodeGenrator { private $file; private $into; private $digitArray = array(0=>"00110",1=>"10001",2=>"01001",3=>"11000",4=>"00101",5=>"10100",6=>"01100",7=>"00011",8=>"10010",9=>"01010"); function __construct($value,$into=1, $filename = 'barcode.gif', $width_bar=450, $height_bar=65, $show_codebar=false) { $lower = 1 ; $hight = 50; $this->into = $into; $this->file = $filename; for($count1=9;$count1>=0;$count1--){ for($count2=9;$count2>=0;$count2--){ $count = ($count1 * 10) + $count2 ; $text = "" ; for($i=1;$i<6;$i++){ } $this->digitArray[$count] = $text; } } $height_bar_max = $height_bar; $width_bar_max = $width_bar; $img = imagecreate($width_bar_max,$height_bar_max); if ($show_codebar) { $height_bar -= 25; } $cl_black = imagecolorallocate($img, 0, 0, 0); $cl_white = imagecolorallocate($img, 255, 255, 255); #imagefilledrectangle($img, 0, 0, $lower*95+1000, $hight+300, $cl_white); imagefilledrectangle($img, 0, 0, $width_bar_max, $height_bar_max, $cl_white); imagefilledrectangle($img, 5,5,5,$height_bar,$cl_black); imagefilledrectangle($img, 6,5,6,$height_bar,$cl_white); imagefilledrectangle($img, 7,5,7,$height_bar,$cl_black); imagefilledrectangle($img, 8,5,8,$height_bar,$cl_white); $thin = 1 ; $wide = 3; } else { $wide = 2.72; } $pos = 9 ; $text = $value ; $text = "0" . $text; } $f = $this->digitArray[$i]; for($i=1;$i<11;$i+=2){ $f1 = $thin ; }else{ $f1 = $wide ; } imagefilledrectangle($img, $pos,5,$pos-1+$f1,$height_bar,$cl_black) ; $pos = $pos + $f1 ; $f2 = $thin ; }else{ $f2 = $wide ; } imagefilledrectangle($img, $pos,5,$pos-1+$f2,$height_bar,$cl_white) ; $pos = $pos + $f2 ; } } imagefilledrectangle($img, $pos,5,$pos-1+$wide,$height_bar,$cl_black); $pos=$pos+$wide; imagefilledrectangle($img, $pos,5,$pos-1+$thin,$height_bar,$cl_white); $pos=$pos+$thin; imagefilledrectangle($img, $pos,5,$pos-1+$thin,$height_bar,$cl_black); $pos=$pos+$thin; if ($show_codebar) { imagestring($img, 5, 0, $height_bar+5, " ".$value, imagecolorallocate($img, 0, 0, 0)); } $this->put_img($img); } function JSK_left($input,$comp){ } function JSK_right($input,$comp){ } function put_img($image,$file='test.gif'){ if($this->into){ imagegif($image,$this->file); } else { imagegif($image); } imagedestroy($image); } }
wywołanie wygląda tak:
function generujLiczbe($liczba) { $defLen = 12; $lenDif = $defLen-$len; $number = false; for ($i=0; $i < $lenDif; $i++) { $number .= 0; } return $number.$liczba; } require_once('barcode.inc.php'); $code_number = generujLiczbe(8); new barCodeGenrator($code_number, 0, 'barcode.png', 120, 50, true);
Z operacjami na obrazkach za bardzo sobie nie radze dlatego będę wdzięczny za wszelką pomoc
Pozdrawiam