zebra-zpl 1.1.0 → 1.1.1

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: faa19461aac4741df172e4172665a34e25d7be83b925e9da52d23a9afe398c13
4
- data.tar.gz: dc6f760289525d0a06654e6b706ca11be6f55d1c5e2baa70b6851104b0a34571
3
+ metadata.gz: 8f71f645c261f13d07c249d0aa2185d0457eb9cd82950bccc7cece4affd4e8ae
4
+ data.tar.gz: 54584c33bbadbc85afdd1d3d6909ed2f97fb310a914fbb06937563c6382699a5
5
5
  SHA512:
6
- metadata.gz: ae75990790ea00a4f036f0c8aa015db79cc6c481988e3f8ba9014f2ff6cf941895c2e875c9149dcf62fe59a457a378447827f8b0e9a5fc51a1a76275bed93704
7
- data.tar.gz: e7895c004ef9ff44b9cd32edbe6d870b58d92fb2970f373f8fe468d8703ede85ccf43cb93cdc932eb1ebb04e363be127a09bbcd30d1c281cb5140b22c62cc233
6
+ metadata.gz: fa31bbcf69048fb620115dfd1e7da60d7c01dc366486019cccefb0d70889c4028676a539375dffec5cface9693fb00f64bf21a97ada1394847710ec60b6cf129
7
+ data.tar.gz: 0c07546694365b8549429e9690de5942f2c161703c3c5691336f44a109906fcabd8b207a123dacef94e93ecabb675011b84afdb23224e7e3497cd0e6b84cb029
data/.gitignore CHANGED
@@ -1,4 +1,4 @@
1
- *.gem
1
+
2
2
  *.rbc
3
3
  .bundle
4
4
  .config
@@ -2,6 +2,10 @@
2
2
 
3
3
  * Your contribution here.
4
4
 
5
+ ### 1.1.1 (12/19/2019)
6
+
7
+ * [#58](https://github.com/bbulpett/zebra-zpl/pull/58): Add access to source `Img2Zpl::Image` object - [@mtking2](https://github.com/mtking2)
8
+
5
9
  ### 1.1.0 (11/04/2019)
6
10
 
7
11
  * [#54](https://github.com/bbulpett/zebra-zpl/pull/54): Fix height bug with ^B commands - [@mtking2](https://github.com/mtking2)
data/README.md CHANGED
@@ -325,7 +325,10 @@ You can also create graphics elements from an image using the `Zebra::Zpl::Image
325
325
  * `black_threshold`: A value between 0 and 1 that sets the darkness threshold which determines how dark a pixel should be in order to become black in the resulting b/w image. Use larger value for a more saturated image and smaller value for a less saturated one. Default: `0.5`
326
326
  * `invert`: set to `true` to invert which pixels are set to black and which are set to white. Default is, depending on the `black_threshold`, dark pixels become black and light pixels become white.
327
327
 
328
+ #### Usage
328
329
  ```ruby
330
+ label = Zebra::Zpl::Label.new width: 600, length: 305, print_speed: 6
331
+
329
332
  image = Zebra::Zpl::Image.new(
330
333
  path: '/path/to/my/image.jpg',
331
334
  position: [100, 50],
@@ -334,6 +337,29 @@ image = Zebra::Zpl::Image.new(
334
337
  rotation: -90,
335
338
  black_threshold: 0.35
336
339
  )
340
+
341
+ label << image
342
+ ```
343
+ **Modifying Images**
344
+
345
+ <p align="center">
346
+ <img src="docs/images/image_manipulation.png" width="500">
347
+ </p>
348
+
349
+ Image elements can also be modified in many ways before being added to the label by calling ImageMagick commands (provided by the [minimagick](https://github.com/minimagick/minimagick) & [img2zpl](https://github.com/mtking2/img2zpl) gems) on the source `Img2Zpl::Image < MiniMagick::Image` object.
350
+
351
+ **Example:** Flattening an image's layers, so it is properly converted, and then trimming out unnecessary white space around the edges:
352
+
353
+ ```ruby
354
+ label = Zebra::Zpl::Label.new width: 600, length: 305, print_speed: 6
355
+ image = Zebra::Zpl::Image.new path: 'path/to/image.png', position: [0, 0]
356
+
357
+ img_src = image.source #=> instance of Img2Zpl::Image < MiniMagick::Image
358
+
359
+ img_src.flatten
360
+ img_src.trim
361
+
362
+ label << image
337
363
  ```
338
364
 
339
365
  ## Options
@@ -143,6 +143,7 @@ image = Zebra::Zpl::Image.new(
143
143
  label << image
144
144
  print_zpl_str('image', label)
145
145
 
146
+ # inverted image
146
147
  label = new_label
147
148
  image = Zebra::Zpl::Image.new(
148
149
  path: File.expand_path('./images/earth.jpg', File.dirname(__FILE__)),
@@ -154,6 +155,33 @@ image = Zebra::Zpl::Image.new(
154
155
  label << image
155
156
  print_zpl_str('image_inverted', label)
156
157
 
158
+ ################################################################################
159
+ # Image Manipulation
160
+ ################################################################################
161
+ label = new_label
162
+ image = Zebra::Zpl::Image.new(
163
+ path: File.expand_path('./images/ruby.png', File.dirname(__FILE__)),
164
+ position: [0, 0],
165
+ width: 305,
166
+ height: 305,
167
+ black_threshold: 0.65
168
+ )
169
+ src = image.source
170
+ src.background('white').flatten
171
+
172
+ # perform edge detection on the image
173
+ MiniMagick::Tool::Convert.new do |convert|
174
+ convert << src.path
175
+ convert << '-colorspace' << 'gray'
176
+ convert << '-edge' << '4'
177
+ convert << '-negate'
178
+ convert << src.path
179
+ end
180
+
181
+ src.trim
182
+
183
+ label << image
184
+ print_zpl_str('image_manipulation', label)
157
185
 
158
186
  ################################################################################
159
187
  # Justification
@@ -15,6 +15,12 @@ module Zebra
15
15
  @path = @img.path
16
16
  end
17
17
 
18
+ def source
19
+ @img
20
+ end
21
+
22
+ alias src source
23
+
18
24
  def width=(value)
19
25
  raise InvalidSizeError.new('Invalid image width') unless value.to_i.positive?
20
26
  @width = value.to_i
@@ -1,5 +1,5 @@
1
1
  module Zebra
2
2
  module Zpl
3
- VERSION = "1.1.0"
3
+ VERSION = '1.1.1'.freeze
4
4
  end
5
5
  end
@@ -61,7 +61,7 @@ describe Zebra::Zpl::Image do
61
61
  end
62
62
  end
63
63
 
64
- describe '#to_zpl' do
64
+ context "instance methods" do
65
65
  let(:valid_attributes) { {
66
66
  path: 'spec/fixtures/default.jpg',
67
67
  position: [50, 50],
@@ -69,45 +69,78 @@ describe Zebra::Zpl::Image do
69
69
  height: 150
70
70
  }}
71
71
  let(:image) { described_class.new valid_attributes }
72
- let(:tokens) { image.to_zpl.split(/(\^[A-Z]+|\,)/).reject{ |e| ['', ',', nil].include?(e) } }
73
72
 
74
- it 'raises an error if the X position is not given' do
75
- qrcode = described_class.new position: [nil, 50]
76
- expect {
77
- qrcode.to_zpl
78
- }.to raise_error(Zebra::Zpl::Printable::MissingAttributeError, "Can't print if the X value is not given")
73
+ describe '#source' do
74
+ it 'returns an Img2Zpl::Image object' do
75
+ expect(image.source.class).to eq Img2Zpl::Image
76
+ end
77
+
78
+ it 'responds to ImageMagick (MiniMagick::Image) commands' do
79
+ attr = valid_attributes
80
+ attr.delete(:width)
81
+ attr.delete(:height)
82
+ img = described_class.new attr
83
+ src = img.src
84
+ expect(src.respond_to?(:resize)).to be true
85
+ expect(src.respond_to?(:trim)).to be true
86
+ expect(src.respond_to?(:crop)).to be true
87
+ expect(src.respond_to?(:flatten)).to be true
88
+ expect(src.respond_to?(:rotate)).to be true
89
+ end
90
+
91
+ it 'properly manipulates the image with ImageMagick (MiniMagick::Image) commands' do
92
+ attr = valid_attributes
93
+ attr.delete(:width)
94
+ attr.delete(:height)
95
+ img = described_class.new attr
96
+
97
+ img.source.resize '123x'
98
+ expect(img.width).to eq 123
99
+ img.source.resize 'x321'
100
+ expect(img.height).to eq 321
101
+ end
79
102
  end
80
103
 
81
- it 'raises an error if the Y position is not given' do
82
- qrcode = described_class.new position: [50, nil]
83
- expect {
84
- qrcode.to_zpl
85
- }.to raise_error(Zebra::Zpl::Printable::MissingAttributeError, "Can't print if the Y value is not given")
104
+ describe '#to_zpl' do
105
+ let(:tokens) { image.to_zpl.split(/(\^[A-Z]+|\,)/).reject{ |e| ['', ',', nil].include?(e) } }
106
+
107
+ it 'raises an error if the X position is not given' do
108
+ qrcode = described_class.new position: [nil, 50]
109
+ expect {
110
+ qrcode.to_zpl
111
+ }.to raise_error(Zebra::Zpl::Printable::MissingAttributeError, "Can't print if the X value is not given")
112
+ end
113
+
114
+ it 'raises an error if the Y position is not given' do
115
+ qrcode = described_class.new position: [50, nil]
116
+ expect {
117
+ qrcode.to_zpl
118
+ }.to raise_error(Zebra::Zpl::Printable::MissingAttributeError, "Can't print if the Y value is not given")
119
+ end
120
+
121
+ it 'raises an error if the path is not given' do
122
+ valid_attributes.delete :path
123
+
124
+ expect {
125
+ image.to_zpl
126
+ }.to raise_error(Zebra::Zpl::Printable::MissingAttributeError, "Can't print if the path is invalid or not given")
127
+ end
128
+
129
+ it "contains the Graphics Field command '^GF'" do
130
+ expect(image.to_zpl).to match /\^GF/
131
+ end
132
+
133
+ it 'contains the X position' do
134
+ expect(tokens[1]).to eq '50'
135
+ end
136
+
137
+ it 'contains the Y position' do
138
+ expect(tokens[2]).to eq '50'
139
+ end
140
+
141
+ it 'contains the properly encoded image' do
142
+ expect(tokens[3..-1].join).to eq '^GFA1079107913:::::K078Q03J07FF8P038I01JFP078I03JF8O0FCI0KFCO0FC001KFEN01FE003LFN01FE003LF8M03FF007LFCM03FF8007LFCM07FF800MFCM0IFC00MFEM0IFC00MFEL01IFE01MFEL01IFE01MFEL03JF01NFL07JF8:01NFL0KFC:01MFEK01KFE00MFEK01LF00MFEK03LF00MFEK07LF8007LFCK07LF8007LFCK0MFC003LF8K0MFC003LFK01MFE001KFEK01NFI0KFCK03NFI07JF8K07NF8I01JFL04N08J07FFCK0FC::::::N01MFE:::::::::::::::::::::::::::::::::::^FS'
143
+ end
86
144
  end
87
-
88
- it 'raises an error if the path is not given' do
89
- valid_attributes.delete :path
90
-
91
- expect {
92
- image.to_zpl
93
- }.to raise_error(Zebra::Zpl::Printable::MissingAttributeError, "Can't print if the path is invalid or not given")
94
- end
95
-
96
- it "contains the Graphics Field command '^GF'" do
97
- expect(image.to_zpl).to match /\^GF/
98
- end
99
-
100
- it 'contains the X position' do
101
- expect(tokens[1]).to eq '50'
102
- end
103
-
104
- it 'contains the Y position' do
105
- expect(tokens[2]).to eq '50'
106
- end
107
-
108
- it 'contains the properly encoded image' do
109
- expect(tokens[3..-1].join).to eq '^GFA1079107913:::::M0FR06L0IFQ07K03IFEP0FK07JFO01F8J01KF8N01F8J03KFCN03FCJ07KFEN03FCJ07LFN07FEJ0MF8M07HFJ0MF8M0IFI01MF8L01IF8I01MFCL01IF8I01MFCL03IFCI03MFCL03IFCI03MFCL07IFEI03MFEL0KF:I03MFEK01KF8:I03MFCK03KFCI01MFCK03KFEI01MFCK07KFEI01MFCK0MFJ0MF8K0MFJ0MF8J01MF8J07LFK01MF8J07KFEK03MFCJ03KFCK03MFEJ01KF8K07MFEK0KFL0OFK03IFEL08M01L0IF8L01F8::::::P03MFC:::::::::::::::::::::::::::::::::::^FS'
110
- end
111
-
112
145
  end
113
146
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: zebra-zpl
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.0
4
+ version: 1.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Barnabas Bulpett
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2019-11-04 00:00:00.000000000 Z
13
+ date: 2019-12-19 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: img2zpl
@@ -122,6 +122,7 @@ files:
122
122
  - docs/images/graphics.png
123
123
  - docs/images/image.png
124
124
  - docs/images/image_inverted.png
125
+ - docs/images/image_manipulation.png
125
126
  - docs/images/images.png
126
127
  - docs/images/justification.png
127
128
  - docs/images/qrcode.png