Zebra\Zpl\Image::encode PHP Method

encode() protected method

Encode the image in ASCII hexadecimal by looping over every pixel.
protected encode ( ) : string
return string
    protected function encode()
    {
        $bitmap = null;
        $lastRow = null;
        for ($y = 0; $y < $this->height; $y++) {
            $bits = null;
            for ($x = 0; $x < $this->width; $x++) {
                $bits .= (imagecolorat($this->image, $x, $y) & 0xff) < 127 ? '1' : '0';
            }
            $bytes = str_split($bits, 8);
            $bytes[] = str_pad(array_pop($bytes), 8, '0');
            $row = null;
            foreach ($bytes as $byte) {
                $row .= sprintf('%02X', bindec($byte));
            }
            $bitmap .= $this->compress($row, $lastRow);
            $lastRow = $row;
        }
        return $bitmap;
    }