escpos-image 0.0.3 → 0.0.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/.gitlab-ci.yml +22 -0
- data/Rakefile +7 -1
- data/escpos-image.gemspec +1 -2
- data/lib/escpos/image.rb +22 -19
- data/test/lib/escpos/image_test.rb +2 -2
- data/test/results/test_image_conversion.png +0 -0
- metadata +6 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 3093ebac2fdbbf59507fc5c4a209f85941a90d03c0f0838a626b43401df38672
|
4
|
+
data.tar.gz: 9e52328a87653d53b3d4359010feccae312c93ef10ecbbc6d41db0944c52469d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ef20ab54bffe996cb3ed65bcd5d6eff1c7a4cc581c63ccdcae982766e3616d8e6f13a02645f0921747923fe91971f399da5c15f9a164b34df44f7e877a284274
|
7
|
+
data.tar.gz: 18cfe1a217a0910f5644b198e5c32a4eeaf04f9d94e8a1a132bdb1af82f9124e7bc2d3c66c91610008e2b4f715b232848efa265acb4113b821705a2f58602b1d
|
data/.gitlab-ci.yml
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
image: ruby:2.5
|
2
|
+
|
3
|
+
cache:
|
4
|
+
paths:
|
5
|
+
- vendor/ruby
|
6
|
+
|
7
|
+
stages:
|
8
|
+
- test
|
9
|
+
|
10
|
+
before_script:
|
11
|
+
- ruby -v
|
12
|
+
- bundle -v
|
13
|
+
- bundle install --jobs $(nproc) --path vendor
|
14
|
+
- apt-get install -y imagemagick
|
15
|
+
- gem install mini_magick
|
16
|
+
|
17
|
+
test:
|
18
|
+
stage: test
|
19
|
+
script:
|
20
|
+
- rake test
|
21
|
+
environment:
|
22
|
+
name: test
|
data/Rakefile
CHANGED
data/escpos-image.gemspec
CHANGED
@@ -1,4 +1,3 @@
|
|
1
|
-
# coding: utf-8
|
2
1
|
lib = File.expand_path('../lib', __FILE__)
|
3
2
|
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
3
|
require 'escpos/image'
|
@@ -23,7 +22,7 @@ Gem::Specification.new do |spec|
|
|
23
22
|
spec.add_development_dependency "bundler"
|
24
23
|
spec.add_development_dependency "rake"
|
25
24
|
|
26
|
-
spec.add_development_dependency "minitest", "~> 5.4
|
25
|
+
spec.add_development_dependency "minitest", "~> 5.4"
|
27
26
|
|
28
27
|
spec.add_dependency "escpos"
|
29
28
|
spec.add_dependency "chunky_png"
|
data/lib/escpos/image.rb
CHANGED
@@ -1,15 +1,21 @@
|
|
1
1
|
module Escpos
|
2
2
|
class Image
|
3
3
|
|
4
|
-
VERSION = "0.0.
|
5
|
-
|
6
|
-
def initialize(
|
7
|
-
if
|
8
|
-
|
9
|
-
|
10
|
-
|
4
|
+
VERSION = "0.0.4"
|
5
|
+
|
6
|
+
def initialize(image_or_path, opts = {})
|
7
|
+
if image_or_path.is_a?(ChunkyPNG::Image)
|
8
|
+
@image = image_or_path
|
9
|
+
elsif image_or_path.is_a?(String)
|
10
|
+
if opts.fetch(:convert_to_monochrome, false)
|
11
|
+
require_mini_magick!
|
12
|
+
image = convert_to_monochrome(image_or_path, opts)
|
13
|
+
@image = ChunkyPNG::Image.from_file(image.path)
|
14
|
+
else
|
15
|
+
@image = ChunkyPNG::Image.from_file(image_or_path)
|
16
|
+
end
|
11
17
|
else
|
12
|
-
|
18
|
+
raise ArgumentError.new("Image must be a path or a ChunkyPNG::Image object.")
|
13
19
|
end
|
14
20
|
|
15
21
|
unless @image.width % 8 == 0 && @image.height % 8 == 0
|
@@ -25,17 +31,14 @@ module Escpos
|
|
25
31
|
|
26
32
|
0.upto(@image.height - 1) do |y|
|
27
33
|
0.upto(@image.width - 1) do |x|
|
28
|
-
|
29
|
-
|
30
|
-
ChunkyPNG::Color.
|
31
|
-
ChunkyPNG::Color.
|
32
|
-
ChunkyPNG::Color.
|
33
|
-
px = (r +
|
34
|
+
px = ChunkyPNG::Color.to_grayscale(@image.get_pixel(x, y))
|
35
|
+
r, g, b =
|
36
|
+
ChunkyPNG::Color.r(px),
|
37
|
+
ChunkyPNG::Color.g(px),
|
38
|
+
ChunkyPNG::Color.b(px)
|
39
|
+
px = (r + b + g) / 3
|
34
40
|
# Alpha is flattened with convert_to_monochrome option
|
35
|
-
|
36
|
-
raise ArgumentError.new("PNG images with alpha are not supported. Use \"convert_to_monochrome\" to flatten it.")
|
37
|
-
end
|
38
|
-
value = px > 128 ? 255 : 0
|
41
|
+
value = px >= 128 ? 255 : 0
|
39
42
|
value = (value << 8) | value
|
40
43
|
temp |= mask if value == 0
|
41
44
|
mask = mask >> 1
|
@@ -71,7 +74,7 @@ module Escpos
|
|
71
74
|
begin
|
72
75
|
require 'mini_magick'
|
73
76
|
rescue LoadError => e
|
74
|
-
raise
|
77
|
+
raise "Required options need the mini_magick gem installed: #{e}."
|
75
78
|
end
|
76
79
|
end
|
77
80
|
end
|
@@ -1,6 +1,6 @@
|
|
1
1
|
require_relative '../../test_helper'
|
2
2
|
|
3
|
-
class
|
3
|
+
class ImageTest < Minitest::Test
|
4
4
|
def setup
|
5
5
|
@printer = Escpos::Printer.new
|
6
6
|
end
|
@@ -13,7 +13,7 @@ class TestPrinter < Minitest::Test
|
|
13
13
|
@printer.write "\n" * 10
|
14
14
|
@printer.cut!
|
15
15
|
image.chunky_png_image.save(File.join(__dir__, "../../results/#{__method__}.png"))
|
16
|
-
assert_equal @printer.to_base64, 'G0AddjAAEACYAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA//gAAAAAAAAAAAAAAAAAD///AAAAAAAAAAAAAAAAAD///8AAAAAAAAAAAAAAAAD////gAAAAAAAAAAAAAAAB////+AAAAAAAAAAAAAAAA/////wAAAAAAAAAAAAAAAf////+AAAAAAAAAAAAAAAP/////gAAAAAAAAAAAAAAH/////8AAAAAAAAAAAAAAB//////gAAAAAAAAAAAAAA//////4AAAAAAAAAAAAAAP//////AAAAAAAAAAAAAAH//////wAAAAAAAAAAAAAB//////8AAAAAAAAAAAAAAf//////gAAAAAAAAAAAAAP//////4AAAAAAAAAAAAAD//////+AAAAAAAAAAAAAA///////gAAAAAAAAAAAAAP//////8AAAAAAAAAAAAAD///////AAAAAAAAAAAAAA////D//wAAAAAAAAAAAAAP///
|
16
|
+
assert_equal @printer.to_base64, 'G0AddjAAEACYAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA//gAAAAAAAAAAAAAAAAAD///AAAAAAAAAAAAAAAAAD///8AAAAAAAAAAAAAAAAD////gAAAAAAAAAAAAAAAB////+AAAAAAAAAAAAAAAA/////wAAAAAAAAAAAAAAAf////+AAAAAAAAAAAAAAAP/////gAAAAAAAAAAAAAAH/////8AAAAAAAAAAAAAAB//////gAAAAAAAAAAAAAA//////4AAAAAAAAAAAAAAP//////AAAAAAAAAAAAAAH//////wAAAAAAAAAAAAAB//////8AAAAAAAAAAAAAAf//////gAAAAAAAAAAAAAP//////4AAAAAAAAAAAAAD//////+AAAAAAAAAAAAAA///////gAAAAAAAAAAAAAP//////8AAAAAAAAAAAAAD///////AAAAAAAAAAAAAA////D//wAAAAAAAAAAAAAP///AP/8AAAAAAAAAAAAAH4P/gB//AAAAAAAAAAAAAB8B/wAf/wAAAAAAAAAAAAAfAP8AD/8AAAAAAAAAAAAAHgD+AA//AAAAAAAAAAAAAB4AfgwH/4AAAAAAAAAAAAAeEHweB/+AAAAAAAAAAAAAHjh8Hwf/gAAAAAAAAAAAAA48fD8H/4AAAAAAAAAAAAAOfHw/B/+AAAAAAAAAAAAADnx+Pwf/gAAAAAAAAAAAAA5/w/8H/4AAAAAAAAAAAAAOPgB/B/+AAAAAAAAAAAAADjwAHw//gAAAAAAAAAAAAA8YAAcP/4AAAAAAAAAAAAAPsAAB//+AAAAAAAAAAAAAD8A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AAAB/////gAAAGAAAB8AAAAAA/////4AAADAAAAH/wAAAAP/gAf/AAABgAAAAH/4AAAD4AAAAwAAAwAAAAAAfgAABgAAAAMAAAYAAAAAAAeAAA4AAAABgAAMAAAAAAAB8AAcAAAAAcAAOAAAAAAAAH4AeAAAAADAAHAAAAAAAAAP/+AAAAAAcAHgAAAAAAAAAf+AAAAAADwPgAAAAAAAAAAAAAAAAAAf/gAAAAAAAAAAAAAAAAAAA/AAAAAAAAAAAAAAAAAAAAAAAAAAACgoKCgoKCgoKCh1WAA=='
|
17
17
|
end
|
18
18
|
|
19
19
|
def test_image_conversion
|
Binary file
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: escpos-image
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jan Svoboda
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2019-02-19 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -44,14 +44,14 @@ dependencies:
|
|
44
44
|
requirements:
|
45
45
|
- - "~>"
|
46
46
|
- !ruby/object:Gem::Version
|
47
|
-
version: 5.4
|
47
|
+
version: '5.4'
|
48
48
|
type: :development
|
49
49
|
prerelease: false
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
52
|
- - "~>"
|
53
53
|
- !ruby/object:Gem::Version
|
54
|
-
version: 5.4
|
54
|
+
version: '5.4'
|
55
55
|
- !ruby/object:Gem::Dependency
|
56
56
|
name: escpos
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
@@ -90,6 +90,7 @@ extensions: []
|
|
90
90
|
extra_rdoc_files: []
|
91
91
|
files:
|
92
92
|
- ".gitignore"
|
93
|
+
- ".gitlab-ci.yml"
|
93
94
|
- Gemfile
|
94
95
|
- README.md
|
95
96
|
- Rakefile
|
@@ -124,8 +125,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
124
125
|
- !ruby/object:Gem::Version
|
125
126
|
version: '0'
|
126
127
|
requirements: []
|
127
|
-
|
128
|
-
rubygems_version: 2.6.8
|
128
|
+
rubygems_version: 3.0.2
|
129
129
|
signing_key:
|
130
130
|
specification_version: 4
|
131
131
|
summary: A ruby implementation of ESC/POS (thermal) printer image command specification.
|