escpos-image 0.0.7 → 0.0.8

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: cbbe37a75125cdbe23b571c0fcc3448653c57d6758f9ac2e8caaaa4b8a87daae
4
- data.tar.gz: 6385051a04e48cf6223b71228ca7789f057a405515d9d6bb47ab0bd9c902cf10
3
+ metadata.gz: 8d5e07c912a9b88b1f75b69a33954270325f8ff465b89064b88053a596fdd903
4
+ data.tar.gz: 521eeedfcd527fa8bc2c64f07b868ceb35c07c52757fb5bf80be3741687be446
5
5
  SHA512:
6
- metadata.gz: 3aec5d8f102a05c66f0123d1e0b1a7e12b4901701501cc86362003c29b542ebf5d8ecc4c632e593e10a57c2bb3fe78151983cd3383c470e66582dfe4f799968b
7
- data.tar.gz: a40b937a4af26c5ae40d032862ba99d395237ca6f0f7160d45a22a4857019adf1be1a2c75491986cccdf5f56e6982091dcc4951332550355b4115ea18f148e45
6
+ metadata.gz: 2e054e569dd6c19d3e1314e16f1569c11ef7e5726770e5f991c7bf3405c7b6a5d9891e629e0320f6c71bc7a0961b57041cad0da37fe8e5fd04b279f3dea64c03
7
+ data.tar.gz: 6472c2f646b0f34de07a8e62df0d9b1e152c5211032a7d2490e90a41cc12e6c76f19da9f70959c3158322d5ef97f6a5a06a1d0eb83a1efd7a95a7ddf0251b5e8
data/README.md CHANGED
@@ -26,28 +26,18 @@ Or install it yourself as:
26
26
 
27
27
  ```ruby
28
28
  @printer = Escpos::Printer.new
29
- image = Escpos::Image.new 'path/to/image.png'
30
29
 
31
- # Recommended usage for best results:
32
- # Supports all mini_magick formats
33
- # Converts the image to monochrome, applies dithering and blends alpha
34
- # Requires the mini_magick gem installed
30
+ # Creating image from path
35
31
  image = Escpos::Image.new 'path/to/image.png', {
36
- convert_to_monochrome: true,
37
- dither: true, # default
38
- extent: true, # default
32
+ processor: "ChunkyPng" # default or MiniMagick
33
+ # ... other options, see following sections
39
34
  }
40
35
 
41
- # Alternative usage:
42
- # Supports only PNG images
43
- # Does NOT require the mini_magick gem installed
44
- image = Escpos::Image.new 'path/to/image.png', {
45
- compose_alpha: true, # default
46
- compose_alpha_bg: 255, # default, assumes white background
47
- }
36
+ # The MiniMagick processor requires the mini_magick gem installed
37
+
38
+ # The constructor also accepts an instance of ChunkyPNG::Image or MiniMagick::Image
48
39
 
49
- @printer.write image.to_escpos
50
- @printer.write image # version 0.0.7 and up
40
+ @printer << image
51
41
 
52
42
  @printer.to_escpos # returns ESC/POS data ready to be sent to printer
53
43
  # on linux this can be piped directly to /dev/usb/lp0
@@ -57,6 +47,32 @@ image = Escpos::Image.new 'path/to/image.png', {
57
47
  @printer.to_base64 # returns base64 encoded ESC/POS data
58
48
  ```
59
49
 
50
+ ## Supported formats
51
+
52
+ | ChunkyPng | MiniMagick |
53
+ | --- | --- |
54
+ | PNG | PNG, JPG, BMP, ... (everything supported by MiniMagick) |
55
+
56
+ When using MiniMagick processor, `mini_magick` gem has to be installed or added to the Gemfile, this makes the gem more lightweight by making this dependency optional.
57
+
58
+ ## Image manipulation
59
+
60
+ All options in the following section are optional and opt-in. By default we only take the RGB value from each pixel, average the sum of the components and make the resulting pixel black if the average is under or equal to 128 and white if it is 129 and up.
61
+
62
+ ## Supported options
63
+
64
+ | Option | ChunkyPng | MiniMagick | Possible values | Default | Description |
65
+ | --- | :---: | :---: | --- | --- | --- |
66
+ | dither | ❌ | ✅ | true/false | false | Apply [dithering](https://en.wikipedia.org/wiki/Dither) to the image |
67
+ | rotate | ❌ | ✅ | String | none | Apply rotation, accepts any MiniMagick valid string |
68
+ | resize | ❌ | ✅ | String | none | Apply resize, accepts any MiniMagick valid string |
69
+ | grayscale | ✅ | ✅ | true/false | false | Convert image to grayscale (mimics the relative perceptual RGB color sensitivity of the human eye) |
70
+ | extent | ✅ | ✅ | true/false | false | Scale the image to nice round dimensions divisible by 8 (required unless input image meets it) |
71
+ | compose_alpha | ✅ | ✅ | true/false | false | Blend alpha into the image (assumes white background by default) |
72
+ | compose_alpha_bg_r | ✅ | ✅ | 0-255 | 255 | Value of the red component of the background when blending alpha |
73
+ | compose_alpha_bg_g | ✅ | ✅ | 0-255 | 255 | Value of the green component of the background when blending alpha |
74
+ | compose_alpha_bg_b | ✅ | ✅ | 0-255 | 255 | Value of the blue component of the background when blending alpha |
75
+
60
76
  ## Contributing
61
77
 
62
78
  Bug reports and pull requests are welcome on GitHub at https://github.com/escpos/escpos-image.
data/escpos-image.gemspec CHANGED
@@ -25,6 +25,6 @@ Gem::Specification.new do |spec|
25
25
  spec.add_development_dependency "minitest", "~> 5.4"
26
26
  spec.add_development_dependency "mini_magick"
27
27
 
28
- spec.add_dependency "escpos", ">= 0.0.7"
28
+ spec.add_dependency "escpos", ">= 0.0.9"
29
29
  spec.add_dependency "chunky_png"
30
30
  end
@@ -0,0 +1,21 @@
1
+ module Escpos
2
+
3
+ class DimensionsMustBeMultipleOf8 < ArgumentError
4
+ def message
5
+ "Image width and height must be a multiple of 8 or the option \"extent\" must be set to true."
6
+ end
7
+ end
8
+
9
+ class InputNotSupported < ArgumentError
10
+ def message
11
+ "Image must be a path or an instance of ChunkyPNG::Image or MiniMagick::Image."
12
+ end
13
+ end
14
+
15
+ class MiniMagickNotInstalled < LoadError
16
+ def message
17
+ "Required options need the mini_magick gem installed: #{e}."
18
+ end
19
+ end
20
+
21
+ end
@@ -1,5 +1,6 @@
1
1
  module Escpos
2
2
  module Helpers
3
+ extend self
3
4
 
4
5
  def image(path, options = {})
5
6
  Image.new(path, options).to_escpos
data/lib/escpos/image.rb CHANGED
@@ -1,29 +1,30 @@
1
+ require_relative "errors"
2
+ require_relative "image_processors/chunky_png"
3
+ require_relative "image_processors/mini_magick"
4
+
1
5
  module Escpos
6
+
7
+ # Images
8
+ IMAGE = [ 0x1d, 0x76, 0x30, 0x00 ] # Start image pixel data
9
+
2
10
  class Image
3
11
 
4
- VERSION = "0.0.7"
12
+ VERSION = "0.0.8"
5
13
 
6
- attr_reader :options
14
+ attr_reader :processor, :options
7
15
 
8
16
  def initialize(image_or_path, options = {})
9
17
  @options = options
10
- if image_or_path.is_a?(ChunkyPNG::Image)
11
- @image = image_or_path
12
- elsif image_or_path.is_a?(String)
13
- if options.fetch(:convert_to_monochrome, false)
14
- require_mini_magick!
15
- image = convert_to_monochrome(image_or_path)
16
- @image = ChunkyPNG::Image.from_file(image.path)
17
- else
18
- @image = ChunkyPNG::Image.from_file(image_or_path)
19
- end
20
- else
21
- raise ArgumentError.new("Image must be a path or a ChunkyPNG::Image object.")
22
- end
23
18
 
24
- unless @image.width % 8 == 0 && @image.height % 8 == 0
25
- raise ArgumentError.new("Image width and height must be a multiple of 8.")
26
- end
19
+ processor_klass_name = options.fetch(:processor, "ChunkyPng")
20
+ processor_klass = ImageProcessors.const_get(processor_klass_name)
21
+ @processor = processor_klass.new image_or_path, options
22
+
23
+ @processor.process!
24
+ end
25
+
26
+ def chunky_png_image
27
+ processor.chunky_png_image
27
28
  end
28
29
 
29
30
  def to_escpos
@@ -32,22 +33,15 @@ module Escpos
32
33
  i = 0
33
34
  temp = 0
34
35
 
35
- 0.upto(@image.height - 1) do |y|
36
- 0.upto(@image.width - 1) do |x|
37
- px = ChunkyPNG::Color.to_grayscale(@image.get_pixel(x, y))
38
- r, g, b, a =
36
+ 0.upto(chunky_png_image.height - 1) do |y|
37
+ 0.upto(chunky_png_image.width - 1) do |x|
38
+ px = chunky_png_image.get_pixel(x, y)
39
+ r, g, b =
39
40
  ChunkyPNG::Color.r(px),
40
41
  ChunkyPNG::Color.g(px),
41
- ChunkyPNG::Color.b(px),
42
- ChunkyPNG::Color.a(px)
43
- px = (r + b + g) / 3
44
- # Alpha is flattened with convert_to_monochrome option
45
- handled_by_mini_magick = options.fetch(:convert_to_monochrome, false)
46
- if !handled_by_mini_magick && options.fetch(:compose_alpha, true)
47
- bg_color = options.fetch(:compose_alpha_bg, 255)
48
- a_quot = a / 255.0
49
- px = (((1 - a_quot) * bg_color) + (a_quot * px)).to_i
50
- end
42
+ ChunkyPNG::Color.b(px)
43
+
44
+ px = (r + b + g) / 3
51
45
  value = px >= 128 ? 255 : 0
52
46
  value = (value << 8) | value
53
47
  temp |= mask if value == 0
@@ -64,64 +58,10 @@ module Escpos
64
58
 
65
59
  [
66
60
  Escpos.sequence(IMAGE),
67
- [@image.width / 8, @image.height ].pack("SS"),
61
+ [ chunky_png_image.width / 8, chunky_png_image.height ].pack("SS"),
68
62
  bits.pack("C*")
69
63
  ].join
70
64
  end
71
65
 
72
- def chunky_png_image
73
- @image
74
- end
75
-
76
- private
77
-
78
- # !!!
79
- # Please note that MiniMagick gem is not required _intentionally_
80
- # This makes the gem more lightweight by making this dependency optional
81
- # !!!
82
- def require_mini_magick!
83
- unless defined?(MiniMagick)
84
- begin
85
- require 'mini_magick'
86
- rescue LoadError => e
87
- raise "Required options need the mini_magick gem installed: #{e}."
88
- end
89
- end
90
- end
91
-
92
- def convert_to_monochrome(image_path)
93
- image = MiniMagick::Image.open(image_path)
94
-
95
- # Flatten transparency
96
- image.flatten
97
-
98
- # Get the first image out of animated gifs
99
- image.collapse!
100
-
101
- # Optimise more actions to single call
102
- image.combine_options do |c|
103
- c.rotate options.fetch(:rotate) if options.has_key?(:rotate)
104
- c.resize options.fetch(:resize) if options.has_key?(:resize)
105
- c.grayscale 'Rec709Luma'
106
- if options.fetch(:dither, true)
107
- c.monochrome '+dither'
108
- # dither the image with FloydSteinberg algoritm for better results
109
- c.dither 'FloydSteinberg'
110
- else
111
- c.monochrome '+dither' # + operator disables dithering
112
- end
113
- end
114
-
115
- # Limit the extent of the image to nice round numbers
116
- if options.fetch(:extent, true)
117
- image.extent "#{(image.width/8.0).round*8}x#{(image.height/8.0).round*8}"
118
- end
119
-
120
- # Force PNG format so ChunkyPNG works
121
- image.format 'png'
122
-
123
- image
124
- end
125
-
126
66
  end
127
67
  end
@@ -0,0 +1,23 @@
1
+ module Escpos
2
+ module ImageProcessors
3
+ class Base
4
+
5
+ attr_reader :image, :options
6
+
7
+ def initialize(image_or_path, options = {})
8
+ @options = options
9
+ assert_options!
10
+ end
11
+
12
+ # Require correct dimensions if auto resizing is not enabled
13
+ def assert_dimensions_multiple_of_8!
14
+ unless options.fetch(:extent, false)
15
+ unless image.width % 8 == 0 && image.height % 8 == 0
16
+ raise DimensionsMustBeMultipleOf8
17
+ end
18
+ end
19
+ end
20
+
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,66 @@
1
+ require_relative "base"
2
+
3
+ module Escpos
4
+ module ImageProcessors
5
+ class ChunkyPng < Base
6
+
7
+ def initialize(image_or_path, options = {})
8
+ @image = begin
9
+ if image_or_path.is_a?(ChunkyPNG::Image)
10
+ image_or_path
11
+ elsif image_or_path.is_a?(String)
12
+ ChunkyPNG::Image.from_file(image_or_path)
13
+ else
14
+ raise InputNotSupported
15
+ end
16
+ end
17
+
18
+ super
19
+ end
20
+
21
+ def chunky_png_image
22
+ @image
23
+ end
24
+
25
+ def assert_options!
26
+ assert_dimensions_multiple_of_8!
27
+ end
28
+
29
+ def process!
30
+ extent = options.fetch(:extent, false)
31
+ compose_alpha = options.fetch(:compose_alpha, false)
32
+ grayscale = options.fetch(:extent, false)
33
+
34
+ if extent
35
+ new_width = (image.width / 8.0).round * 8
36
+ new_height = (image.height / 8.0).round * 8
37
+ image.resample_nearest_neighbor!(new_width, new_height)
38
+ end
39
+
40
+ return if !compose_alpha && !grayscale
41
+
42
+ if compose_alpha
43
+ bg_r, bg_g, bg_b =
44
+ options.fetch(:compose_alpha_bg_r, 255),
45
+ options.fetch(:compose_alpha_bg_g, 255),
46
+ options.fetch(:compose_alpha_bg_b, 255)
47
+ end
48
+
49
+ 0.upto(image.height - 1) do |y|
50
+ 0.upto(image.width - 1) do |x|
51
+ px = image.get_pixel(x, y)
52
+ if compose_alpha
53
+ bg_color = ChunkyPNG::Color.rgb(bg_r, bg_g, bg_b)
54
+ px = ChunkyPNG::Color.compose_quick(px, bg_color)
55
+ end
56
+ if grayscale
57
+ px = ChunkyPNG::Color.to_grayscale(px)
58
+ end
59
+ image.set_pixel(x, y, px)
60
+ end
61
+ end
62
+ end
63
+
64
+ end
65
+ end
66
+ end
@@ -0,0 +1,80 @@
1
+ require_relative "base"
2
+
3
+ module Escpos
4
+ module ImageProcessors
5
+ class MiniMagick < Base
6
+
7
+ def initialize(image_or_path, options = {})
8
+ require_mini_magick!
9
+
10
+ @image = begin
11
+ if image_or_path.is_a?(::MiniMagick::Image)
12
+ image_or_path
13
+ elsif image_or_path.is_a?(String)
14
+ ::MiniMagick::Image.open(image_or_path)
15
+ else
16
+ raise InputNotSupported
17
+ end
18
+ end
19
+
20
+ super
21
+ end
22
+
23
+ def chunky_png_image
24
+ ChunkyPNG::Image.from_file @image.path
25
+ end
26
+
27
+ def assert_options!
28
+ assert_dimensions_multiple_of_8!
29
+ end
30
+
31
+ # MiniMagick gem is not required intentionally
32
+ # This makes the gem more lightweight by making this dependency optional
33
+ def require_mini_magick!
34
+ return if defined?(::MiniMagick)
35
+ require "mini_magick"
36
+ rescue LoadError => e
37
+ raise MiniMagickNotInstalled
38
+ end
39
+
40
+ def process!
41
+ if options.fetch(:compose_alpha, false)
42
+ image.combine_options do |c|
43
+ bg_r, bg_g, bg_b =
44
+ options.fetch(:compose_alpha_bg_r, 255),
45
+ options.fetch(:compose_alpha_bg_g, 255),
46
+ options.fetch(:compose_alpha_bg_b, 255)
47
+ c.background "rgb(#{bg_r},#{bg_g},#{bg_b})"
48
+ c.flatten
49
+ end
50
+ end
51
+
52
+ # Get the first image out of animated gifs
53
+ image.collapse!
54
+
55
+ # Optimise more actions to single call
56
+ image.combine_options do |c|
57
+ c.rotate options.fetch(:rotate) if options.has_key?(:rotate)
58
+ c.resize options.fetch(:resize) if options.has_key?(:resize)
59
+
60
+ c.grayscale('Rec709Luma') if options.fetch(:grayscale, false)
61
+
62
+ if options.fetch(:dither, false)
63
+ c.monochrome '+dither'
64
+ # dither the image with FloydSteinberg algoritm for better results
65
+ c.dither 'FloydSteinberg'
66
+ end
67
+ end
68
+
69
+ # Limit the extent of the image to nice round numbers
70
+ if options.fetch(:extent, false)
71
+ image.extent "#{(image.width/8.0).round*8}x#{(image.height/8.0).round*8}"
72
+ end
73
+
74
+ # Force PNG format so ChunkyPNG works
75
+ image.format 'png'
76
+ end
77
+
78
+ end
79
+ end
80
+ end
@@ -9,24 +9,29 @@ class ImageTest < Minitest::Test
9
9
  image_path = File.join(__dir__, '../../fixtures/tux_mono.png')
10
10
  image = Escpos::Image.new image_path
11
11
 
12
- @printer.write image
13
- @printer.write "\n" * 10
12
+ @printer << image
13
+ @printer << "\n" * 10
14
14
  @printer.cut!
15
15
  image.chunky_png_image.metadata = {}
16
16
  image.chunky_png_image.save(File.join(__dir__, "../../results/#{__method__}.png"))
17
- 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/4AAAAAAAAAAAAA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AAAAAA4BgAAAAAAcAAAA/gAAAAAcAwAAAAAAHwAAA/wAAAAAcAMAAAAAAA/AAB/8AAAAAcADAAAAAAAP/AH//AAAAAcAAwAAAAAAD/////wAAAAcAAOAAAAAAAf////8AAAAcAABgAAAAAAH////+AAAAOAAAMAAAAAAB/////gAAAGAAAB8AAAAAA/////4AAADAAAAH/wAAAAP/gAf/AAABgAAAAH/4AAAD4AAAAwAAAwAAAAAAfgAABgAAAAMAAAYAAAAAAAeAAA4AAAABgAAMAAAAAAAB8AAcAAAAAcAAOAAAAAAAAH4AeAAAAADAAHAAAAAAAAAP/+AAAAAAcAHgAAAAAAAAAf+AAAAAADwPgAAAAAAAAAAAAAAAAAAf/gAAAAAAAAAAAAAAAAAAA/AAAAAAAAAAAAAAAAAAAAAAAAAAACgoKCgoKCgoKCh1WAA=='
17
+ file = File.join(__dir__, "../../results/#{__method__}.txt")
18
+ #IO.binwrite file, @printer.to_escpos
19
+ assert_equal IO.binread(file), @printer.to_escpos
18
20
  end
19
21
 
20
22
  def test_image_conversion
21
23
  image_path = File.join(__dir__, '../../fixtures/tux_alpha.png')
22
- image = Escpos::Image.new image_path, convert_to_monochrome: true
24
+ image = Escpos::Image.new image_path, grayscale: true,
25
+ compose_alpha: true, extent: true
23
26
 
24
- @printer.write image.to_escpos
25
- @printer.write "\n" * 10
27
+ @printer << image.to_escpos
28
+ @printer << "\n" * 10
26
29
  @printer.cut!
27
30
  image.chunky_png_image.metadata = {}
28
31
  image.chunky_png_image.save(File.join(__dir__, "../../results/#{__method__}.png"))
29
- assert_equal @printer.to_base64, 'G0AddjAAEACYAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAASAAAAAAAAAAAAAAAAAAAF/+gAAAAAAAAAAAAAAAAAP//+AAAAAAAAAAAAAAAAAP///wAAAAAAAAAAAAAAAAH////AAAAAAAAAAAAAAAAH////4AAAAAAAAAAAAAAAD/////AAAAAAAAAAAAAAAB/////4AAAAAAAAAAAAAAAf/////AAAAAAAAAA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AAwAAcAAAA/+AAAAAAwAAAAMAAOAAAAP/gAAAAAMAAAADAAHAAAAB/8AAAAAGAAAAAwABgAAAAf/gAAAAAwAAAAGAAYAAAAD/4AAAAAYAAAABgAGAAAAA//AAAAADAAAAAcABgAAAAH/wAAAABgAAAADgAYAAAAA/8AAAAAYAAAAAYAGAAAAAP/AAAAAGAAAAADABgAAAAB/gAAAABgAAAAA4AMAAAAAPwAAAAAYAAAAAGAGAAAAABwAAAAAMAAAAAAwAwAAAAAcAAAAADAAAAAAMAYAAAAADgAAAAAwAAAAADADAAAAAAYAAAAAcAAAAAAwBgAAAAADAAAAAOAAAAAAYAYAAAAAA4AAAAHgAAAAAOAOAAAAAAHAAAAH4AAAAAPABAAAAAAA8AAAH8AAAAAHgAwAAAAAAPwAAP/AAAAAPgAMAAAAAAB/wAf/wAAAAHgADAAAAAAAf////8AAAAPgAAwAAAAAAH/////AAAAHgAAGAAAAAAA/////gAAAHgAABwAAAAAAf////8AAADgAAAPgAAAAAH/////AAABwAAAA/+AAAAB/+pf/gAAA4AAAAC//AAAAfoAAK8AAAcAAAAAAH+AAAOAAAADAAAGAAAAAAAH4AAHAAAAAYAAHAAAAAAAAHgADgAAAAHAADgAAAAAAAA/ADwAAAAAwABwAAAAAAAAB/vwAAAAAHAB4AAAAAAAAAH/wAAAAAA8D4AAAAAAAAAABAAAAAAAH/4AAAAAAAAAAAAAAAAAAAPwAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAACgoKCgoKCgoKCh1WAA=='
32
+ file = File.join(__dir__, "../../results/#{__method__}.txt")
33
+ #IO.binwrite file, @printer.to_escpos
34
+ assert_equal IO.binread(file), @printer.to_escpos
30
35
  end
31
36
 
32
37
  end
Binary file
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.7
4
+ version: 0.0.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jan Svoboda
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-02-21 00:00:00.000000000 Z
11
+ date: 2019-02-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -72,14 +72,14 @@ dependencies:
72
72
  requirements:
73
73
  - - ">="
74
74
  - !ruby/object:Gem::Version
75
- version: 0.0.7
75
+ version: 0.0.9
76
76
  type: :runtime
77
77
  prerelease: false
78
78
  version_requirements: !ruby/object:Gem::Requirement
79
79
  requirements:
80
80
  - - ">="
81
81
  - !ruby/object:Gem::Version
82
- version: 0.0.7
82
+ version: 0.0.9
83
83
  - !ruby/object:Gem::Dependency
84
84
  name: chunky_png
85
85
  requirement: !ruby/object:Gem::Requirement
@@ -112,13 +112,19 @@ files:
112
112
  - bin/setup
113
113
  - escpos-image.gemspec
114
114
  - examples/IMG_20160610_232415_HDR.jpg
115
+ - lib/escpos/errors.rb
115
116
  - lib/escpos/helpers.rb
116
117
  - lib/escpos/image.rb
118
+ - lib/escpos/image_processors/base.rb
119
+ - lib/escpos/image_processors/chunky_png.rb
120
+ - lib/escpos/image_processors/mini_magick.rb
117
121
  - test/fixtures/tux_alpha.png
118
122
  - test/fixtures/tux_mono.png
119
123
  - test/lib/escpos/image_test.rb
120
124
  - test/results/test_image.png
125
+ - test/results/test_image.txt
121
126
  - test/results/test_image_conversion.png
127
+ - test/results/test_image_conversion.txt
122
128
  - test/test_helper.rb
123
129
  homepage: https://github.com/escpos/escpos-image
124
130
  licenses:
@@ -148,5 +154,7 @@ test_files:
148
154
  - test/fixtures/tux_mono.png
149
155
  - test/lib/escpos/image_test.rb
150
156
  - test/results/test_image.png
157
+ - test/results/test_image.txt
151
158
  - test/results/test_image_conversion.png
159
+ - test/results/test_image_conversion.txt
152
160
  - test/test_helper.rb