easyimg_utils 0.4.3 → 0.5.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 +163 -98
- data.tar.gz.sig +0 -0
- metadata +1 -1
- 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: 4b3711353eefc74eef13ab152c8ca9755c100704838c4173ea93456aca64eb77
|
4
|
+
data.tar.gz: 368e6035463fd8d9caf41d0f30bfcac5c3bd5f5efff8e2f496c8d8aeb1dbe19a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
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
|
-
|
118
|
+
read() do |img|
|
117
119
|
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
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
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
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
|
-
|
146
|
-
|
147
|
-
|
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
|
-
|
167
|
-
|
168
|
-
|
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
|
-
|
197
|
+
read() do |img|
|
177
198
|
|
178
|
-
|
199
|
+
imgx = Magick::ImageList.new(filex)
|
179
200
|
|
180
|
-
|
181
|
-
|
201
|
+
# Change the white pixels in the sign to transparent.
|
202
|
+
imgx = imgx.matte_replace(0,0)
|
182
203
|
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
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
|
-
|
225
|
+
read() do |img|
|
204
226
|
|
205
|
-
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
|
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
|
-
|
245
|
-
|
246
|
-
|
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
|
-
|
276
|
+
read() do |img|
|
253
277
|
|
254
|
-
|
255
|
-
|
256
|
-
|
257
|
-
|
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
|
-
|
264
|
-
|
265
|
-
|
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
|
-
|
286
|
-
|
287
|
-
|
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
|
-
|
324
|
+
read() do |preview|
|
298
325
|
|
299
|
-
|
300
|
-
|
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
|
-
|
310
|
-
|
311
|
-
|
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
|
-
|
318
|
-
|
319
|
-
|
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
|
-
|
326
|
-
|
327
|
-
|
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
|
-
|
334
|
-
|
335
|
-
|
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
|
-
|
375
|
+
read() do |img|
|
344
376
|
|
345
|
-
|
346
|
-
|
347
|
-
|
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
|
-
|
388
|
+
read() do |img|
|
356
389
|
|
357
|
-
|
358
|
-
|
390
|
+
# Convert to grayscale
|
391
|
+
sketch = img.quantize(256, Magick::GRAYColorspace)
|
359
392
|
|
360
|
-
|
361
|
-
|
393
|
+
# Apply histogram equalization
|
394
|
+
sketch = sketch.equalize
|
362
395
|
|
363
|
-
|
364
|
-
|
396
|
+
sketch = sketch.sketch(0, 10, 135)
|
397
|
+
img = img.dissolve(sketch, 0.75, 0.25)
|
365
398
|
|
366
|
-
|
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
|
-
|
383
|
-
|
384
|
-
|
385
|
-
|
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
|
-
|
395
|
-
|
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 =~
|
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(
|
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,
|
486
|
+
FileX.cp outfile, file_out
|
422
487
|
|
423
488
|
else
|
424
489
|
|
425
|
-
img.write
|
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
metadata.gz.sig
CHANGED
Binary file
|