Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Printing Image #1

Closed
abdkaviani opened this issue Nov 29, 2018 · 2 comments
Closed

Printing Image #1

abdkaviani opened this issue Nov 29, 2018 · 2 comments

Comments

@abdkaviani
Copy link

Hello Ian

This is a simple datamax code to printing my image:

$command = "\x02qA\x0d";
$command .= "\x02IAAFLOGO\x0d";
$command .= "801100000000FFFFFFFFFFFFFFFFFFFFFFFF00\x0d";
$command .= "801100000000FFFFFFFFFFFFFFFFFFFFFFFF00\x0d";
$command .= "801100000000FFFFFFFFFFFFFFFFFFFFFFFF00\x0d";
$command .= "801100000000FFFFFFFFFFFFFFFFFFFFFFFF00\x0d";
$command .= "801100000000FFFFFFFFFFFFFFFFFFFFFFFF00\x0d";
$command .= "801100000000FFFFFFFFFFFFFFFFFFFFFFFF00\x0d";
$command .= "801100000000FFFFFFFFFFFFFFFFFFFFFFFF00\x0d";
$command .= "FFFF\x0d";
$command .= "\x02L\x0d";
$command .= "1Y1100000000000LOGO\x0d";
$command .= "E\x0d";

I found a solution to convert my image to datamax format (edit this sample), but my result is not suitable or bad resolution. Do you know best function to printing an image with Datamax language with php?

@ianthrive
Copy link
Owner

I don't have a direct answer for your question. However, a couple thoughts:

Check out page 20 and 139 of the PDF manual in this repository.

The solution to which you link is for ZPL (Zebra Printing Language). As a general rule, ZPL is not compatible with older Datamax printers. I don't know if your snippet is Datamax-compatiable.

@abdkaviani
Copy link
Author

abdkaviani commented Dec 9, 2018

Thanks

I edited above link according to the Datamax manual
This is my function and it works for me in most cases
I hope somebody to write perfect function :)

function imageToDPL($in, $name='') {
$res = "";
if(empty($in)) return '';
$im = imagecreatefrompng($in);
if ($im === false) return false;
// Black and white only
imagefilter($im, IMG_FILTER_GRAYSCALE); //first, convert to grayscale
imagefilter($im, IMG_FILTER_CONTRAST, -255); //then, apply a full contrast
// Convert to WBMP
ob_start();
imagewbmp($im);
$wbmp = ob_get_contents();
ob_end_clean();
$type = uintvar_shift($wbmp);
$fixed = uintvar_shift($wbmp);
$w = uintvar_shift($wbmp);
$h = uintvar_shift($wbmp);
$bitmap = str_split($wbmp); // Black is white, white is black
$total_bytes = count($bitmap);
$bytes_per_line = ceil($w/8);
if($w % 8 > 0) {
// End of line is padded with black; make that white
// Get last byte of each line
$period = ceil($w/8);
for($i=$bytes_per_line; $i <= $total_bytes; $i+=$bytes_per_line) {
$byte = ord($bitmap[$i-1]);
for($j=1; $j<=$w%8; $j++) {
// Flip j-th bit
$byte = $byte & (
(1<<($j-1)));
}
$bitmap[$i-1] = chr($byte);
}
}
$bitmap = implode("", $bitmap);
$uncompressed = strtoupper(bin2hex($bitmap));
$prtLine = strtoupper(dechex($bytes_per_line));
//echo "width:".$w." height:".$h." total:".$total_bytes." per_line:".$bytes_per_line." length:".strlen($uncompressed)."
";
for($k=strlen($uncompressed);$k>=0;$k-=($bytes_per_line2))
$res .= "80".$prtLine.substr($uncompressed,$k,($bytes_per_line
2))."\x0d";
//$r = $uncompressed;
return $res;
}
function uintvar_shift(&$data) {
$index = 0;
$r = 0;
while ((ord($data[$index]) & 0x80) != 0) {
if ($index >= 4) {
return false;
}
$r = ($r << 7) | (ord($data[$index]) & 0x7f);
$index++;
}
$r = ($r << 7) | (ord($data[$index]) & 0x7f);
$data = substr($data, $index + 1);
return $r;
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants