escper 1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,3 @@
1
+ pkg/*
2
+ *.gem
3
+ .bundle
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "http://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in escper.gemspec
4
+ gemspec
@@ -0,0 +1,2 @@
1
+ require 'bundler'
2
+ Bundler::GemHelper.install_tasks
@@ -0,0 +1,21 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "escper/version"
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = "escper"
7
+ s.version = Escper::VERSION
8
+ s.platform = Gem::Platform::RUBY
9
+ s.authors = ["Michael Franzl"]
10
+ s.email = ["office@michaelfranzl.com"]
11
+ s.homepage = "http://michaelfranzl.com"
12
+ s.summary = %q{Converts bitmaps to the ESC/POS receipt printer command}
13
+ s.description = %q{}
14
+
15
+ s.rubyforge_project = "escper"
16
+
17
+ s.files = `git ls-files`.split("\n")
18
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
19
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
20
+ s.require_paths = ["lib"]
21
+ end
@@ -0,0 +1,61 @@
1
+ require 'RMagick'
2
+ module Escper
3
+ class Image
4
+ def initialize(img)
5
+ @image = convert(Magick::Image.read(img).first)
6
+ end
7
+
8
+ def convert(img=nil)
9
+ if img.nil? and @image
10
+ @image = @image.quantize 2, Magick::GRAYColorspace
11
+ @image = crop(@image)
12
+ return @image
13
+ else
14
+ img = img.quantize 2, Magick::GRAYColorspace
15
+ img = crop(img)
16
+ return img
17
+ end
18
+ end
19
+
20
+ def crop(image)
21
+ @x = (image.columns / 8.0).round
22
+ @y = (image.rows / 8.0).round
23
+ @x = 1 if @x == 0
24
+ @y = 1 if @y == 0
25
+ image = image.extent @x * 8, @y * 8
26
+ return image
27
+ end
28
+
29
+ def to_a
30
+ colorarray = @image.export_pixels
31
+ return colorarray
32
+ end
33
+
34
+ def to_s
35
+ colorarray = self.to_a
36
+ bits = []
37
+ mask = 0x80
38
+ i = 0
39
+ temp = 0
40
+ (@x * @y * 8 * 3 * 8).times do |j|
41
+ next unless (j % 3).zero?
42
+ temp |= mask if colorarray[j] == 0 # put 1 in place if black
43
+ mask = mask >> 1 # shift mask
44
+ i += 3
45
+ if i == 24
46
+ bits << temp
47
+ mask = 0x80
48
+ i = 0
49
+ temp = 0
50
+ end
51
+ end
52
+ result = bits.collect { |b| b.chr }.join
53
+ escpos="\x1D\x76\x30\x00#{@x.chr}\x00#{(@y*8).chr}\x00#{ result }"
54
+ return escpos
55
+ end
56
+ end
57
+ end
58
+
59
+ File.open('/dev/usb/lp0','w') do |f|
60
+ f.write Escper::Image.new('/home/michael3/projects/salor-tec/cigarstore.png').to_s
61
+ end
@@ -0,0 +1,3 @@
1
+ module Escper
2
+ VERSION = "1.0"
3
+ end
metadata ADDED
@@ -0,0 +1,69 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: escper
3
+ version: !ruby/object:Gem::Version
4
+ prerelease: false
5
+ segments:
6
+ - 1
7
+ - 0
8
+ version: "1.0"
9
+ platform: ruby
10
+ authors:
11
+ - Michael Franzl
12
+ autorequire:
13
+ bindir: bin
14
+ cert_chain: []
15
+
16
+ date: 2011-10-20 00:00:00 +02:00
17
+ default_executable:
18
+ dependencies: []
19
+
20
+ description: ""
21
+ email:
22
+ - office@michaelfranzl.com
23
+ executables: []
24
+
25
+ extensions: []
26
+
27
+ extra_rdoc_files: []
28
+
29
+ files:
30
+ - .gitignore
31
+ - Gemfile
32
+ - Rakefile
33
+ - escper.gemspec
34
+ - lib/escper.rb
35
+ - lib/escper/version.rb
36
+ has_rdoc: true
37
+ homepage: http://michaelfranzl.com
38
+ licenses: []
39
+
40
+ post_install_message:
41
+ rdoc_options: []
42
+
43
+ require_paths:
44
+ - lib
45
+ required_ruby_version: !ruby/object:Gem::Requirement
46
+ none: false
47
+ requirements:
48
+ - - ">="
49
+ - !ruby/object:Gem::Version
50
+ segments:
51
+ - 0
52
+ version: "0"
53
+ required_rubygems_version: !ruby/object:Gem::Requirement
54
+ none: false
55
+ requirements:
56
+ - - ">="
57
+ - !ruby/object:Gem::Version
58
+ segments:
59
+ - 0
60
+ version: "0"
61
+ requirements: []
62
+
63
+ rubyforge_project: escper
64
+ rubygems_version: 1.3.7
65
+ signing_key:
66
+ specification_version: 3
67
+ summary: Converts bitmaps to the ESC/POS receipt printer command
68
+ test_files: []
69
+