nfephp-org / posprint

API para impressão em impressoras POS (Point of Sales) térmicas.
Other
66 stars 43 forks source link

Epson TM-T88v 4-bit grayscale image #75

Closed ninsky closed 7 years ago

ninsky commented 7 years ago

Hello

first of all, thanks for your effort to publish this code!

I have an Epson TM-T88V printer which is capable to print a 4-bit PNG grayscale / multi tone image. I didn't manage it yet to produce raster code which is accepted by the printer. Do you have any plans to provide a PHP function to provide such raster code? As far as I've seen in your code your translating images to 1-bit BW.

Posted the same request here, as I'm a bit lost: https://github.com/mike42/escpos-php/issues/154

Thanks in advance ninsky

robmachado commented 7 years ago

I do not see why not, but I do not have access to that specific printer (as well as any). So any real practice test will depend on fellow like you.

I will find what are the code structures to send the image in the Epson manuals and return as soon as possible.

ninsky commented 7 years ago

Thanks for your reply, Rob. Of course, would be happy to help by testing code.

Actually I'm using TM-T88V direct print feature which polls periodically a web url providing a XML file containing the base64 encoded raster code of the 4-bit PNG image. The XML data has to be in Epson's ePOS-Print XML format.

On page 74 within the ePOS-Print manual there are some hints how to create raster code from 4-bit grayscale PNGs like

Data is generated based on 1 bit per pixel for two-tone images, and 4 bits per pixel for 16-tone images, starting with the upper bits of byte data. And zero-padding is performed so that scan data per line can be treated on a byte basis.

and...

To create raster graphic bit-images, use the ePOS-Print XML generator tool or your own application. Note the following when creating raster graphic images using your own application. Two-tone image: Specify a multiple of 8 for the image width or fill the missing bits with zeros. 16-tone image: Specify a multiple of 2 for the image width or fill the missing bits with zeros.

I've tried to create such a PNG to raster code coverter from scratch but realized my missing understanding about the PNG file format and image processing (I'm still trying to dig in...). Hopefully it's easier to modify your existing 1-bit PNG function to work with 4-bit PNGs. Please let me know if I can help somehow...!

robmachado commented 7 years ago

Well, this is not a simple thing to do. Convert a PNG 16-bits for a 4-bit is simple using the imagick functions. The problem is to make sure that the image meets the structure required by the printer command. From what you say, you are using the SOAP server by sending an XML file, and not low-level commands. And then the problem may be even easier to solve, using the http://www.i-pos.nl/epson/ application and making a reverse engineering.

ninsky commented 7 years ago

Yes, you're right. I've already found the according JS function and tried to reverse engineer it. Have to work on it as there's another complexity to understand what type of raster code a HTML5 canvas object produces and how to work with it in PHP...

Do you think it would need a complete rewrite of your existing converstRaster() function to work with 4-bit PNG images or would it be a matter of adapting some variables within the function? I'm just trying to find out which way is easier to solve... Thanks so far!

robmachado commented 7 years ago

Yes, the code have to be rewritten ... currently the code considers only one bit for each pixel and reassembles the byte that will print each line of the image. In the normal condition (BW), where each byte will print 8 pixels.

So, an image of 256x60 pixels, will be require 32 bytes per line and 60 lines. We need to know how they passed the information to the printer when have multiple shades of gray.

robmachado commented 7 years ago

Ex. In the example generated with the epson editor I received in the xml a string with 10,240 bytes to represent an image of 256x60 pixels.

If it were only in BW would be 1,920 bytes.

ninsky commented 7 years ago

Think I will try my luck to translate the JS function line by line to PHP. I've already spent much time to find an existing PHP solution which doesn't seem to exist at the moment. I'll let you know if I should be successful with it ;)

robmachado commented 7 years ago

OK I will also continue to study the matter and I'll let you know if you have success

ninsky commented 7 years ago

Decided to generate the raster code on client side using Epsons's JS lib. Don't like doing thinks in JS which I could do on server side, but it works ;) Maybe I should move from PHP to Node.js ;) Thanks for the exchange! You can close this ticket if you want.

robmachado commented 7 years ago

Ok friend ... when I solve i reopen this issue By