easyimg_utils 0.4.3 → 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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 4d14e8e346eadfa36ea43f336f4b8bb161e2c38e216c162d97e67439767fb84b
4
- data.tar.gz: 9f27d41d4938f8c5b4249c90566062a5841ff24d9b1bf86506b2354fe0c070a4
3
+ metadata.gz: 4b3711353eefc74eef13ab152c8ca9755c100704838c4173ea93456aca64eb77
4
+ data.tar.gz: 368e6035463fd8d9caf41d0f30bfcac5c3bd5f5efff8e2f496c8d8aeb1dbe19a
5
5
  SHA512:
6
- metadata.gz: 3df7e8b76c8860579e2801664a3a14dcfb24c36eeb79607c0aeb944b37183db7b5cc0905790bd38a124a63abbba2ac0f1b72ca714a6456d937fab99a5efde938
7
- data.tar.gz: 5e845353a3f9b335712cb262c5272de9b5d6a71a4fb3efa291863104d4fbe8b8bf7de90a935a2e87a5a0a0da7c4771da1fcfd42742ceee7449bc4f4bfaf96c07
6
+ metadata.gz: b091344cc47cac8248f0ce408fb43392573ff40da3e068983a81af69a347eec9aba772805bed440c807db5333e2c39982dbc6ddcda70bf13577fb9a41548725b
7
+ data.tar.gz: ac8b138321d6849852f2f096fba9bda524f768c2d7d1f979117b66e99b42929255d06a225cef8e0ebc49226002136ebaa9e0062d492f2d5928ba0c33eec7eea2
checksums.yaml.gz.sig CHANGED
Binary file
data/lib/easyimg_utils.rb CHANGED
@@ -51,6 +51,7 @@ class EasyImgUtils
51
51
  * add rectangle # usage: add_rectangle(color: 'green', x1: 12, y1: 12, x2: 24, y2: 24)
52
52
  * add_svg # adds an SVG transparency overlay. usage: add_svg('/tmp/image1.svg')
53
53
  * add_text # e.g. add_text('some text')
54
+ * animate Creates an animated gif e.g. animate('/tmp/a%d.png', '/tmp/b.gif')
54
55
  * blur # e.g. blur(x: 231, y: 123, w: 85, h: 85)
55
56
  * capture_screen # takes a screenshot of the desktop
56
57
  * center_crop # crops from the centre of an image. Usage center_crop(width, height)
@@ -86,14 +87,15 @@ class EasyImgUtils
86
87
  x1: 0, y1: 0, x2: 0, y2: 0)
87
88
 
88
89
  x1, y1, x2, y2 = *a if a
89
- img = read()
90
- gc = Magick::Draw.new
91
- gc.stroke('green')
92
- gc.stroke_width(5)
93
- gc.fill('transparent')
94
- gc.rectangle(x1, y1, x2, y2)
95
- gc.draw(img)
96
- write img, quality
90
+ read() do |img|
91
+ gc = Magick::Draw.new
92
+ gc.stroke('green')
93
+ gc.stroke_width(5)
94
+ gc.fill('transparent')
95
+ gc.rectangle(x1, y1, x2, y2)
96
+ gc.draw(img)
97
+ write img, quality
98
+ end
97
99
 
98
100
  end
99
101
 
@@ -113,38 +115,56 @@ class EasyImgUtils
113
115
 
114
116
  def add_text(s='your text goes here', quality: nil)
115
117
 
116
- img = read()
118
+ read() do |img|
117
119
 
118
- d = Draw.new
119
- img.annotate(d, 0,0,0,0, s) do
120
- d.gravity = Magick::SouthGravity
121
- d.pointsize = 26
122
- d.stroke = '#000000'
123
- d.fill = '#ffffff'
124
- d.font_weight = Magick::BoldWeight
120
+ d = Draw.new
121
+ img.annotate(d, 0,0,0,0, s) do
122
+ d.gravity = Magick::SouthGravity
123
+ d.pointsize = 26
124
+ d.stroke = '#000000'
125
+ d.fill = '#ffffff'
126
+ d.font_weight = Magick::BoldWeight
127
+ end
128
+
129
+ write img, quality
130
+
125
131
  end
126
132
 
127
- write img, quality
128
-
129
133
  end
130
134
 
135
+ def animate()
136
+
137
+ anim = Magick::ImageList.new
138
+
139
+ read() {|img| anim << img }
140
+ anim.ticks_per_second = 100
141
+ anim.delay = 20
142
+
143
+ @file_out ? anim.write(@file_out) : anim.animate
144
+
145
+ end
131
146
 
132
147
  def blur(x: 0, y: 0, w: 80, h: 80, strength: 8, quality: nil)
133
148
 
134
149
  width, height = w, h
135
- img = read()
136
- region = img.dispatch(x, y, width, height, 'RGB')
137
- face_img = Magick::Image.constitute(width, height, "RGB", region)
138
- img.composite!(face_img.gaussian_blur(0, strength), x, y,
139
- Magick::OverCompositeOp)
140
- write img, quality
150
+
151
+ read() do |img|
152
+
153
+ region = img.dispatch(x, y, width, height, 'RGB')
154
+ face_img = Magick::Image.constitute(width, height, "RGB", region)
155
+ img.composite!(face_img.gaussian_blur(0, strength), x, y,
156
+ Magick::OverCompositeOp)
157
+ write img, quality
158
+
159
+ end
141
160
 
142
161
  end
143
162
 
144
163
  def brightness(quality: nil)
145
- img = read()
146
- img2 = imglevel(-Magick::QuantumRange * 0.25, Magick::QuantumRange * 1.25, 1.0)
147
- write img2, quality
164
+ read() do |img|
165
+ img2 = imglevel(-Magick::QuantumRange * 0.25, Magick::QuantumRange * 1.25, 1.0)
166
+ write img2, quality
167
+ end
148
168
  end
149
169
 
150
170
  def capture_screen(quality: nil)
@@ -163,9 +183,10 @@ class EasyImgUtils
163
183
 
164
184
  return unless w
165
185
 
166
- img = read()
167
- img.crop!(CenterGravity, width, height)
168
- write img, quality
186
+ read() do |img|
187
+ img.crop!(CenterGravity, width, height)
188
+ write img, quality
189
+ end
169
190
 
170
191
  end
171
192
 
@@ -173,18 +194,19 @@ class EasyImgUtils
173
194
 
174
195
  return unless filex
175
196
 
176
- img = read()
197
+ read() do |img|
177
198
 
178
- imgx = Magick::ImageList.new(filex)
199
+ imgx = Magick::ImageList.new(filex)
179
200
 
180
- # Change the white pixels in the sign to transparent.
181
- imgx = imgx.matte_replace(0,0)
201
+ # Change the white pixels in the sign to transparent.
202
+ imgx = imgx.matte_replace(0,0)
182
203
 
183
- img2 = Magick::Draw.new
184
- img2.composite(x, y, 0, 0, imgx)
185
- img2.draw(img)
186
-
187
- write img, quality
204
+ img2 = Magick::Draw.new
205
+ img2.composite(x, y, 0, 0, imgx)
206
+ img2.draw(img)
207
+
208
+ write img, quality
209
+ end
188
210
 
189
211
  end
190
212
 
@@ -200,13 +222,14 @@ class EasyImgUtils
200
222
 
201
223
  return if level == neutral
202
224
 
203
- img ||= read()
225
+ read() do |img|
204
226
 
205
- n = neutral - level
206
- sharpen = n > 0
207
- n.abs.times { img = img.contrast(sharpen) }
208
-
209
- write img, quality
227
+ n = neutral - level
228
+ sharpen = n > 0
229
+ n.abs.times { img = img.contrast(sharpen) }
230
+
231
+ write img, quality
232
+ end
210
233
 
211
234
  end
212
235
 
@@ -241,28 +264,31 @@ class EasyImgUtils
241
264
 
242
265
  return unless w
243
266
 
244
- img = read()
245
- img.crop!(x,y, width=w, height=h)
246
- write img, quality
267
+ read() do |img|
268
+ img.crop!(x,y, width=w, height=h)
269
+ write img, quality
270
+ end
247
271
 
248
272
  end
249
273
 
250
274
  def fax_effect(threshold: 0.55, quality: nil)
251
275
 
252
- img = read()
276
+ read() do |img|
253
277
 
254
- # Use a threshold of 55% of MaxRGB.
255
- img = img.threshold(Magick::MaxRGB*threshold)
256
-
257
- write img, quality
278
+ # Use a threshold of 55% of MaxRGB.
279
+ img = img.threshold(Magick::MaxRGB*threshold)
280
+ write img, quality
281
+
282
+ end
258
283
 
259
284
  end
260
285
 
261
286
  def greyscale(quality: nil)
262
287
 
263
- img = read()
264
- img2 = img.quantize(256, GRAYColorspace)
265
- write img2, quality
288
+ read() do |img|
289
+ img2 = img.quantize(256, GRAYColorspace)
290
+ write img2, quality
291
+ end
266
292
 
267
293
  end
268
294
 
@@ -282,9 +308,10 @@ class EasyImgUtils
282
308
 
283
309
  def make_thumbnail(width=125, height=125)
284
310
 
285
- img = read()
286
- img2 = img.thumbnail(width, height)
287
- write img2, quality
311
+ read() do |img|
312
+ img2 = img.thumbnail(width, height)
313
+ write img2, quality
314
+ end
288
315
 
289
316
  end
290
317
 
@@ -294,45 +321,50 @@ class EasyImgUtils
294
321
  #
295
322
  def resize(geometry='320x240', quality: nil)
296
323
 
297
- preview = read()
324
+ read() do |preview|
298
325
 
299
- preview.change_geometry!(geometry) do |cols, rows, img|
300
- img.resize!(cols, rows)
326
+ preview.change_geometry!(geometry) do |cols, rows, img|
327
+ img.resize!(cols, rows)
328
+ end
329
+
330
+ write preview, quality
301
331
  end
302
332
 
303
- write preview, quality
304
-
305
333
  end
306
334
 
307
335
  def rotate(degrees)
308
336
 
309
- img = read()
310
- img2 = img.rotate(degrees.to_i)
311
- write img2, quality
337
+ read() do |img|
338
+ img2 = img.rotate(degrees.to_i)
339
+ write img2, quality
340
+ end
312
341
 
313
342
  end
314
343
 
315
344
  def rotate_180()
316
345
 
317
- img = read()
318
- img2 = img.rotate(180)
319
- write img2, quality
346
+ read() do |img|
347
+ img2 = img.rotate(180)
348
+ write img2, quality
349
+ end
320
350
 
321
351
  end
322
352
 
323
353
  def rotate_left()
324
354
 
325
- img = read()
326
- img2 = img.rotate(-45)
327
- write img2, quality
355
+ read() do |img|
356
+ img2 = img.rotate(-45)
357
+ write img2, quality
358
+ end
328
359
 
329
360
  end
330
361
 
331
362
  def rotate_right()
332
363
 
333
- img = read()
334
- img2 = img.rotate(45)
335
- write img2, quality
364
+ read() do |img|
365
+ img2 = img.rotate(45)
366
+ write img2, quality
367
+ end
336
368
 
337
369
  end
338
370
 
@@ -340,11 +372,12 @@ class EasyImgUtils
340
372
  #
341
373
  def scale(factor=0.75, quality: nil)
342
374
 
343
- img = read()
375
+ read() do |img|
344
376
 
345
- img2 = img.scale(factor)
346
-
347
- write img2, quality
377
+ img2 = img.scale(factor)
378
+ write img2, quality
379
+
380
+ end
348
381
 
349
382
  end
350
383
 
@@ -352,18 +385,20 @@ class EasyImgUtils
352
385
 
353
386
  def sketch(quality: nil)
354
387
 
355
- img = read()
388
+ read() do |img|
356
389
 
357
- # Convert to grayscale
358
- sketch = img.quantize(256, Magick::GRAYColorspace)
390
+ # Convert to grayscale
391
+ sketch = img.quantize(256, Magick::GRAYColorspace)
359
392
 
360
- # Apply histogram equalization
361
- sketch = sketch.equalize
393
+ # Apply histogram equalization
394
+ sketch = sketch.equalize
362
395
 
363
- sketch = sketch.sketch(0, 10, 135)
364
- img = img.dissolve(sketch, 0.75, 0.25)
396
+ sketch = sketch.sketch(0, 10, 135)
397
+ img = img.dissolve(sketch, 0.75, 0.25)
365
398
 
366
- write img, quality
399
+ write img, quality
400
+
401
+ end
367
402
 
368
403
  end
369
404
 
@@ -379,10 +414,12 @@ class EasyImgUtils
379
414
 
380
415
  def vignette(quality: nil)
381
416
 
382
- img = read()
383
- img2 = img.vignette
384
-
385
- write img2, quality
417
+ read() do |img|
418
+
419
+ img2 = img.vignette
420
+ write img2, quality
421
+
422
+ end
386
423
 
387
424
  end
388
425
 
@@ -391,8 +428,28 @@ class EasyImgUtils
391
428
  private
392
429
 
393
430
  def read(file=@file_in)
394
- data, type = RXFHelper.read(file)
395
- Magick::Image.from_blob(data).first
431
+
432
+ files = if file =~ /%d/ then
433
+
434
+ regfilepath = file.sub('%d','(\d+)')
435
+ globfilepath = file.sub('%d','*')
436
+
437
+ a = Dir[globfilepath]
438
+
439
+ a.sort_by {|x| Regexp.new(regfilepath).match(x).captures[0].to_i }
440
+
441
+ else
442
+ [file]
443
+ end
444
+
445
+ files.each do |filex|
446
+
447
+ @filex_in = filex
448
+ data, type = RXFHelper.read(filex)
449
+ yield(Magick::Image.from_blob(data).first)
450
+
451
+ end
452
+
396
453
  end
397
454
 
398
455
  def run(command, show=false)
@@ -410,19 +467,27 @@ class EasyImgUtils
410
467
 
411
468
  return img.to_blob unless @file_out
412
469
 
413
- if @file_out =~ /^dfs:/ then
470
+ file_out = if @file_out =~ /%d/ then
471
+ regpath = @file_in.sub('%d','(\d+)')
472
+ n = @filex_in[/#{regpath}/,1]
473
+ @file_out.sub('%d',n)
474
+ else
475
+ @file_out
476
+ end
477
+
478
+ if file_out =~ /^dfs:/ then
414
479
 
415
- outfile = File.join(@working_dir, File.basename(@file_out))
480
+ outfile = File.join(@working_dir, File.basename(file_out))
416
481
 
417
482
  img.write outfile do
418
483
  self.quality = quality.to_i if quality
419
484
  end
420
485
 
421
- FileX.cp outfile, @file_out
486
+ FileX.cp outfile, file_out
422
487
 
423
488
  else
424
489
 
425
- img.write @file_out do
490
+ img.write file_out do
426
491
  self.quality = quality.to_i if quality
427
492
  end
428
493
 
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.3
4
+ version: 0.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - James Robertson
metadata.gz.sig CHANGED
Binary file