Escper (read: “escaper”) – Convert an image to ESCPOS commands for thermal receipt printers

Usage:

gem install escper

Test it in a Ruby script:

require 'escper'
puts Escper::Image.new('test.png', :file).to_s

Or if you read the image from an image upload form in Rails, do this:

Escper::Image.new(data.read, :blob).to_s

where “data” is a variable containing the image data of a multipart HTML form.

For optimal visual results, image.png should previously be converted to an indexed, black and white 1-bit palette image. In Gimp, click on “Image -> Mode -> Indexed…” and select “Use black and white (1-bit) palette”. For dithering, choose “Floyd-Steinberg (reduced color bleeding)”. The image size depends on the resolution of the printer.

To send an image directly to a thermal receipt printer:

File.open('/dev/usb/lp0','w') { |f| f.write Escper::Image.new('image.png').to_s }

Licence

Copyright © 2011-2012 Michael Franzl <[email protected]>

This program is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more details.

You should have received a copy of the GNU Affero General Public License along with this program. If not, see <www.gnu.org/licenses/>.