img2zpl 0.1.3 → 1.0.0
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 +4 -4
- data/CHANGELOG.md +6 -2
- data/README.md +27 -0
- data/lib/img2zpl/image.rb +3 -2
- data/lib/img2zpl/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 5dc00b95a89a63d7e2464f9564224043d229702fa2ee34f867f87588c6ff7446
|
|
4
|
+
data.tar.gz: 32e08dbe2a982507a56d3c71c421bd396351219d44b7e0394eccb50a172048e4
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 4f0a368e1c0caad2bfd9d6ccba1e35104cf3e17a80b72aec71aa58df88f8ede49b63a8addc53c21dc9d82ea6c9bc047bc0642da73d4df18fe90e8cf1891b99f0
|
|
7
|
+
data.tar.gz: 105c15388445dfea07ed5e0b40d5e7f4b4739cb52661ad9f12d68641180d49904bb737de78f5cd657247d5e331aea043fafb8b76948aad27a43371b2eee77eea
|
data/CHANGELOG.md
CHANGED
|
@@ -1,6 +1,10 @@
|
|
|
1
|
-
###
|
|
1
|
+
### v1.0.x (next)
|
|
2
2
|
|
|
3
|
-
* Your contribution here
|
|
3
|
+
* Your contribution here
|
|
4
|
+
|
|
5
|
+
### v1.0.0 (2019/10/31)
|
|
6
|
+
|
|
7
|
+
* [#4](https://github.com/mtking2/img2zpl/pull/4): Add ability to invert images - [@mtking2](https://github.com/mtking2).
|
|
4
8
|
|
|
5
9
|
### v0.1.3 (2019/10/16)
|
|
6
10
|
|
data/README.md
CHANGED
|
@@ -27,6 +27,33 @@ img = Img2Zpl::Image.open('foo.jpg')
|
|
|
27
27
|
zpl = img.to_zpl #=> "^GFA, ... ^FS"
|
|
28
28
|
```
|
|
29
29
|
|
|
30
|
+
#### Using ImageMagick commands
|
|
31
|
+
|
|
32
|
+
The `Img2Zpl::Image` class inherits from the `MiniMagick::Image` class provied by the [minimagick](https://github.com/minimagick/minimagick) gem. So you have the same control when it comes to modifying the image before converting to ZPL.
|
|
33
|
+
|
|
34
|
+
**Example**:
|
|
35
|
+
```ruby
|
|
36
|
+
img = Img2Zpl::Image.open('foo.jpg')
|
|
37
|
+
|
|
38
|
+
img.resize '100x100'
|
|
39
|
+
img.trim
|
|
40
|
+
|
|
41
|
+
zpl = img.to_zpl
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
#### Options
|
|
45
|
+
|
|
46
|
+
When calling the `.to_zpl` method there a number of optional parameters you can pass to further customize the resulting image:
|
|
47
|
+
|
|
48
|
+
- `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`
|
|
49
|
+
- `invert`: set to `true` to invert which pixels are set to black and which are set to white.
|
|
50
|
+
- `compress`: set to `false` to not perform the ACSII compression in the resulting `^GF` string. For larger images the uncompressed string can become **very** long, so use caution.
|
|
51
|
+
|
|
52
|
+
**Example**:
|
|
53
|
+
```ruby
|
|
54
|
+
zpl = img.to_zpl black_threshold: 0.65, invert: true
|
|
55
|
+
```
|
|
56
|
+
|
|
30
57
|
### Contributing
|
|
31
58
|
|
|
32
59
|
See [CONTRIBUTING.md](CONTRIBUTING.md)
|
data/lib/img2zpl/image.rb
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
module Img2Zpl
|
|
2
2
|
class Image < MiniMagick::Image
|
|
3
3
|
|
|
4
|
-
def to_zpl(black_threshold: 0.5, compress: true)
|
|
4
|
+
def to_zpl(black_threshold: 0.5, invert: false, compress: true)
|
|
5
5
|
bytes_per_row = (width % 8).positive? ? (width / 8) + 1 : (width / 8)
|
|
6
6
|
byte_count = bytes_per_row * height
|
|
7
7
|
data, line, previous_line, byte = '', '', '', ''
|
|
@@ -9,7 +9,8 @@ module Img2Zpl
|
|
|
9
9
|
get_pixels.each do |row|
|
|
10
10
|
row.each_with_index do |column, i|
|
|
11
11
|
r, g, b = column.map(&:to_i)
|
|
12
|
-
|
|
12
|
+
b_dot, w_dot = invert ? %w(1 0) : %w(0 1)
|
|
13
|
+
byte << ((r + g + b) > (black_threshold * 765) ? b_dot : w_dot)
|
|
13
14
|
if (i % 8).zero?
|
|
14
15
|
line << byte.to_i(2).to_s(16).upcase.rjust(2, '0')
|
|
15
16
|
byte = ''
|
data/lib/img2zpl/version.rb
CHANGED
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: img2zpl
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.
|
|
4
|
+
version: 1.0.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Michael King
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2019-10-
|
|
11
|
+
date: 2019-10-31 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: mini_magick
|