img2zpl 1.0.1 → 1.0.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 5b6d9b924895cd320a4925805a90fafc549c1802154417b3c40de23f521050b6
4
- data.tar.gz: 3edfa63c167c715682b837a141301fdb6a45a8a4cd3fb2a47821e084eef3e779
3
+ metadata.gz: 42a5f5ead2a3e78f171c686741a83b8519a3733576db28546c31aa1b150d62c5
4
+ data.tar.gz: f94755deda19a24575a70aba5ee0df8ba8a749b7b4f336fc493565154357e49c
5
5
  SHA512:
6
- metadata.gz: cb307f865a49b70e95d877d3039530c8b818dd80396f435139549449500739b15cac64e8e6565656c172a5e5237255a32b303ecce35723a1153cb7a2689edbb6
7
- data.tar.gz: e73f9857dfaeeee4e33e552ff24dceed221480b4ef5b6c82693c9e7c5c1b51bb9001a40957ea1ad89693690d0c5508cba7c36600802a5b899bb60685effd82d5
6
+ metadata.gz: ebf7942cf02e5424ee2360eeab8f70984baac265e554071bb7f844fe90770331ff1d9de8fa64100d2db245b2967ad5fce3ddb7d2c969d19fa4128045f14691ec
7
+ data.tar.gz: 2bb8e47222414015978bb52907be65078a772de1231aedfd5165f5f11c9aa8e72acd6939989ee97725c331fde72dfabd2c6a8b03e223b5f132f3aa1ce6b53ceb
data/CHANGELOG.md CHANGED
@@ -1,7 +1,22 @@
1
- ### v1.0.1 (next)
1
+ ### v1.0.4 (next)
2
2
 
3
3
  * Your contribution here
4
4
 
5
+ ### v1.0.3 (2025/08/22)
6
+
7
+ * [#11](https://github.com/mtking2/img2zpl/pull/11): Reduce gem size by excluding test files - [@yuri-zubov](https://github.com/yuri-zubov)
8
+ * [#10](https://github.com/mtking2/img2zpl/pull/10): Fix line mutation - [@DmytroVasin](https://github.com/DmytroVasin)
9
+
10
+ ### v1.0.2 (2025/05/22)
11
+
12
+ * [#9](https://github.com/mtking2/img2zpl/pull/9): Development updates and fixes - [@mtking2](https://github.com/mtking2).
13
+ * added rubocop and linted files
14
+ * added some more binstubs
15
+ * add a Github Actions workflow for linting/testing
16
+ * fix string literal issue [#7](https://github.com/mtking2/img2zpl/issues/7)
17
+ * use unary plus operator to unfreeze string per [rubocop-performance](https://docs.rubocop.org/rubocop-performance/cops_performance.html#performanceunfreezestring) recommendation
18
+ * [#8](https://github.com/mtking2/img2zpl/pull/8): Loosen mini_magick dependency - [@harmdewit](https://github.com/harmdewit).
19
+
5
20
  ### v1.0.1 (2019/11/05)
6
21
 
7
22
  * [#5](https://github.com/mtking2/img2zpl/pull/5): Fix artifact bug & improve compression - [@mtking2](https://github.com/mtking2).
data/lib/img2zpl/image.rb CHANGED
@@ -1,66 +1,70 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Img2Zpl
2
- class Image < MiniMagick::Image
3
4
 
4
- def to_zpl(black_threshold: 0.5, invert: false, compress: true)
5
- bytes_per_row = (width % 8).positive? ? (width / 8) + 1 : (width / 8)
6
- byte_count = bytes_per_row * height
7
- data, line, previous_line, byte = '', '', '', ''
5
+ class Image < MiniMagick::Image
6
+
7
+ def to_zpl(black_threshold: 0.5, invert: false, compress: true)
8
+ bytes_per_row = (width % 8).positive? ? (width / 8) + 1 : (width / 8)
9
+ byte_count = bytes_per_row * height
10
+ data, line, previous_line, byte = Array.new(4) { +"" }
11
+
12
+ get_pixels.each do |row|
13
+ row.each_with_index do |column, i|
14
+ r, g, b = column.map(&:to_i)
15
+ b_dot, w_dot = invert ? %w[1 0] : %w[0 1]
16
+ byte << (((r + g + b) > (black_threshold * 765)) ? b_dot : w_dot)
8
17
 
9
- get_pixels.each do |row|
10
- row.each_with_index do |column, i|
11
- r, g, b = column.map(&:to_i)
12
- b_dot, w_dot = invert ? %w(1 0) : %w(0 1)
13
- byte << ((r + g + b) > (black_threshold * 765) ? b_dot : w_dot)
18
+ if ((i + 1) % 8).zero? || i == (width - 1)
19
+ line_str = byte.ljust(8, "0").to_i(2).to_s(16).upcase.rjust(2, "0")
20
+ line << line_str
21
+ byte = +""
22
+ end
23
+ end
14
24
 
15
- if ((i+1) % 8).zero? || i == (width-1)
16
- line_str = byte.ljust(8, '0').to_i(2).to_s(16).upcase.rjust(2, '0')
17
- line << line_str
18
- byte = ''
19
- end
20
- end
25
+ data << if compress
26
+ ((line == previous_line) ? ":" : line.gsub(/0+$/, ",").gsub(/F+$/, "!"))
27
+ else
28
+ line
29
+ end
21
30
 
22
- data << if compress
23
- (line == previous_line ? ':' : line.gsub(/0+$/, ',').gsub(/F+$/, '!'))
24
- else
25
- line
26
- end
31
+ previous_line = line
32
+ line = +""
33
+ end
27
34
 
28
- previous_line = line
29
- line = ''
30
- end
35
+ _compress(data) if compress
36
+ "^GFA,#{byte_count},#{byte_count},#{bytes_per_row},#{data}^FS"
37
+ end
31
38
 
32
- _compress(data) if compress
33
- "^GFA,#{byte_count},#{byte_count},#{bytes_per_row},#{data}^FS"
34
- end
39
+ private
35
40
 
36
- private
41
+ def _compression_map
42
+ map = {}
43
+ start = "G".ord
44
+ 19.times { |i| map[i + 1] = (start + i).chr }
45
+ start = "g".ord
46
+ (20..400).step(20).each_with_index { |i, j| map[i] = (start + j).chr }
47
+ map
48
+ end
37
49
 
38
- def _compression_map
39
- map = {}
40
- start = 'G'.ord
41
- 19.times { |i| map[i + 1] = (start+i).chr }
42
- start = 'g'.ord
43
- (20..400).step(20).each_with_index { |i, j| map[i] = (start+j).chr }
44
- map
45
- end
50
+ def _reduce(n)
51
+ str = +""
52
+ counts = _compression_map.keys.sort.reverse
53
+ counts.each do |c|
54
+ if c <= n
55
+ str << _compression_map[c]
56
+ n -= c
57
+ end
58
+ end
59
+ str
60
+ end
46
61
 
47
- def _reduce(n)
48
- str = ''
49
- counts = _compression_map.keys.sort.reverse
50
- counts.each do |c|
51
- if c <= n
52
- str << (_compression_map[c])
53
- n -= c
54
- end
55
- end
56
- str
57
- end
62
+ def _compress(data)
63
+ data.gsub!(/([\da-zA-Z])(\1+)/) do |m|
64
+ (m.length == 2) ? m : "#{_reduce(m.length)}#{$1}"
65
+ end
66
+ end
58
67
 
59
- def _compress(data)
60
- data.gsub!(/([\da-zA-Z])(\1+)/) do |m|
61
- m.length == 2 ? m : "#{_reduce(m.length)}#{$1}"
62
- end
63
- end
68
+ end
64
69
 
65
- end
66
70
  end
@@ -1,3 +1,5 @@
1
1
  module Img2Zpl
2
- VERSION = '1.0.1'.freeze
2
+
3
+ VERSION = "1.0.3".freeze
4
+
3
5
  end
data/lib/img2zpl.rb CHANGED
@@ -1,2 +1,2 @@
1
- require 'mini_magick'
2
- require_relative 'img2zpl/image'
1
+ require "mini_magick"
2
+ require_relative "img2zpl/image"
metadata CHANGED
@@ -1,27 +1,26 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: img2zpl
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.1
4
+ version: 1.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Michael King
8
- autorequire:
9
8
  bindir: bin
10
9
  cert_chain: []
11
- date: 2019-11-05 00:00:00.000000000 Z
10
+ date: 2025-08-22 00:00:00.000000000 Z
12
11
  dependencies:
13
12
  - !ruby/object:Gem::Dependency
14
13
  name: mini_magick
15
14
  requirement: !ruby/object:Gem::Requirement
16
15
  requirements:
17
- - - "~>"
16
+ - - ">="
18
17
  - !ruby/object:Gem::Version
19
18
  version: '4.9'
20
19
  type: :runtime
21
20
  prerelease: false
22
21
  version_requirements: !ruby/object:Gem::Requirement
23
22
  requirements:
24
- - - "~>"
23
+ - - ">="
25
24
  - !ruby/object:Gem::Version
26
25
  version: '4.9'
27
26
  - !ruby/object:Gem::Dependency
@@ -53,31 +52,21 @@ dependencies:
53
52
  - !ruby/object:Gem::Version
54
53
  version: '3.9'
55
54
  description: Ruby library to convert images to usable & printable ZPL code
56
- email: mtking1123@gmail.com
55
+ email: m.king@fastmail.com
57
56
  executables: []
58
57
  extensions: []
59
58
  extra_rdoc_files: []
60
59
  files:
61
- - ".gitignore"
62
- - ".rspec"
63
60
  - CHANGELOG.md
64
- - CONTRIBUTING.md
65
- - Gemfile
66
61
  - LICENSE
67
62
  - README.md
68
- - Rakefile
69
- - img2zpl.gemspec
70
63
  - lib/img2zpl.rb
71
64
  - lib/img2zpl/image.rb
72
65
  - lib/img2zpl/version.rb
73
- - spec/fixtures/default.jpg
74
- - spec/img2zpl/image_spec.rb
75
- - spec/spec_helper.rb
76
66
  homepage: https://github.com/mtking2/img2zpl
77
67
  licenses:
78
68
  - MIT
79
69
  metadata: {}
80
- post_install_message:
81
70
  rdoc_options: []
82
71
  require_paths:
83
72
  - lib
@@ -92,11 +81,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
92
81
  - !ruby/object:Gem::Version
93
82
  version: '0'
94
83
  requirements: []
95
- rubygems_version: 3.0.6
96
- signing_key:
84
+ rubygems_version: 3.6.2
97
85
  specification_version: 4
98
86
  summary: Convert images to ZPL
99
- test_files:
100
- - spec/fixtures/default.jpg
101
- - spec/img2zpl/image_spec.rb
102
- - spec/spec_helper.rb
87
+ test_files: []
data/.gitignore DELETED
@@ -1,50 +0,0 @@
1
- *.gem
2
- *.rbc
3
- /.config
4
- /coverage/
5
- /InstalledFiles
6
- /pkg/
7
- /spec/reports/
8
- /spec/examples.txt
9
- /test/tmp/
10
- /test/version_tmp/
11
- /tmp/
12
-
13
- # Used by dotenv library to load environment variables.
14
- # .env
15
-
16
- ## Specific to RubyMotion:
17
- .dat*
18
- .repl_history
19
- build/
20
- *.bridgesupport
21
- build-iPhoneOS/
22
- build-iPhoneSimulator/
23
-
24
- ## Specific to RubyMotion (use of CocoaPods):
25
- #
26
- # We recommend against adding the Pods directory to your .gitignore. However
27
- # you should judge for yourself, the pros and cons are mentioned at:
28
- # https://guides.cocoapods.org/using/using-cocoapods.html#should-i-check-the-pods-directory-into-source-control
29
- #
30
- # vendor/Pods/
31
-
32
- ## Documentation cache and generated files:
33
- /.yardoc/
34
- /_yardoc/
35
- /doc/
36
- /rdoc/
37
-
38
- ## Environment normalization:
39
- /.bundle/
40
- /vendor/bundle
41
- /lib/bundler/man/
42
-
43
- # for a library or gem, you might want to ignore these files since the code is
44
- # intended to run in multiple environments; otherwise, check them in:
45
- Gemfile.lock
46
- # .ruby-version
47
- # .ruby-gemset
48
-
49
- # unless supporting rvm < 1.11.0 or doing something fancy, ignore this:
50
- .rvmrc
data/.rspec DELETED
@@ -1,3 +0,0 @@
1
- --require spec_helper
2
- --format documentation
3
- --color
data/CONTRIBUTING.md DELETED
@@ -1,46 +0,0 @@
1
- ## Contributing
2
-
3
- ### Fork & clone the repository
4
-
5
- ```
6
- git clone git@github.com:<your-username>/img2zpl.git
7
- cd img2zpl
8
- git remote add upstream git@github.com:mtking2/img2zpl.git
9
- bundle install
10
- ```
11
-
12
- Then check out a working branch:
13
-
14
- ```
15
- git checkout -b <my-working-branch>
16
- ```
17
-
18
- ### Write tests
19
-
20
- This project uses `rspec`. After writing your tests, you can run tests with the following command:
21
-
22
- `bundle exec rspec`
23
-
24
-
25
- ### Write code
26
-
27
- Write your code to make your tests pass.
28
-
29
- ### Update the CHANGELOG with a description and your name
30
-
31
- Update the CHANGELOG with the description of your code changes and your name on the line after `"* Your contribution here"`.
32
-
33
- ### Commit and push your changes
34
-
35
- Commit and push your changes to your working branch.
36
-
37
- ```
38
- git commit -am 'Add some feature'
39
- git push origin <my-working-branch>
40
- ```
41
-
42
- ### Open a pull request
43
-
44
- Open a pull request against upstream master and your working branch. Give a brief description of what your PR does and explain what the code changes do.
45
-
46
- Thank you!
data/Gemfile DELETED
@@ -1,9 +0,0 @@
1
- source 'https://rubygems.org'
2
-
3
- group :development, :test do
4
- gem 'byebug'
5
- gem 'pry'
6
- gem 'pry-nav'
7
- end
8
-
9
- gemspec
data/Rakefile DELETED
@@ -1,14 +0,0 @@
1
- require 'rubygems'
2
- require 'bundler'
3
- require 'bundler/gem_tasks'
4
-
5
- Bundler.setup :default, :development
6
-
7
- require 'rspec/core'
8
- require 'rspec/core/rake_task'
9
-
10
- RSpec::Core::RakeTask.new(:spec) do |spec|
11
- spec.pattern = FileList['spec/**/*_spec.rb']
12
- end
13
-
14
- task default: %i[spec]
data/img2zpl.gemspec DELETED
@@ -1,23 +0,0 @@
1
- # coding: utf-8
2
- $LOAD_PATH.push File.expand_path('lib', __dir__)
3
- require 'img2zpl/version'
4
-
5
- Gem::Specification.new do |spec|
6
- spec.name = 'img2zpl'
7
- spec.version = Img2Zpl::VERSION
8
- spec.authors = ['Michael King']
9
- spec.email = 'mtking1123@gmail.com'
10
- spec.summary = 'Convert images to ZPL'
11
- spec.description = 'Ruby library to convert images to usable & printable ZPL code'
12
-
13
- spec.homepage = "https://github.com/mtking2/img2zpl"
14
- spec.license = 'MIT'
15
-
16
- spec.files = `git ls-files`.split($/)
17
- spec.test_files = `git ls-files -- spec/*`.split("\n")
18
- spec.require_paths = ['lib']
19
-
20
- spec.add_dependency 'mini_magick', '~> 4.9'
21
- spec.add_development_dependency 'rake', '~> 13'
22
- spec.add_development_dependency 'rspec', '~> 3.9'
23
- end
Binary file
@@ -1,72 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe Img2Zpl::Image do
4
-
5
- subject { described_class.open('spec/fixtures/default.jpg') }
6
-
7
- it 'should inherit from the MiniMagick::Image class' do
8
- expect(described_class.respond_to?(:open)).to be true
9
- expect(described_class.respond_to?(:read)).to be true
10
- expect(subject.respond_to?(:to_zpl)).to be true
11
- end
12
-
13
- it 'should have the compression map' do
14
- map = subject.send(:_compression_map)
15
- expect(map[1]).to eq 'G'
16
- expect(map[2]).to eq 'H'
17
- expect(map[3]).to eq 'I'
18
- expect(map[4]).to eq 'J'
19
- expect(map[5]).to eq 'K'
20
- expect(map[6]).to eq 'L'
21
- expect(map[7]).to eq 'M'
22
- expect(map[8]).to eq 'N'
23
- expect(map[9]).to eq 'O'
24
- expect(map[10]).to eq 'P'
25
- expect(map[11]).to eq 'Q'
26
- expect(map[12]).to eq 'R'
27
- expect(map[13]).to eq 'S'
28
- expect(map[14]).to eq 'T'
29
- expect(map[15]).to eq 'U'
30
- expect(map[16]).to eq 'V'
31
- expect(map[17]).to eq 'W'
32
- expect(map[18]).to eq 'X'
33
- expect(map[19]).to eq 'Y'
34
- expect(map[20]).to eq 'g'
35
- expect(map[40]).to eq 'h'
36
- expect(map[60]).to eq 'i'
37
- expect(map[80]).to eq 'j'
38
- expect(map[100]).to eq 'k'
39
- expect(map[120]).to eq 'l'
40
- expect(map[140]).to eq 'm'
41
- expect(map[160]).to eq 'n'
42
- expect(map[180]).to eq 'o'
43
- expect(map[200]).to eq 'p'
44
- expect(map[220]).to eq 'q'
45
- expect(map[240]).to eq 'r'
46
- expect(map[260]).to eq 's'
47
- expect(map[280]).to eq 't'
48
- expect(map[300]).to eq 'u'
49
- expect(map[320]).to eq 'v'
50
- expect(map[340]).to eq 'w'
51
- expect(map[360]).to eq 'x'
52
- expect(map[380]).to eq 'y'
53
- expect(map[400]).to eq 'z'
54
- end
55
-
56
- it 'should properly compress ASCII data' do
57
- d1 = '00000000000000000000000000000000000000000000000000000000008'
58
- d2 = '5555555555555ADDDDDDDDDDDDDDDDDDDDDDD'
59
- d3 = '00000000FFFFFFFFFFFFFFFFFFFFFFC0000000000000000000007FFFFFFFFF'
60
- subject.send(:_compress, d1)
61
- subject.send(:_compress, d2)
62
- subject.send(:_compress, d3)
63
- expect(d1).to eq 'hX08'
64
- expect(d2).to eq 'S5AgID'
65
- expect(d3).to eq 'N0gHFCgG07OF'
66
- end
67
-
68
- it 'should return a string when calling .to_zpl' do
69
- expect(subject.to_zpl).to be_kind_of String
70
- end
71
-
72
- end
data/spec/spec_helper.rb DELETED
@@ -1,106 +0,0 @@
1
- # This file was generated by the `rspec --init` command. Conventionally, all
2
- # specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
3
- # The generated `.rspec` file contains `--require spec_helper` which will cause
4
- # this file to always be loaded, without a need to explicitly require it in any
5
- # files.
6
- #
7
- # Given that it is always loaded, you are encouraged to keep this file as
8
- # light-weight as possible. Requiring heavyweight dependencies from this file
9
- # will add to the boot time of your test suite on EVERY test run, even for an
10
- # individual file that may not need all of that loaded. Instead, consider making
11
- # a separate helper file that requires the additional dependencies and performs
12
- # the additional setup, and require it from the spec files that actually need
13
- # it.
14
- #
15
- # See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
16
- require 'img2zpl'
17
- require 'byebug'
18
- require 'pry'
19
- require 'pry-nav'
20
-
21
-
22
- RSpec.configure do |config|
23
- # rspec-expectations config goes here. You can use an alternate
24
- # assertion/expectation library such as wrong or the stdlib/minitest
25
- # assertions if you prefer.
26
- config.expect_with :rspec do |expectations|
27
- # This option will default to `true` in RSpec 4. It makes the `description`
28
- # and `failure_message` of custom matchers include text for helper methods
29
- # defined using `chain`, e.g.:
30
- # be_bigger_than(2).and_smaller_than(4).description
31
- # # => "be bigger than 2 and smaller than 4"
32
- # ...rather than:
33
- # # => "be bigger than 2"
34
- expectations.include_chain_clauses_in_custom_matcher_descriptions = true
35
- end
36
-
37
- # rspec-mocks config goes here. You can use an alternate test double
38
- # library (such as bogus or mocha) by changing the `mock_with` option here.
39
- config.mock_with :rspec do |mocks|
40
- # Prevents you from mocking or stubbing a method that does not exist on
41
- # a real object. This is generally recommended, and will default to
42
- # `true` in RSpec 4.
43
- mocks.verify_partial_doubles = true
44
- end
45
-
46
- # This option will default to `:apply_to_host_groups` in RSpec 4 (and will
47
- # have no way to turn it off -- the option exists only for backwards
48
- # compatibility in RSpec 3). It causes shared context metadata to be
49
- # inherited by the metadata hash of host groups and examples, rather than
50
- # triggering implicit auto-inclusion in groups with matching metadata.
51
- config.shared_context_metadata_behavior = :apply_to_host_groups
52
-
53
- # The settings below are suggested to provide a good initial experience
54
- # with RSpec, but feel free to customize to your heart's content.
55
- =begin
56
- # This allows you to limit a spec run to individual examples or groups
57
- # you care about by tagging them with `:focus` metadata. When nothing
58
- # is tagged with `:focus`, all examples get run. RSpec also provides
59
- # aliases for `it`, `describe`, and `context` that include `:focus`
60
- # metadata: `fit`, `fdescribe` and `fcontext`, respectively.
61
- config.filter_run_when_matching :focus
62
-
63
- # Allows RSpec to persist some state between runs in order to support
64
- # the `--only-failures` and `--next-failure` CLI options. We recommend
65
- # you configure your source control system to ignore this file.
66
- config.example_status_persistence_file_path = "spec/examples.txt"
67
-
68
- # Limits the available syntax to the non-monkey patched syntax that is
69
- # recommended. For more details, see:
70
- # - http://rspec.info/blog/2012/06/rspecs-new-expectation-syntax/
71
- # - http://www.teaisaweso.me/blog/2013/05/27/rspecs-new-message-expectation-syntax/
72
- # - http://rspec.info/blog/2014/05/notable-changes-in-rspec-3/#zero-monkey-patching-mode
73
- config.disable_monkey_patching!
74
-
75
- # This setting enables warnings. It's recommended, but in some cases may
76
- # be too noisy due to issues in dependencies.
77
- config.warnings = true
78
-
79
- # Many RSpec users commonly either run the entire suite or an individual
80
- # file, and it's useful to allow more verbose output when running an
81
- # individual spec file.
82
- if config.files_to_run.one?
83
- # Use the documentation formatter for detailed output,
84
- # unless a formatter has already been configured
85
- # (e.g. via a command-line flag).
86
- config.default_formatter = "doc"
87
- end
88
-
89
- # Print the 10 slowest examples and example groups at the
90
- # end of the spec run, to help surface which specs are running
91
- # particularly slow.
92
- config.profile_examples = 10
93
-
94
- # Run specs in random order to surface order dependencies. If you find an
95
- # order dependency and want to debug it, you can fix the order by providing
96
- # the seed, which is printed after each run.
97
- # --seed 1234
98
- config.order = :random
99
-
100
- # Seed global randomization in this process using the `--seed` CLI option.
101
- # Setting this allows you to use `--seed` to deterministically reproduce
102
- # test failures related to randomization by passing the same `--seed` value
103
- # as the one that triggered the failure.
104
- Kernel.srand config.seed
105
- =end
106
- end