|
I came across this a while ago - dunno if it'll help:
<?php
function UPCAbarcode($code) {
$lw = 2; $hi = 100;
$Lencode = array('0001101','0011001','0010011','0111101','0100011',
'0110001','0101111','0111011','0110111','0001011');
$Rencode = array('1110010','1100110','1101100','1000010','1011100',
'1001110','1010000','1000100','1001000','1110100');
$ends = '101'; $center = '01010';
if ( strlen($code) != 11 ) { die("UPC-A Must be 11 digits."); }
$ncode = '0'.$code;
$even = 0; $odd = 0;
for ($x=0;$x<12;$x++) {
if ($x % 2) { $odd += $ncode[$x]; } else { $even += $ncode[$x]; }
}
$code.=(10 - (($odd * 3 + $even) % 10)) % 10;
$bars=$ends;
$bars.=$Lencode[$code[0]];
for($x=1;$x<6;$x++) {
$bars.=$Lencode[$code[$x]];
}
$bars.=$center;
for($x=6;$x<12;$x++) {
$bars.=$Rencode[$code[$x]];
}
$bars.=$ends;
$img = ImageCreate($lw*95+30,$hi+30);
$fg = ImageColorAllocate($img, 0, 0, 0);
$bg = ImageColorAllocate($img, 255, 255, 255);
ImageFilledRectangle($img, 0, 0, $lw*95+30, $hi+30, $bg);
$shift=10;
for ($x=0;$x<strlen($bars);$x++) {
if (($x<10) || ($x>=45 && $x<50) || ($x >=85)) { $sh=10; } else { $sh=0; }
if ($bars[$x] == '1') { $color = $fg; } else { $color = $bg; }
ImageFilledRectangle($img, ($x*$lw)+15,5,($x+1)*$lw+14,$hi+5+$sh,$color);
}
ImageString($img,4,5,$hi-5,$code[0],$fg);
for ($x=0;$x<5;$x++) {
ImageString($img,5,$lw*(13+$x*6)+15,$hi+5,$code[$x+1],$fg);
ImageString($img,5,$lw*(53+$x*6)+15,$hi+5,$code[$x+6],$fg);
}
ImageString($img,4,$lw*95+17,$hi-5,$code[11],$fg);
header("Content-Type: image/png");
ImagePNG($img);
}
UPCAbarcode('12345678901');
?>
|
|
|
|
|
I got it working. I had a few issues that needed to be adressed.
1) My checksum made a mistake of just using the modulus value as a lookup, when I really needed to add 32 to the value and find the ascii character it represents. Then I can find the hash code based on that and add it to the bar code string.
$checksum = $checksum + 32;
$checksum2 = chr($checksum);
$key = array_search($checksum2,$b_chr,true);
$bcstring.=$b_enc[$key].$stop.$term_bar;
2) I did not draw the final termination barcode in my for loop due to a simple logic error. I corrected it with and a "or" to check for the end of the barcode string so I write the last part.
if($bcstring[$i]==0 && $bcstring[$i]!=$last_char || $i == $bc_cnt-1)
{
imagefilledrectangle($im, $start_x, $pad_top, $start_x+($stop_x*$size)-1, $height, $black);
$stop_x = 1;
}
it is all working. If anyone wants to use this code, enjoy!
Of course a mention is always nice
|
|
|
|
|
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
$string=urldecode($_GET['string']);
$size=urldecode($_GET['size']);
$height=urldecode($_GET['height']);
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;
$ttl_height = $pad_top + $pad_text + $font_size + $pad_bottom + $height;
$running_checksum = 104;
$bcstring.=$b_enc['104'];
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;
$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) {
$start_x = $quiet_zone+($i*$size);
}
if($bcstring[$i]==1 && $bcstring[$i]==$last_char) {
$stop_x++;
}
if($bcstring[$i]==0 && $bcstring[$i]!=$last_char) {
imagefilledrectangle($im, $start_x, $pad_top, $start_x+($stop_x*$size)-1, $height, $black);
$stop_x = 1;
}
$last_char = $bcstring[$i];
if($bcstring[$i]==0 && $bcstring[$i]!=$last_char || $i == $bc_cnt-1){
imagefilledrectangle($im, $start_x, $pad_top, $start_x+($stop_x*$size)-1, $height, $black);
$stop_x = 1;
}
}
imagestring($im, 3, $font_left, $font_top, "", $black);
imagepng($im);
imagedestroy($im);
?>
|
|
|
|
|
here is the full code that is in production still. maybe this will help. cjoki
<?php
function gen_code128($string, $fid, $size = 1, $height = 50, $show_text = true)
{
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;
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;
$bcstring.=$b_enc['104'];
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;
if($checksum<95)
{
$checksum = $checksum + 32;
$checksum2 = chr($checksum);
$key = array_search($checksum2,$b_chr,true);
}
else
{
$key = $checksum;
}
$bcstring.=$b_enc[$key].$stop.$term_bar;
$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)
{
$start_x = $quiet_zone+($i*$size);
}
if($bcstring[$i]==1 && $bcstring[$i]==$last_char)
{
$stop_x++;
}
if($bcstring[$i]==0 && $bcstring[$i]!=$last_char || $i == $bc_cnt-1)
{
imagefilledrectangle($im, $start_x, $pad_top, $start_x+($stop_x*$size)-1, $height, $black);
$stop_x = 1;
}
$last_char = $bcstring[$i];
}
$filename = '';
if($show_text)
{
imagestring($im, 3, $font_left, $font_top, $string, $black);
}
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
|
|
|
|
|
Hi everyone,
Im new to Linux and its first time that I am using of it but I have a problem how can I install exe files in linux I searched on the net and I undrestood that its not possible because exe files are for windows but you can install exe files with WINE so I got wine.exe but again its exe how can I install wine? I am using of "Mandriva Linux" on VMware Workstation.
Thanks
|
|
|
|
|
in the name of god
hello
depending on your linux os:
if you access to internet only type:
sudo apt-get install wine
password:
type your password then wine itself will be installed.
valhamdoolelah.
|
|
|
|
|
in the name of god
hello everybody
i want to use one of linux app as oog to do an action and then after 10 second do other action how i must do it? indeed how i use this time and how i use linux app in perl? must i install special perl modules?
valhamdolelah
|
|
|
|
|
|
good but how to use for example oog or totem the app off linux in it??
thanks.
valhamdolelah.
|
|
|
|
|
if i understand what you want to do...
system "oog" == 0 or die $!;
sleep(10);
system "totem" == 0 or die $!;
whatever the syntax for those linux apps are, please fill in.
|
|
|
|
|
thanks
i exactly want the thing that you have wrote.but please let me find what is the below error:
#!/scr/bin/perl -w
#use strict;
use warnings;
system "oog" == 0 or die $!;
sleep(10);
system "totem" == 0 or die $!;
=pod
Argument "oog" isn't numeric in numeric eq (==) at perl.pl line 4.
Can't exec "1": No such file or directory at perl.pl line 4.
Argument "totem" isn't numeric in numeric eq (==) at perl.pl line 6.
Can't exec "1": No such file or directory at perl.pl line 6.
=cut
__END__
valhamdolelah.
|
|
|
|
|
hmmm.... didn't expect that. I wonder which version of Perl that you are using.
try this:
system("oog") == 0 or die $!
etc...
|
|
|
|
|
thanks for your replies
this is my perl version:
This is perl, v5.10.0 built for i386-linux-thread-multi
i used this command:
#!/scr/bin/perl -w
use strict;
use warnings;
#system "oog" == 0 or die $!;
sleep(3);
my $music="/home/sajad/intertainment/Music/001.MP3";
system "totem --play $music";
sleep(8);
system "totem --quit $music";
exit;
but i want to play a music and then at finish i want to close it but none of the command i write after system "totem --play $music";
are executed until i manually close the totem ,how i can solve this error????
thanks in advance.
valhamdolelah.
|
|
|
|
|
try using
exec "totem --play $music";
iirc, exec does not wait for the command to return output and system does.
|
|
|
|
|
oh
this also not work!!
after playing the music it stopped and is on the screen yet.
indeed i want to use a linux app and after some works close it with some command as this thing i posted.it can be a music or a program.
thanks.
|
|
|
|
|
ok, for clarification...
is it still not stopping after 8 seconds?
because otherwise all you would need to do is change your second system to exec, because it would be hanging up there.
|
|
|
|
|
i wrote this :
#!/scr/bin/perl -w
use strict;
use warnings;
my $music="/home/sajad/intertainment/Music/001.MP3";
system "totem --play $music";
sleep(8);
exec "totem --quit $music";
exit;
after playing the music in 6 second(time of music) then it stopped until i close it then the command sleep(8) is running and after it terminate my program.i also wrote this code but as above result:
#!/scr/bin/perl -w
use strict;
use warnings;
my $music="/home/sajad/intertainment/Music/001.MP3";
system "totem --play $music";
exec "totem --quit $music";
exit;
|
|
|
|
|
ok... so you changed
system "totem --quit $music";
to
exec "totem --quit $music";
correct?
did you try the change I suggested which was:
system "totem --play $music";
to
exec "totem --play $music";
|
|
|
|
|
yes i also change it to all of states with changing exec to system or system to exec but it play the music repeatedly
also this is one of them:
#!/scr/bin/perl -w
use strict;
use warnings;
#system "oog" == 0 or die $!;
sleep(3);
my $music="/home/sajad/intertainment/Music/001.MP3";
system "totem --play $music && totem --quit $music";
#sleep(8);
system "totem --quit $music";#exec "totem --quit $music";
exit;
|
|
|
|
|
This is error:
aljaz@aljaz-laptop /Desktop$ nasm -f elf vhod.asm
aljaz@aljaz-laptop /Desktop$ ld -s -o vhod vhod.o
ld: i386 architecture of input file `vhod.o' is incompatible with i386:x86-64 output
ld: warning: cannot find entry symbol _start; defaulting to 00000000004000b0
vhod.o: In function `main':
vhod.asm text+0x7): undefined reference to `printf'
aljaz@aljaz-laptop /Desktop$
Here is code:
bits 32
extern printf
global main
section .data
message db "hello, world!", 10, 0
section .text
main:
pushad;
push dword message
call printf;
add esp, 4;
popad;
ret
|
|
|
|
|
Some suggestions:
1. It seems that you created an 32-bit application but try to compile it as an 32/64-bit application.
Try to add the parameter -m32 to ld.
2. I think you have to link your vhod.o with an library that holds the printf function.
3. At last, try to solve the warning by calling your main start or adding -e main to the ld statement.
I hope that helps and be aware this are only suggestions cause I never developed for linux.
Greetings
Covean
|
|
|
|
|
I always wanted to distribute my PHP files without having to distribute a server package like WAMP, XAMPP etc so now I use Viewer for PHP. Its open source and freely available:
http://viewerforphp.sourceforge.net/[^]
|
|
|
|
|
<?php
$url = "http://www.nseindia.com/content/equities/TopGainers.htm";
$html = strtolower(implode('', file($url)));
echo $html;
?>
Why i am unable to read this file ?
|
|
|
|
|
Permissions. DO you own the site? If so set you need to check your settings in php.ini on nseindia
|
|
|
|
|
udch wrote: file($url)
you need to look up and set permissions for that
|
|
|
|
|