Coder Social home page Coder Social logo

Printing Image about datamax HOT 2 CLOSED

abdkaviani avatar abdkaviani commented on August 16, 2024
Printing Image

from datamax.

Comments (2)

ianthrive avatar ianthrive commented on August 16, 2024

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.

from datamax.

abdkaviani avatar abdkaviani commented on August 16, 2024

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;
}

from datamax.

Related Issues (1)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.