easyimg_utils 0.1.0 → 0.2.0
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/lib/easyimg_utils.rb +97 -12
- data.tar.gz.sig +0 -0
- metadata +17 -17
- 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: ca697c8f506cb4a300a4409d64f141e3ba54ad73a4752a87bff42e56e2966b5a
|
4
|
+
data.tar.gz: 38fa011815055c8a5006a98246fa7e1f567568d20c42ded7921da9ba91b7f2c0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: aecc89caf56b44b17733a41ab911fc5ad8eb1c3fdb05d78285d9b3f2bd30beb3144a6ca11d1e594c543ebead8e34e6ce9557a73e5010dcfab9d14c8dbd0e9f1f
|
7
|
+
data.tar.gz: 18a9a3c4bc4fe47990485ef412194b25c7c7a942ff3d28c00b6f52f262b0f915cef06b68ccf176a1009babf225a352941344caf0ba9df17e50a4f6b89a32a916
|
checksums.yaml.gz.sig
CHANGED
Binary file
|
data/lib/easyimg_utils.rb
CHANGED
@@ -3,10 +3,17 @@
|
|
3
3
|
# file: easyimg_utils.rb
|
4
4
|
|
5
5
|
require 'c32'
|
6
|
+
require 'rxfhelper'
|
6
7
|
require 'rmagick'
|
7
8
|
|
8
9
|
# requirements:
|
9
|
-
#
|
10
|
+
#
|
11
|
+
# rmagick package dependencies:
|
12
|
+
# apt-get install imagemagick imagemagick-doc libmagickcore-dev libmagickwand-dev`
|
13
|
+
#
|
14
|
+
# viewer:
|
15
|
+
# apt-get install feh
|
16
|
+
|
10
17
|
|
11
18
|
|
12
19
|
module CommandHelper
|
@@ -19,8 +26,8 @@ module CommandHelper
|
|
19
26
|
" %s %s %s" % ['*'.blue, command, desc.to_s.light_black]
|
20
27
|
end
|
21
28
|
|
22
|
-
|
23
|
-
|
29
|
+
puts a.map {|x| format_command.call(x) }.join("\n")
|
30
|
+
|
24
31
|
end
|
25
32
|
|
26
33
|
def search(s)
|
@@ -35,31 +42,101 @@ class EasyImgUtils
|
|
35
42
|
include Magick
|
36
43
|
|
37
44
|
@commands = "
|
38
|
-
*
|
45
|
+
* add_text # e.g. add_text('some text')
|
46
|
+
* blur # e.g. blur(x: 231, y: 123, w: 85, h: 85)
|
47
|
+
* crop # e.g. crop(x: 231, y: 123, w: 85, h: 85)
|
48
|
+
* info # returns the dimension of the image in a Hash object
|
49
|
+
* resize # set the maximum geomertry of the image for resizing e.g. resize('320x240')
|
50
|
+
* view # view the output
|
39
51
|
".strip.lines.map {|x| x[/(?<=\* ).*/]}.sort
|
40
52
|
|
41
53
|
|
42
|
-
def initialize(img_in=nil, img_out=
|
54
|
+
def initialize(img_in=nil, img_out=nil, out: img_out,
|
43
55
|
working_dir: '/tmp')
|
44
56
|
|
45
57
|
@file_in, @file_out, @working_dir = img_in, out, working_dir
|
46
58
|
|
47
59
|
end
|
60
|
+
|
61
|
+
def add_text(s='your text goes here', quality: nil)
|
62
|
+
|
63
|
+
img = read()
|
64
|
+
|
65
|
+
d = Draw.new
|
66
|
+
img.annotate(d, 0,0,0,0, s) do
|
67
|
+
d.gravity = Magick::SouthGravity
|
68
|
+
d.pointsize = 26
|
69
|
+
d.stroke = '#000000'
|
70
|
+
d.fill = '#ffffff'
|
71
|
+
d.font_weight = Magick::BoldWeight
|
72
|
+
end
|
73
|
+
|
74
|
+
write img, quality
|
75
|
+
|
76
|
+
end
|
77
|
+
|
78
|
+
def blur(x: 0, y: 0, w: 80, h: 80, strength: 8, quality: nil)
|
79
|
+
|
80
|
+
width, height = w, h
|
81
|
+
img = read()
|
82
|
+
region = img.dispatch(x, y, width, height, 'RGB')
|
83
|
+
face_img = Magick::Image.constitute(width, height, "RGB", region)
|
84
|
+
img.composite!(face_img.gaussian_blur(0, strength), x, y,
|
85
|
+
Magick::OverCompositeOp)
|
86
|
+
write img, quality
|
87
|
+
|
88
|
+
end
|
89
|
+
|
90
|
+
def crop(x: 0, y: 0, w: nil, h: nil, quality: nil)
|
91
|
+
|
92
|
+
return unless w
|
93
|
+
|
94
|
+
img = read()
|
95
|
+
img.crop!(x,y, width=w, height=h)
|
96
|
+
write img, quality
|
97
|
+
|
98
|
+
end
|
99
|
+
|
100
|
+
def info()
|
101
|
+
|
102
|
+
img = Magick::Image.ping( @file_in ).first
|
103
|
+
{
|
104
|
+
geometry: "%sx%s" % [img.columns, img.rows],
|
105
|
+
mime_type: img.mime_type, format: img.format,
|
106
|
+
quality: img.quality, filesize: img.filesize,
|
107
|
+
filename: img.filename, created: img.properties
|
108
|
+
}
|
109
|
+
|
110
|
+
end
|
48
111
|
|
49
112
|
# defines the maximum size of an image while maintaining aspect ratio
|
50
113
|
#
|
51
|
-
def resize(geometry='320x240')
|
114
|
+
def resize(geometry='320x240', quality: nil)
|
115
|
+
|
116
|
+
preview = read()
|
52
117
|
|
53
|
-
preview
|
54
|
-
preview.change_geometry!(geometry) { |cols, rows, img|
|
118
|
+
preview.change_geometry!(geometry) do |cols, rows, img|
|
55
119
|
img.resize!(cols, rows)
|
56
|
-
|
57
|
-
|
120
|
+
end
|
121
|
+
|
122
|
+
write img, quality
|
58
123
|
|
59
124
|
end
|
60
125
|
|
126
|
+
def view(show: true)
|
127
|
+
|
128
|
+
return unless @file_out
|
129
|
+
command = `feh #{@file_out}`
|
130
|
+
run command, show
|
131
|
+
|
132
|
+
end
|
61
133
|
|
62
|
-
private
|
134
|
+
private
|
135
|
+
|
136
|
+
def read()
|
137
|
+
data, type = RXFHelper.read(@file_in)
|
138
|
+
Magick::Image.from_blob(data).first
|
139
|
+
end
|
63
140
|
|
64
141
|
def run(command, show: false)
|
65
142
|
|
@@ -71,6 +148,14 @@ class EasyImgUtils
|
|
71
148
|
end
|
72
149
|
|
73
150
|
end
|
151
|
+
|
152
|
+
def write(img, quality=nil)
|
153
|
+
|
154
|
+
return img.to_blob unless @file_out
|
155
|
+
|
156
|
+
img.write @file_out do
|
157
|
+
self.quality = quality if quality
|
158
|
+
end
|
159
|
+
end
|
74
160
|
|
75
161
|
end
|
76
|
-
|
data.tar.gz.sig
CHANGED
Binary file
|
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.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- James Robertson
|
@@ -35,48 +35,48 @@ cert_chain:
|
|
35
35
|
6PB/a3YCkvA1ipebq/pmmvF9VopoG5giimE7Rkw0QPUi/w6724YH6tVQj077N2mP
|
36
36
|
WOpXPMFUK6eXTvN8BbxLtUkt
|
37
37
|
-----END CERTIFICATE-----
|
38
|
-
date: 2019-05-
|
38
|
+
date: 2019-05-06 00:00:00.000000000 Z
|
39
39
|
dependencies:
|
40
40
|
- !ruby/object:Gem::Dependency
|
41
|
-
name:
|
41
|
+
name: rmagick
|
42
42
|
requirement: !ruby/object:Gem::Requirement
|
43
43
|
requirements:
|
44
44
|
- - ">="
|
45
45
|
- !ruby/object:Gem::Version
|
46
|
-
version:
|
46
|
+
version: 3.1.0
|
47
47
|
- - "~>"
|
48
48
|
- !ruby/object:Gem::Version
|
49
|
-
version: '
|
49
|
+
version: '3.1'
|
50
50
|
type: :runtime
|
51
51
|
prerelease: false
|
52
52
|
version_requirements: !ruby/object:Gem::Requirement
|
53
53
|
requirements:
|
54
54
|
- - ">="
|
55
55
|
- !ruby/object:Gem::Version
|
56
|
-
version:
|
56
|
+
version: 3.1.0
|
57
57
|
- - "~>"
|
58
58
|
- !ruby/object:Gem::Version
|
59
|
-
version: '
|
59
|
+
version: '3.1'
|
60
60
|
- !ruby/object:Gem::Dependency
|
61
|
-
name:
|
61
|
+
name: rxfhelper
|
62
62
|
requirement: !ruby/object:Gem::Requirement
|
63
63
|
requirements:
|
64
|
-
- - ">="
|
65
|
-
- !ruby/object:Gem::Version
|
66
|
-
version: 3.1.0
|
67
64
|
- - "~>"
|
68
65
|
- !ruby/object:Gem::Version
|
69
|
-
version: '
|
66
|
+
version: '0.9'
|
67
|
+
- - ">="
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: 0.9.4
|
70
70
|
type: :runtime
|
71
71
|
prerelease: false
|
72
72
|
version_requirements: !ruby/object:Gem::Requirement
|
73
73
|
requirements:
|
74
|
-
- - ">="
|
75
|
-
- !ruby/object:Gem::Version
|
76
|
-
version: 3.1.0
|
77
74
|
- - "~>"
|
78
75
|
- !ruby/object:Gem::Version
|
79
|
-
version: '
|
76
|
+
version: '0.9'
|
77
|
+
- - ">="
|
78
|
+
- !ruby/object:Gem::Version
|
79
|
+
version: 0.9.4
|
80
80
|
description:
|
81
81
|
email: james@jamesrobertson.eu
|
82
82
|
executables: []
|
@@ -106,5 +106,5 @@ requirements: []
|
|
106
106
|
rubygems_version: 3.0.1
|
107
107
|
signing_key:
|
108
108
|
specification_version: 4
|
109
|
-
summary:
|
109
|
+
summary: Makes manipulating images from 1 line of code easier.
|
110
110
|
test_files: []
|
metadata.gz.sig
CHANGED
Binary file
|