Closed sv1gzf closed 8 years ago
While debugging I noticed that on the first GFA row the string is properly formated
^GFA,5000,5000,25,:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::W03LFC01LF8......
But on the second row !!!
^GFA,5000,5000,25,,:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::g03F0103FC0...
The format should be ^GFa,b,c,d,data but it has two commas after the d value !!!!
A quick work around was this /* * Encode the image in ASCII hexadecimal by looping over every pixel. * @return string */ protected function encode() { $bitmap = null;
for ($row = 0; $row < $this->height; $row++) {
$bits = null;
for ($column = 0; $column < $this->width; $column++) {
$bits .= (imagecolorat($this->image, $column, $row) & 0xFF) < 127 ? '1' : '0';
}
$bytes = str_split($bits, 8);
$bytes[] = str_pad(array_pop($bytes), 8, '0');
$ascii = null;
foreach ($bytes as $byte) {
$ascii .= sprintf('%02X', bindec($byte));
}
//$bitmap .= $this->compress($ascii);
$bitmap .= $ascii;
}
return $bitmap;
}
Each instance of the Builder class is designed to represent one label. It automatically inserts ^XA
and ^XZ
. If you want to print two labels, you need to instantiate the Builder class twice and build up each label separately.
The "extra" comma is intended behaviour. A comma in ZPL image compression represents one entire row of zeros.
It Looks like the Images object causes a problem when printing multiple image labels
I wrote this code and it works smoothly printing both labels $client = new Client('192.168.4.201'); $zpl = new Builder();
//SIMPLE LABELS $zpl->command('XA'); $zpl->fo(100,100)->command('BY3')->command('B4N,20,A,A')->command('FD12345ABCDE')->fs(); $zpl->command('XZ'); //Label 2 $zpl->command('XA'); $zpl->fo(100,100)->command('BQN,2,10')->command('FDMM,AAC-42')->command('FD12345ABCDE')->fs(); $zpl->command('XZ'); $client->send($zpl);
But this code one only prints one of the the two image labels. $client = new Client('192.168.4.201'); $zpl = new Builder();
//LABELS WITH IMAGES $zpl->command('XA'); $zpl->fo(100,100)->gf(new Image(file_get_contents('test1.gif')))->fs(); $zpl->command('XZ'); $zpl->command('XA'); $zpl->fo(100,100)->gf(new Image(file_get_contents('test2.gif')))->fs(); $zpl->command('XZ'); $client->send($zpl);
The printer completely ignores the second label :(