easyimg_utils 0.2.1 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: c11db71fb42a9794475a7bc991da66eb20358ea7c946fa805687dde73c3686eb
4
- data.tar.gz: c0ff39057ff9bc678737e5f234aa212314c091d27ed87e9d3831cffd92bc03ad
3
+ metadata.gz: 9e40cc156b9ae80cfc9ec4f1db9f44b886a73e9364924d88bc3cc73d6344d9b2
4
+ data.tar.gz: e7bcb81e66135174816218d2729b05d140eec50dc9b94e4e4d6a509578b69a72
5
5
  SHA512:
6
- metadata.gz: f163c5a6a5a855184a95150c4f669db1fb3e7ea0f76949383c8c206e525e8b70ab990629b7eed519c2232fe5eacf1fe4a97bb4b6a987ff10957ab316ccbc28e3
7
- data.tar.gz: 99bd0108eee06ec9f5658d05dbba12cb9c9e12c6b1c931986bb7d760dde8f63661e12d99570656ff9d9227f9bd4dad9e2f55018f6cf17b1e30956ca3f4c2ca5f
6
+ metadata.gz: d77d64f6b55259700029284542eb2b5e308b1fb25086acf30be8829e6872745fc35b60b8103abf69dadcfcdc193246810095b600c348ad91d77bfbdd6b72642e
7
+ data.tar.gz: 259a7364e0283cc6ebfb21a12bdbc3037a63e7deae9894390e589d2bfe5150973b585e5bff5717c652a0b0dda2963a3d7c964233e5de640e1d094127ced4d65c
checksums.yaml.gz.sig CHANGED
@@ -1 +1,2 @@
1
- R�M�D�-��ğ���H���zD��p1_چM Ɛ�0vIiɬ5Q�l��i*�������ƈ�����\rZDC���:� ���\��w��<���S����:i�#��`�����wC-�R��}m��ByQ�� ��?�/�><����8���a���kWUA�e��W�\�9C�PC_�7P,�k�� �A ��Ԑ��l�60, s���g���KAu�R�Jm�ҝ�\?O�,4��(ۭ��u��Q:w � ����@i�G�\���� ��X���,�8Ջ��T1ҵޢ�2�� ��RkC���4n��K'QL�����a>�V�,����pw���1��J��AV����0���kT��Q�z� ^�*��tZ�d��ź��&*��a9�
1
+ ��kg��Q8'v\� 
2
+ E_���k��*v�t��D�g�����~�K� ����~u5���J�dNa��cO�o�Q,3���3���U�����@��w�Y&���x� X%�+�
data/lib/easyimg_utils.rb CHANGED
@@ -26,12 +26,12 @@ module CommandHelper
26
26
  " %s %s %s" % ['*'.blue, command, desc.to_s.light_black]
27
27
  end
28
28
 
29
- puts a.map {|x| format_command.call(x) }.join("\n")
29
+ puts a.map(&format_command).join("\n")
30
30
 
31
31
  end
32
32
 
33
33
  def search(s)
34
- list @commands.grep Regexp.new(s)
34
+ list @commands.grep Regexp.new(s.to_s)
35
35
  end
36
36
 
37
37
  end
@@ -42,40 +42,47 @@ class EasyImgUtils
42
42
  include Magick
43
43
 
44
44
  @commands = "
45
+ * add rectangle # usage: add_rectangle(color: 'green', x1: 12, y1: 12, x2: 24, y2: 24)
45
46
  * add_svg # adds an SVG transparency overlay. usage: add_svg('/tmp/image1.svg')
46
47
  * add_text # e.g. add_text('some text')
47
48
  * blur # e.g. blur(x: 231, y: 123, w: 85, h: 85)
49
+ * center_crop # crops from the centre of an image. Usage center_crop(width, height)
50
+ * composite # overlay a smaller image on top of an image
51
+ * contrast # changes the intensity between lighter and darker elements
48
52
  * crop # e.g. crop(x: 231, y: 123, w: 85, h: 85)
53
+ * fax_effect # Produces a high-contrast, two colour image
54
+ * greyscale # Reduces the image to 256 shades of grey
49
55
  * info # returns the dimension of the image in a Hash object
56
+ * make_thumbnail # similar to resize but faster for sizes less than 10% of original image
50
57
  * resize # set the maximum geomertry of the image for resizing e.g. resize('320x240')
58
+ * sketch # renders an artistic sketch, ideal with simplistic photos
51
59
  * view # view the output
60
+ * vignette # Feathers the edge of an image in a circular path
52
61
  ".strip.lines.map {|x| x[/(?<=\* ).*/]}.sort
53
62
 
54
63
 
55
64
  def initialize(img_in=nil, img_out=nil, out: img_out,
56
65
  working_dir: '/tmp')
57
66
 
58
- @file_in, @file_out, @working_dir = img_in, out, working_dir
67
+ @file_in, @file_out, @working_dir = img_in, out, working_dir
59
68
 
60
69
  end
61
70
 
62
- def add_text(s='your text goes here', quality: nil)
71
+ def add_rectangle(a=[], quality: nil, color: 'green', stroke_width: 5,
72
+ x1: 0, y1: 0, x2: 0, y2: 0)
63
73
 
74
+ x1, y1, x2, y2 = *a if a
64
75
  img = read()
65
-
66
- d = Draw.new
67
- img.annotate(d, 0,0,0,0, s) do
68
- d.gravity = Magick::SouthGravity
69
- d.pointsize = 26
70
- d.stroke = '#000000'
71
- d.fill = '#ffffff'
72
- d.font_weight = Magick::BoldWeight
73
- end
74
-
76
+ gc = Magick::Draw.new
77
+ gc.stroke('green')
78
+ gc.stroke_width(5)
79
+ gc.fill('transparent')
80
+ gc.rectangle(x1, y1, x2, y2)
81
+ gc.draw(img)
75
82
  write img, quality
76
83
 
77
84
  end
78
-
85
+
79
86
  def add_svg(svg_file)
80
87
 
81
88
  img = Magick::ImageList.new
@@ -89,6 +96,24 @@ class EasyImgUtils
89
96
  img.flatten_images.write @file_out
90
97
 
91
98
  end
99
+
100
+ def add_text(s='your text goes here', quality: nil)
101
+
102
+ img = read()
103
+
104
+ d = Draw.new
105
+ img.annotate(d, 0,0,0,0, s) do
106
+ d.gravity = Magick::SouthGravity
107
+ d.pointsize = 26
108
+ d.stroke = '#000000'
109
+ d.fill = '#ffffff'
110
+ d.font_weight = Magick::BoldWeight
111
+ end
112
+
113
+ write img, quality
114
+
115
+ end
116
+
92
117
 
93
118
  def blur(x: 0, y: 0, w: 80, h: 80, strength: 8, quality: nil)
94
119
 
@@ -101,6 +126,54 @@ class EasyImgUtils
101
126
  write img, quality
102
127
 
103
128
  end
129
+
130
+ def center_crop(w=0, h=0, width: w, height: h, quality: nil)
131
+
132
+ return unless w
133
+
134
+ img = read()
135
+ img.crop!(CenterGravity, width, height)
136
+ write img, quality
137
+
138
+ end
139
+
140
+ def composite(filex=nil, x: 0, y: 0, quality: nil)
141
+
142
+ return unless filex
143
+
144
+ img = read()
145
+
146
+ imgx = Magick::ImageList.new(filex)
147
+
148
+ # Change the white pixels in the sign to transparent.
149
+ imgx = imgx.matte_replace(0,0)
150
+
151
+ img2 = Magick::Draw.new
152
+ img2.composite(x, y, 0, 0, imgx)
153
+ img2.draw(img)
154
+
155
+ write img, quality
156
+
157
+ end
158
+
159
+ # contrast level
160
+ # 1 low -> 10 high
161
+ #
162
+ def contrast(level=5)
163
+
164
+ neutral = 5
165
+
166
+ return if level == neutral
167
+
168
+ img ||= read()
169
+
170
+ n = neutral - level
171
+ sharpen = n > 0
172
+ n.abs.times { img = img.contrast(sharpen) }
173
+
174
+ write img, quality
175
+
176
+ end
104
177
 
105
178
  def crop(x: 0, y: 0, w: nil, h: nil, quality: nil)
106
179
 
@@ -112,6 +185,27 @@ class EasyImgUtils
112
185
 
113
186
  end
114
187
 
188
+ def fax_effect(threshold: 0.55, quality: nil)
189
+
190
+ img = read()
191
+
192
+ # Use a threshold of 55% of MaxRGB.
193
+ img = img.threshold(Magick::MaxRGB*threshold)
194
+
195
+ write img, quality
196
+
197
+ end
198
+
199
+ def greyscale(quality: nil)
200
+
201
+ img = read()
202
+ img2 = img.quantize(256, GRAYColorspace)
203
+ write img2, quality
204
+
205
+ end
206
+
207
+ alias grayscale greyscale
208
+
115
209
  def info()
116
210
 
117
211
  img = Magick::Image.ping( @file_in ).first
@@ -123,6 +217,14 @@ class EasyImgUtils
123
217
  }
124
218
 
125
219
  end
220
+
221
+ def make_thumbnail(width=125, height=125)
222
+
223
+ img = read()
224
+ img2 = img.thumbnail(width, height)
225
+ write img2, quality
226
+
227
+ end
126
228
 
127
229
  # defines the maximum size of an image while maintaining aspect ratio
128
230
  #
@@ -134,6 +236,23 @@ class EasyImgUtils
134
236
  img.resize!(cols, rows)
135
237
  end
136
238
 
239
+ write preview, quality
240
+
241
+ end
242
+
243
+ def sketch(quality: nil)
244
+
245
+ img = read()
246
+
247
+ # Convert to grayscale
248
+ sketch = img.quantize(256, Magick::GRAYColorspace)
249
+
250
+ # Apply histogram equalization
251
+ sketch = sketch.equalize
252
+
253
+ sketch = sketch.sketch(0, 10, 135)
254
+ img = img.dissolve(sketch, 0.75, 0.25)
255
+
137
256
  write img, quality
138
257
 
139
258
  end
@@ -145,6 +264,15 @@ class EasyImgUtils
145
264
  run command, show
146
265
 
147
266
  end
267
+
268
+ def vignette(quality: nil)
269
+
270
+ img = read()
271
+ img2 = img.vignette
272
+
273
+ write img2, quality
274
+
275
+ end
148
276
 
149
277
  private
150
278
 
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.2.1
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - James Robertson
metadata.gz.sig CHANGED
Binary file