image_util 0.3.0 → 0.4.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 +5 -0
- data/README.md +8 -6
- data/lib/image_util/codec/image_magick.rb +7 -12
- data/lib/image_util/color.rb +1 -1
- data/lib/image_util/filter/_mixin.rb +9 -0
- data/lib/image_util/filter/background.rb +3 -0
- data/lib/image_util/filter/resize.rb +3 -0
- data/lib/image_util/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: 893e648382567326c70c82a4b3e3b6580889229c9d56c7a20ec4d182b45332b4
|
4
|
+
data.tar.gz: 70fd8a63b0551a0aaca12dae391c076fb01621443ec1ae5e5f92c680655277f2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 89a0a3bf90307337674acae7e1315505bc4a8363e58c041388dc6e6beeaab3f03e4534d2ff41e9a97c23f5775e62db6ebe5493658ac2b81e06f3a650a197d28a
|
7
|
+
data.tar.gz: 6b425b6539c389431e78cdc98744a82888a3f55e0fdeed64062bf69a3e0448fec84e83264b3dd1380133a5adafa87e5751dd36595c7c3dc413e4ead3173d21ae
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,8 @@
|
|
1
|
+
## [0.4.0] - 2025-10-04
|
2
|
+
- BREAKING: Float color components now share the 0..255 range with integers instead of being scaled from 0..1.
|
3
|
+
- Add `define_mutable_version` helper to create bang versions from immutable methods
|
4
|
+
- Add `background!` and `resize!` filters
|
5
|
+
|
1
6
|
## [0.3.0] - 2025-07-25
|
2
7
|
- Rename `dither!` to `palette_reduce!`
|
3
8
|
- Rename `#set_each_pixel_by_location` to `#set_each_pixel_by_location!` since it's mutable
|
data/README.md
CHANGED
@@ -96,13 +96,13 @@ the earlier system packages. Both Kitty and SIXEL outputs also accept one-dimens
|
|
96
96
|
- Symbols or strings containing CSS color names (`:rebeccapurple`, 'papayawhip')
|
97
97
|
- Hex strings like `'#abc'`, `'#aabbcc'` or `'#rrggbbaa'`
|
98
98
|
|
99
|
-
When numeric components are given,
|
100
|
-
range
|
101
|
-
|
102
|
-
If the alpha channel is omitted it defaults to `255`.
|
99
|
+
When numeric components are given, values are clamped directly to the `0..255`
|
100
|
+
range regardless of whether they are integers or floats. Floating point inputs
|
101
|
+
are no longer scaled from `0..1`; instead they are treated in the same units as
|
102
|
+
integers. If the alpha channel is omitted it defaults to `255`.
|
103
103
|
|
104
104
|
```ruby
|
105
|
-
ImageUtil::Color[
|
105
|
+
ImageUtil::Color[128.5] # => #808080
|
106
106
|
ImageUtil::Color[:red] # => #ff0000
|
107
107
|
ImageUtil::Color["#fc0"] # => #ffcc00
|
108
108
|
```
|
@@ -177,7 +177,8 @@ Flatten an RGBA image on a solid color.
|
|
177
177
|
img = ImageUtil::Image.new(128, 128) { |x, y| [255, 0, 0, x + y] }
|
178
178
|
|
179
179
|
# put it on a blue background
|
180
|
-
img.background([0, 0, 255])
|
180
|
+
img.background!([0, 0, 255])
|
181
|
+
# img.background([0, 0, 255]) # returns a new image
|
181
182
|
```
|
182
183
|
|
183
184
|

|
@@ -216,6 +217,7 @@ Scale an image to new dimensions.
|
|
216
217
|
img = ImageUtil::Image.new(128, 128) { |x, y| [x, y, 30] }
|
217
218
|
img[20, 20] = img.resize(64, 64)
|
218
219
|
img
|
220
|
+
# img.resize!(64, 64) # modifies in place
|
219
221
|
```
|
220
222
|
|
221
223
|

|
@@ -64,20 +64,15 @@ module ImageUtil
|
|
64
64
|
img = img.redimension(img.width, img.height + pad) if pad > 0
|
65
65
|
end
|
66
66
|
pam = Codec::Pam.encode(:pam, img)
|
67
|
-
|
68
|
-
IO.popen(["magick", "pam:-", "#{fmt}:-"], "r+b") do |proc_io|
|
69
|
-
proc_io << pam
|
70
|
-
proc_io.close_write
|
71
|
-
proc_io.read
|
72
|
-
end
|
73
67
|
else
|
74
68
|
frames = image.buffer.last_dimension_split.map { |b| Image.from_buffer(b) }
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
69
|
+
pam = frames.map { |f| Codec::Pam.encode(:pam, f) }.join
|
70
|
+
end
|
71
|
+
|
72
|
+
IO.popen(["magick", "pam:-", "#{fmt}:-"], "r+b") do |proc_io|
|
73
|
+
proc_io << pam
|
74
|
+
proc_io.close_write
|
75
|
+
proc_io.read
|
81
76
|
end
|
82
77
|
end
|
83
78
|
|
data/lib/image_util/color.rb
CHANGED
@@ -11,6 +11,15 @@ module ImageUtil
|
|
11
11
|
end
|
12
12
|
end
|
13
13
|
|
14
|
+
def define_mutable_version(*names)
|
15
|
+
names.each do |name|
|
16
|
+
define_method("#{name}!") do |*args, **kwargs, &block|
|
17
|
+
initialize_from_buffer(public_send(name, *args, **kwargs, &block).buffer)
|
18
|
+
self
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
14
23
|
def axis_to_number(axis)
|
15
24
|
axis = 0 if axis == :x
|
16
25
|
axis = 1 if axis == :y
|
@@ -3,6 +3,7 @@
|
|
3
3
|
module ImageUtil
|
4
4
|
module Filter
|
5
5
|
module Background
|
6
|
+
extend ImageUtil::Filter::Mixin
|
6
7
|
def background(bgcolor)
|
7
8
|
return self if channels == 3
|
8
9
|
|
@@ -18,6 +19,8 @@ module ImageUtil
|
|
18
19
|
end
|
19
20
|
img
|
20
21
|
end
|
22
|
+
|
23
|
+
define_mutable_version :background
|
21
24
|
end
|
22
25
|
end
|
23
26
|
end
|
@@ -3,6 +3,7 @@
|
|
3
3
|
module ImageUtil
|
4
4
|
module Filter
|
5
5
|
module Resize
|
6
|
+
extend ImageUtil::Filter::Mixin
|
6
7
|
def resize(*new_dimensions, view: View::Interpolated)
|
7
8
|
src = self.view(view)
|
8
9
|
|
@@ -15,6 +16,8 @@ module ImageUtil
|
|
15
16
|
src[*src_loc]
|
16
17
|
end
|
17
18
|
end
|
19
|
+
|
20
|
+
define_mutable_version :resize
|
18
21
|
end
|
19
22
|
end
|
20
23
|
end
|
data/lib/image_util/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: image_util
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- hmdne
|
@@ -168,7 +168,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
168
168
|
- !ruby/object:Gem::Version
|
169
169
|
version: '0'
|
170
170
|
requirements: []
|
171
|
-
rubygems_version: 3.6.
|
171
|
+
rubygems_version: 3.6.9
|
172
172
|
specification_version: 4
|
173
173
|
summary: Simple pixel buffers with SIXEL and codec helpers
|
174
174
|
test_files: []
|