image_util 0.3.0 → 0.5.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 +8 -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/image.rb +4 -8
- data/lib/image_util/inspectable.rb +25 -0
- data/lib/image_util/version.rb +1 -1
- data/lib/image_util.rb +1 -0
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2665eb7733f8fa7dc6e091d09a8ddc3315d0461395fd15aa1eb2c12ca9de9df6
|
4
|
+
data.tar.gz: bc5ced5903fa35dfbe03a05ae6aff8e797ca3c5d39407881c288168f5cbe51d1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: caf2f99b10ff415168c0ac9defc7966d5e374d007a5859eab7580ae0865f6a6bc5203d116e094ca77dbbc26fcc69faaead7869b092297bc4a42749ae2a2f95cd
|
7
|
+
data.tar.gz: 66823c89ef52e3bb5c0927529c4dc99877253047a7659450da0d2a7bd7790944f836656b10c07bbbcb2eae40cb95ad95c694f5d69c2338a526fae36bfddedf21
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,11 @@
|
|
1
|
+
## [0.5.0] - 2025-10-05
|
2
|
+
- Add `ImageUtil::Inspectable` interface for other gems to use
|
3
|
+
|
4
|
+
## [0.4.0] - 2025-10-04
|
5
|
+
- BREAKING: Float color components now share the 0..255 range with integers instead of being scaled from 0..1.
|
6
|
+
- Add `define_mutable_version` helper to create bang versions from immutable methods
|
7
|
+
- Add `background!` and `resize!` filters
|
8
|
+
|
1
9
|
## [0.3.0] - 2025-07-25
|
2
10
|
- Rename `dither!` to `palette_reduce!`
|
3
11
|
- 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/image.rb
CHANGED
@@ -4,6 +4,8 @@ module ImageUtil
|
|
4
4
|
class Image
|
5
5
|
autoload :Buffer, "image_util/image/buffer"
|
6
6
|
|
7
|
+
include ImageUtil::Inspectable
|
8
|
+
|
7
9
|
Util.irb_fixup
|
8
10
|
|
9
11
|
ALL = nil..nil
|
@@ -211,14 +213,8 @@ module ImageUtil
|
|
211
213
|
Codec.encode(:sixel, self)
|
212
214
|
end
|
213
215
|
|
214
|
-
def
|
215
|
-
|
216
|
-
p.flush
|
217
|
-
p.output << image
|
218
|
-
p.text("", 0)
|
219
|
-
else
|
220
|
-
super
|
221
|
-
end
|
216
|
+
def inspect_image
|
217
|
+
self
|
222
218
|
end
|
223
219
|
|
224
220
|
def pixel_count(locations) = location_expand(locations).first.reduce(:*)
|
@@ -0,0 +1,25 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module ImageUtil
|
4
|
+
module Inspectable
|
5
|
+
def pretty_print(pp)
|
6
|
+
image = inspect_image
|
7
|
+
return super unless image.is_a?(ImageUtil::Image)
|
8
|
+
|
9
|
+
rendered = ImageUtil::Terminal.output_image($stdin, $stdout, image)
|
10
|
+
if rendered
|
11
|
+
pp.flush
|
12
|
+
pp.output << rendered
|
13
|
+
pp.text("", 0)
|
14
|
+
else
|
15
|
+
super
|
16
|
+
end
|
17
|
+
rescue LoadError
|
18
|
+
super
|
19
|
+
end
|
20
|
+
|
21
|
+
def inspect_image
|
22
|
+
raise NotImplementedError, "including classes must implement #inspect_image"
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
data/lib/image_util/version.rb
CHANGED
data/lib/image_util.rb
CHANGED
@@ -11,6 +11,7 @@ module ImageUtil
|
|
11
11
|
autoload :Image, "image_util/image"
|
12
12
|
autoload :Util, "image_util/util"
|
13
13
|
autoload :Codec, "image_util/codec"
|
14
|
+
autoload :Inspectable, "image_util/inspectable"
|
14
15
|
autoload :Magic, "image_util/magic"
|
15
16
|
autoload :Extension, "image_util/extension"
|
16
17
|
autoload :Filter, "image_util/filter"
|
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.5.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- hmdne
|
@@ -134,6 +134,7 @@ files:
|
|
134
134
|
- lib/image_util/generator/example/rose.png
|
135
135
|
- lib/image_util/image.rb
|
136
136
|
- lib/image_util/image/buffer.rb
|
137
|
+
- lib/image_util/inspectable.rb
|
137
138
|
- lib/image_util/magic.rb
|
138
139
|
- lib/image_util/statistic.rb
|
139
140
|
- lib/image_util/statistic/colors.rb
|
@@ -168,7 +169,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
168
169
|
- !ruby/object:Gem::Version
|
169
170
|
version: '0'
|
170
171
|
requirements: []
|
171
|
-
rubygems_version: 3.6.
|
172
|
+
rubygems_version: 3.6.9
|
172
173
|
specification_version: 4
|
173
174
|
summary: Simple pixel buffers with SIXEL and codec helpers
|
174
175
|
test_files: []
|