2

We need to create a 1 bit BMP file to send it to a printer. Apparently the file should be a headerless bmp file. I found that that could be just removing the first 45 bytes.

I got something like this, but it aint working:

$filename = APPPATH.'../assets/test.prn';
$im = @imagecreate(432, 20) or die("Cannot Initialize new GD image stream");
$background_color = imagecolorallocate($im, 255, 255, 255);
$text_color = imagecolorallocate($im, 0, 0, 0);
imagestring($im, 1, 5, 5,  "A Simple Text String", $text_color);
imagepng($im, $filename);
imagedestroy($im);
$im = new Imagick();
$im->readimage($filename);
$im->resizeimage(432, 20, Imagick::FILTER_UNDEFINED, 1, false);
$im->posterizeimage(2, false);
$im->writeimage($filename.".bmp");

This is just to try and make a 1 bit image file. But it is not headerless and it isn't a bmp.

user1494552
  • 163
  • 8
  • 1
    I think “headerless” is a misnomer, because without _any_ header no interpreting software would know the dimensions of the image. I can only assume that what is meant is maybe a [Wireless Bitmap](http://en.wikipedia.org/wiki/Wbmp) image …? – If so, have a look at [image2wbmp](http://www.php.net/manual/en/function.image2wbmp.php) / [imagewbmp](http://www.php.net/manual/en/function.imagewbmp.php). – CBroe Feb 12 '14 at 13:49
  • Well, the bitmap data is used in a c++ program that adds it's own header. The width of the image is always the same and so known. The whole thing is then pushed to a printer. – user1494552 Feb 12 '14 at 15:08
  • I doubt there's no such thing as a headerless BMP file. You can have BMP files that have had their header removed. Or you can have raw RGB data files, which look like the image data in a BMP file. You probably are after just raw 1-bit rgb* data - can you provide an example file of what you're after. – Danack Feb 13 '14 at 03:06
  • Well, you guys probably are right. I got wrong instructions. After we did some trial and errors we managed to use a normal 1 bit bmp, with header, and print it. It did help that you guys said that headerless was probably not needed, so thanks. – user1494552 Feb 13 '14 at 18:31

1 Answers1

-2

Did you have any issues installing Imagick, there is a comment on it being a bit tricky with some PHP versions.

Marcus Kirsch
  • 87
  • 2
  • 7