easyimg_utils 0.6.5 → 0.7.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- checksums.yaml.gz.sig +0 -0
- data.tar.gz.sig +0 -0
- data/lib/easyimg_utils.rb +81 -2
- metadata +22 -2
- metadata.gz.sig +0 -0
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2b1dfaea58127ef88f5b78e46e00146d925b9cc9e05c7c8836d9d934a9cb87b5
|
4
|
+
data.tar.gz: d54061b87a0864110935762bfcd8558552fdaf0e925b3446aa1c22667a8ef41f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c66d8a62d782f4a1535df8351984c05701c6bfb0868cc42c266983054de86b70dc1238888108aa0492bd689d27b3485058fee7c1fe57175c495bc4bcad884c92
|
7
|
+
data.tar.gz: c1ddf021ed6e85154dc13d3b1dbcc59c47d8bac8066acbd8502d5f4704aa7296b3d713e0b9171c796e6bbe4e4530684d1e3c8d1bfe83c73aac055535cb6e6304
|
checksums.yaml.gz.sig
CHANGED
Binary file
|
data.tar.gz.sig
CHANGED
Binary file
|
data/lib/easyimg_utils.rb
CHANGED
@@ -7,6 +7,7 @@ require 'x4ss'
|
|
7
7
|
require 'rmagick'
|
8
8
|
require 'webp_ffi'
|
9
9
|
require 'rxfhelper'
|
10
|
+
require 'detectfaces'
|
10
11
|
|
11
12
|
# requirements:
|
12
13
|
#
|
@@ -19,6 +20,8 @@ require 'rxfhelper'
|
|
19
20
|
# webp-ffi dependencies
|
20
21
|
# apt-get install libjpeg-dev libpng-dev libtiff-dev libwebp-dev
|
21
22
|
#
|
23
|
+
# detectfaces dependencies
|
24
|
+
# apt-get install libopencv-dev
|
22
25
|
|
23
26
|
|
24
27
|
|
@@ -54,6 +57,7 @@ class EasyImgUtils
|
|
54
57
|
* add_svg # adds an SVG transparency overlay. usage: add_svg('/tmp/image1.svg')
|
55
58
|
* add_text # e.g. add_text('some text')
|
56
59
|
* animate Creates an animated gif e.g. animate('/tmp/a%d.png', '/tmp/b.gif')
|
60
|
+
* best_viewport # returns the best viewing region on the y-axis
|
57
61
|
* blur # e.g. blur(x: 231, y: 123, w: 85, h: 85)
|
58
62
|
* capture_screen # takes a screenshot of the desktop
|
59
63
|
* calc_resize # e.g. calc_resize '640x480' #=> 640x491
|
@@ -63,6 +67,7 @@ class EasyImgUtils
|
|
63
67
|
* convert # convert from 1 img format to another
|
64
68
|
* crop # e.g. crop(x: 231, y: 123, w: 85, h: 85)
|
65
69
|
* fax_effect # Produces a high-contrast, two colour image
|
70
|
+
* faces # Returns an array of bounding boxes for detected faces
|
66
71
|
* greyscale # Reduces the image to 256 shades of grey
|
67
72
|
* info # returns the dimension of the image in a Hash object
|
68
73
|
* make_thumbnail # similar to resize but faster for sizes less than 10% of original image
|
@@ -171,6 +176,42 @@ class EasyImgUtils
|
|
171
176
|
|
172
177
|
end
|
173
178
|
|
179
|
+
# Used where images are perhaps cropped using CSS to a letterbox size image.
|
180
|
+
# Works best with portrait mode photos of selfies or natural
|
181
|
+
# landscapes with a lot of sky
|
182
|
+
#
|
183
|
+
# Returns the starting y pos as a percentage of the image using face
|
184
|
+
# detection and high contrast detection on the y-axis
|
185
|
+
#
|
186
|
+
def best_viewport()
|
187
|
+
|
188
|
+
percentage = 0
|
189
|
+
|
190
|
+
read() do |img|
|
191
|
+
|
192
|
+
found = faces()
|
193
|
+
|
194
|
+
index = if found.any? then
|
195
|
+
|
196
|
+
# find the top y
|
197
|
+
box = found.max_by {|x, y, width, height| y}
|
198
|
+
y, height = box.values_at 1, 3
|
199
|
+
y - (height / 2)
|
200
|
+
|
201
|
+
else
|
202
|
+
|
203
|
+
y_maxcontrast(img)
|
204
|
+
|
205
|
+
end
|
206
|
+
|
207
|
+
percentage = (100 / (img.rows / index.to_f)).round
|
208
|
+
|
209
|
+
end
|
210
|
+
|
211
|
+
return percentage
|
212
|
+
|
213
|
+
end
|
214
|
+
|
174
215
|
def blur(x: 0, y: 0, w: 80, h: 80, strength: 8, quality: nil)
|
175
216
|
|
176
217
|
width, height = w, h
|
@@ -304,6 +345,10 @@ class EasyImgUtils
|
|
304
345
|
|
305
346
|
end
|
306
347
|
|
348
|
+
def faces()
|
349
|
+
DetectFaces.new(@file_in).faces
|
350
|
+
end
|
351
|
+
|
307
352
|
def fax_effect(threshold: 0.55, quality: nil)
|
308
353
|
|
309
354
|
read() do |img|
|
@@ -352,8 +397,10 @@ class EasyImgUtils
|
|
352
397
|
|
353
398
|
# defines the maximum size of an image while maintaining aspect ratio
|
354
399
|
#
|
355
|
-
def resize(
|
400
|
+
def resize(raw_geometry='320x240', quality: nil)
|
356
401
|
|
402
|
+
geometry = calc_resize(raw_geometry
|
403
|
+
)
|
357
404
|
read() do |preview|
|
358
405
|
|
359
406
|
preview.change_geometry!(geometry) do |cols, rows, img|
|
@@ -473,7 +520,7 @@ class EasyImgUtils
|
|
473
520
|
|
474
521
|
end
|
475
522
|
|
476
|
-
alias feathered_around vignette
|
523
|
+
alias feathered_around vignette
|
477
524
|
|
478
525
|
private
|
479
526
|
|
@@ -543,5 +590,37 @@ class EasyImgUtils
|
|
543
590
|
|
544
591
|
end
|
545
592
|
end
|
593
|
+
|
594
|
+
# returns the y index of the pixel containing the most contrast using the
|
595
|
+
# y-axis center of the image
|
596
|
+
#
|
597
|
+
def y_maxcontrast(img)
|
598
|
+
|
599
|
+
rows, cols = img.rows, img.columns
|
600
|
+
center = (cols / 2).round
|
601
|
+
pixels = img.get_pixels(center,0,1,rows)
|
602
|
+
|
603
|
+
rgb = []
|
604
|
+
px = pixels[0]
|
605
|
+
rgb = [px.red, px.green, px.blue].map { |v| 255*(v/65535.0) }
|
606
|
+
|
607
|
+
a = pixels[1..-1].map do |pixel,i|
|
608
|
+
|
609
|
+
c = [pixel.red, pixel.green, pixel.blue].map { |v| 255*(v/65535.0) }
|
610
|
+
rgb[0] - c[0]
|
611
|
+
rgb.map.with_index {|x,i| (x - c[i]).abs.to_i}
|
612
|
+
|
613
|
+
end
|
546
614
|
|
615
|
+
a2 = a.map(&:sum)
|
616
|
+
puts 'a2: ' + a2.inspect if @debug
|
617
|
+
#a2.index(a2.max) + 1
|
618
|
+
# attempt to detect the 1st occurrence of contrast
|
619
|
+
r = a2.detect {|x| x > 600}
|
620
|
+
# otherwise select any occurrence of high contrast
|
621
|
+
r = a2.max unless r
|
622
|
+
a2.index(r) + 1
|
623
|
+
|
624
|
+
end
|
625
|
+
|
547
626
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: easyimg_utils
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.7.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- James Robertson
|
@@ -35,7 +35,7 @@ cert_chain:
|
|
35
35
|
KY48n99T12IOioQ4ghCO1L/UAg2taLOcZbMv4WpV1p9bXKhnrow81zeogZjjiNGS
|
36
36
|
OmTAjCfyGFPC/1eXnSV5Smv8
|
37
37
|
-----END CERTIFICATE-----
|
38
|
-
date: 2021-03-
|
38
|
+
date: 2021-03-24 00:00:00.000000000 Z
|
39
39
|
dependencies:
|
40
40
|
- !ruby/object:Gem::Dependency
|
41
41
|
name: rmagick
|
@@ -117,6 +117,26 @@ dependencies:
|
|
117
117
|
- - "~>"
|
118
118
|
- !ruby/object:Gem::Version
|
119
119
|
version: '0.2'
|
120
|
+
- !ruby/object:Gem::Dependency
|
121
|
+
name: detectfaces
|
122
|
+
requirement: !ruby/object:Gem::Requirement
|
123
|
+
requirements:
|
124
|
+
- - ">="
|
125
|
+
- !ruby/object:Gem::Version
|
126
|
+
version: 0.1.0
|
127
|
+
- - "~>"
|
128
|
+
- !ruby/object:Gem::Version
|
129
|
+
version: '0.1'
|
130
|
+
type: :runtime
|
131
|
+
prerelease: false
|
132
|
+
version_requirements: !ruby/object:Gem::Requirement
|
133
|
+
requirements:
|
134
|
+
- - ">="
|
135
|
+
- !ruby/object:Gem::Version
|
136
|
+
version: 0.1.0
|
137
|
+
- - "~>"
|
138
|
+
- !ruby/object:Gem::Version
|
139
|
+
version: '0.1'
|
120
140
|
description:
|
121
141
|
email: digital.robertson@gmail.com
|
122
142
|
executables: []
|
metadata.gz.sig
CHANGED
Binary file
|