rmagick-bin_magick 0.1.2 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +5 -0
- data/Gemfile.lock +1 -1
- data/README.md +12 -2
- data/lib/rmagick/bin_magick/image_inst_methods.rb +29 -25
- data/lib/rmagick/bin_magick/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: 0a293900932fdfc11d0cc3ba539c01ba265ccc4a152742f12a9e5a4232a6c7ce
|
4
|
+
data.tar.gz: b27891b507f6e6206e89d8030a3fac4eadd7b863989647deab08e2cd7a6cfb3c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 65b15dc2c7c57dcc93353fd88b03cc3daa17d06d6a94490a7f81f05e636fbbaff5609b1cce710795e12356be8c9596efef8521d382bc6cc8c51567ec17b6747c
|
7
|
+
data.tar.gz: 512fc5b71bfd67963a3b778bc0ecdb61bce2d8d623a074d8d580dede300b580d766912f69729ddc91ebb3c4613b634d7aaeb0439da06cc45788af4caa1df427b
|
data/CHANGELOG.md
CHANGED
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -181,6 +181,16 @@ The code above will produce the following result:
|
|
181
181
|
|
182
182
|
### Class Magick::BinMagick::Image: instance methods
|
183
183
|
|
184
|
+
- **binary?**
|
185
|
+
|
186
|
+
*img*.binary? -> *boolean*
|
187
|
+
|
188
|
+
Checks if the image consists of pixels that can have one of exactly two colors: black or white.
|
189
|
+
|
190
|
+
**Returns**: a boolean value.
|
191
|
+
|
192
|
+
***
|
193
|
+
|
184
194
|
- **black_px?**
|
185
195
|
|
186
196
|
*img*.black_px? -> *boolean*
|
@@ -195,7 +205,7 @@ The code above will produce the following result:
|
|
195
205
|
|
196
206
|
*img*.crop_border -> *image*
|
197
207
|
|
198
|
-
Crop border around the image. If the image
|
208
|
+
Crop border around the image. If the image can't be cropped (e.g. it has only pixels of the same color): returns an unedited copy of the target image.
|
199
209
|
|
200
210
|
Methods calculates a bounding box value for the target image (see Magick::Image#[bounding_box](https://rmagick.github.io/image1.html#bounding_box)), and uses that value to crop a copy of the target image.
|
201
211
|
|
@@ -221,7 +231,7 @@ The code above will produce the following result:
|
|
221
231
|
|
222
232
|
Same as *crop_border*, but treats a color image like it is already a binary one. The bounding box value is being calculated for a binary version of the target image, then a copy of the target image is being cropped used that value.
|
223
233
|
|
224
|
-
|
234
|
+
The method **does not** convert the target image to a binary, but uses a binary version only to calculate the bounding box value. For that purpose it accepts and utilizes all *to_binary* arguments.
|
225
235
|
|
226
236
|
**Arguments**: see *to_binary* arguments description.
|
227
237
|
|
@@ -8,35 +8,36 @@ module Magick
|
|
8
8
|
# Image instance methods.
|
9
9
|
#
|
10
10
|
class Image < MagickWrapper
|
11
|
+
#
|
12
|
+
# Check if the image is a binary image.
|
13
|
+
#
|
14
|
+
# @return [Boolean]
|
15
|
+
#
|
16
|
+
def binary?
|
17
|
+
accepted_colors = %w[black white]
|
18
|
+
colors = quantize.color_histogram.transform_keys(&:to_color)
|
19
|
+
|
20
|
+
(colors.keys - accepted_colors).empty?
|
21
|
+
end
|
22
|
+
|
11
23
|
#
|
12
24
|
# Check if the image has at least one black pixel.
|
13
25
|
#
|
14
26
|
# @return [Boolean]
|
15
27
|
#
|
16
28
|
def black_px?
|
17
|
-
colors = color_histogram
|
18
|
-
colors = colors.transform_keys(&:to_color)
|
19
|
-
|
29
|
+
colors = color_histogram.transform_keys(&:to_color)
|
20
30
|
colors.key?("black")
|
21
31
|
end
|
22
32
|
|
23
33
|
#
|
24
|
-
# Crop border around the image
|
34
|
+
# Crop border around the image or return an unedited copy if the image can't be cropped.
|
25
35
|
#
|
26
36
|
# @return [BinMagick::Image]
|
27
37
|
# A cropped image.
|
28
38
|
#
|
29
39
|
def crop_border
|
30
|
-
|
31
|
-
|
32
|
-
bb = bounding_box
|
33
|
-
|
34
|
-
crop(
|
35
|
-
bb.x,
|
36
|
-
bb.y,
|
37
|
-
bb.width,
|
38
|
-
bb.height
|
39
|
-
)
|
40
|
+
_crop_border(self)
|
40
41
|
end
|
41
42
|
|
42
43
|
#
|
@@ -59,17 +60,7 @@ module Magick
|
|
59
60
|
#
|
60
61
|
def crop_border_clr(...)
|
61
62
|
bin_img = to_binary(...)
|
62
|
-
|
63
|
-
return copy unless bin_img.black_px?
|
64
|
-
|
65
|
-
bb = bin_img.bounding_box
|
66
|
-
|
67
|
-
crop(
|
68
|
-
bb.x,
|
69
|
-
bb.y,
|
70
|
-
bb.width,
|
71
|
-
bb.height
|
72
|
-
)
|
63
|
+
_crop_border(bin_img)
|
73
64
|
end
|
74
65
|
|
75
66
|
#
|
@@ -215,6 +206,19 @@ module Magick
|
|
215
206
|
|
216
207
|
private
|
217
208
|
|
209
|
+
#
|
210
|
+
# Crop border around the image *img* or return an unedited copy of the image if the image can't be cropped.
|
211
|
+
#
|
212
|
+
# @param [Magick::BinMagick::Image] img
|
213
|
+
# Image to crop.
|
214
|
+
#
|
215
|
+
def _crop_border(img)
|
216
|
+
bb = img.bounding_box
|
217
|
+
crop(bb.x, bb.y, bb.width, bb.height)
|
218
|
+
rescue RuntimeError
|
219
|
+
img.copy
|
220
|
+
end
|
221
|
+
|
218
222
|
#
|
219
223
|
# Replace pixels in the target image with pixels from the image 'img' that is a result of a BinMagick::Image or
|
220
224
|
# a Magick::Image instance method call.
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rmagick-bin_magick
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Mate
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2023-04-
|
11
|
+
date: 2023-04-17 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rmagick
|