BOCA IMAGE (sort of)

The BOCA MiniMB (Now Lemur) printer has become a de facto standard in theatres and other entertainment venues for ticket printing.

Unlike Zebra (which has numerous excellent online tools like Labelary's Free Online Editor for their ZPL language), tooling for the BOCA FGL (Friendly Ghost Language) is harder to find.

A few guides make reference to BOCA IMAGE for converting an image file to something that the BOCA can print from FGL. Unfortuntaely, this is not freely available and, at least on my aging MiniMB printers, printing .BMP and .PCX image formats was either flaky or slow.

It turns out converting a PNG to <g> image data for use with the BOCA printers is actually quite trivial, as the following short PHP script should hopefully demonstrate.

This is NOT the most efficient way to do this (but you only need to do it once for a logo) and it uses a lot of string manipulation purely because it was easier to debug at the time, you could generate binary data if you prefer.

Anyway, hopefully someone will find this useful if you need to get an image onto a BOCA printer!

<?php
// Import a .png image
$im = imagecreatefrompng("./bitmap.png");

// Optionally set a position here
$x_pos = 1420; // the column position on the ticket 
$y_pos = 310;  // the row position on the ticket

$imgW = imagesx($im);
$imgH = imagesy($im);
$x = 0;
$y = 0;

// Loop through each row of the image
while ($y < $imgH) {
	$arrRow = Array();
    // Loop through each column of the image
	while ($x < $imgW) {
		// process 8 rows at a time
		$bin = ''; // concatenated into a string for laziness
		for ($line = 0; $line <= 7; $line++) {
			if ($y+$line > $imgH-1) {
				$bin .= '0';
			} else {
				$rgb = imagecolorat($im, $x, $y+$line);
				$boolThisPix = !($rgb > 1);
				$bin .= ($boolThisPix) ? '1' : '0';
			}
		}
		$hex = dechex(bindec($bin));
		if (strlen($hex) == 1) $hex = "0$hex";
		$arrRow[] = $hex;
		$x++;
	}
	$y = $y+7;
	$x = 0;
	$posny = $y+$y_pos;
	$posnx = $x+$x_pos;
	echo "<RC$posny,$posnx><g".(sizeof($arrRow)*2).">".join('',$arrRow);
	echo "\n";
}