Does Zebra GC420t supports black and white images to print

I am using an Zebra GC420t printer where I need to print the image on label. I can convert the image to the hex code using the following the code

<?php
/**

 * Converts a PNG image to a .GRF file for use with Zebra printers
 * The input is preferably a 1-bit black/white image but RGB images
 * are accepted as well.
 *
 * This function uses PHP's GD library image functions.
 *
 * @copyright Thomas Bruederli <inbox@brotherli.ch>
 *
 * @param string $filename Path to the input file
 * @param string $targetname Name of the GRF file reference
 * @return string ZPL command for uploading the graphic image (~DG)
 */

$photo_url="";
if(isset($_GET['photo'])){
  $photo_url=$_GET['photo'];
}

function image2grf($filename='photo_url', $targetname = 'R:IMAGE.GRF')
{
  $info = getimagesize($filename);
  $im = imagecreatefrompng($filename);
  $width = $info[0]; // imagesx($im);
  $height = $info[1]; // imagesy($im);
  $depth = $info['bits'] ?: 1;
  $threshold = $depth > 1 ? 160 : 0;
  $hexString = '';
  $byteShift = 7;
  $currentByte = 0;
  // iterate over all image pixels
  for ($y = 0; $y < $height; $y++) {
    for ($x = 0; $x < $width; $x++) {
      $color = imagecolorat($im, $x, $y);
      // compute gray value from RGB color
      if ($depth > 1) {
        $value = max($color >> 16, $color >> 8 & 255, $color & 255);
      } else {
        $value = $color;
      }
      // set (inverse) bit for the current pixel
      $currentByte |= (($value > $threshold ? 0 : 1) << $byteShift);
      $byteShift--;
      // 8 pixels filled one byte => append to output as hex
      if ($byteShift < 0) {
        $hexString .= sprintf('%02X', $currentByte);
        $currentByte = 0;
        $byteShift = 7;
      }
    }
    // append last byte at end of row
    if ($byteShift < 7) {
      $hexString .= sprintf('%02X', $currentByte);
      $currentByte = 0;
      $byteShift = 7;
    }
    $hexString .= PHP_EOL;
  }
  // compose ZPL ~DG command
  $totalBytes = ceil(($width * $height) / 8);
  $bytesPerRow = ceil($width / 8);
return sprintf('~DG%s,%05d,%03d,' . PHP_EOL, $targetname, $totalBytes, $bytesPerRow) . $hexString;
}
// Usage:
print "^XA N ^XZ" . PHP_EOL;
print image2grf($photo_url, 'R:SAMPLE.GRF');
// print "^XA^FO20,20^XGR:SAMPLE.GRF,1,1^FS^XZ" . PHP_EOL;

This code converts the image to the hex code for example if an image input is given:

0000000000000000000000000000000000000007FDFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF0 000000000000000000000000000000000000018FE3FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF0 0000000000000000000000000000000000000031C1FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF0 00000000000000000000000000000000000000027FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF0

But when I try to print the image on the label it doesn't show up any image This is the code where I refered from the github refer

1 answer

  • answered 2018-11-08 21:34 AkA

    I check your ZPL code with zpldesigner.com software, and the result is a blank label, so your php code to convert image to Zebra graphic is wrong