workspace-media 1.0.3 → 1.0.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/workspace-media.rb +11 -24
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f051d57f039398dbe338d8c99ca85d4666aba3c6
|
4
|
+
data.tar.gz: 63288e8b21f0993813e841bf2904cf49d783de18
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2d5c39f30be004d2c435a2a1000a189f316c470e19b9f21da6e33ca7095c66a945dfa6682c2febf9a5224ab45551d2106350e0f8013eee248524829eb1a81995
|
7
|
+
data.tar.gz: 7fa5e6be831f04a59f6ea72488fe401ad0ee13466f68a82d6dccd8fa22e55b0e57cee9d72e31ae1a30bfbc1b826bb5d84ab6fd8bace592434f2b77447cfb8d3e
|
data/workspace-media.rb
CHANGED
@@ -17,9 +17,8 @@ module Workspace
|
|
17
17
|
|
18
18
|
def image_size
|
19
19
|
image = Magick::Image.read(to_s).first
|
20
|
-
|
21
|
-
|
22
|
-
size
|
20
|
+
{ width: image.columns, height: image.rows }
|
21
|
+
ensure image&.destroy!
|
23
22
|
end
|
24
23
|
|
25
24
|
def fit(width: nil, height: nil, quality: 85)
|
@@ -30,36 +29,24 @@ module Workspace
|
|
30
29
|
image.change_geometry!("#{width}x^#{height}") { |cols, rows| image.thumbnail!(cols, rows) }
|
31
30
|
image.crop!(0, 0, width, height)
|
32
31
|
image.write(to_s) { self.quality = quality }
|
33
|
-
image.destroy!
|
34
32
|
self
|
33
|
+
ensure image&.destroy!
|
35
34
|
end
|
36
35
|
|
37
|
-
def optimize!(
|
36
|
+
def optimize!(image_max_width: nil, quality: 85, convert_jpg: true, optimize: true)
|
38
37
|
return false if !exists? or !image?
|
39
|
-
optimize_png!(options) if ["png"].include?(extension)
|
40
|
-
optimize_jpg!(options) if ["jpg", "jpeg"].include?(extension)
|
41
|
-
Piet.optimize(to_s, verbose: false)
|
42
|
-
self
|
43
|
-
end
|
44
|
-
|
45
|
-
private
|
46
|
-
|
47
|
-
def optimize_jpg!(image_max_width: 2048, quality: 85)
|
48
|
-
image = Magick::Image.read(to_s).first
|
49
|
-
image.change_geometry!("#{image_max_width}>x") { |cols, rows, img| img.resize!(cols, rows) } if image.columns > image_max_width
|
50
|
-
image.write(to_s) { self.quality = quality }
|
51
|
-
image.destroy!
|
52
|
-
end
|
53
|
-
|
54
|
-
def optimize_png!(image_max_width: 2048, quality: 85)
|
55
38
|
image = Magick::Image.read(to_s).first
|
56
|
-
|
57
|
-
|
39
|
+
if !image_max_width.nil? and image.columns > image_max_width
|
40
|
+
image.change_geometry!("#{image_max_width}>x") { |cols, rows, img| img.resize!(cols, rows) }
|
41
|
+
end
|
42
|
+
if mimetype == "image/png" and convert_jpg and (!image.alpha? or image.resize(1, 1).pixel_color(0, 0).opacity == 0)
|
58
43
|
image.format = "JPG"
|
59
44
|
rename("#{basename}.jpg")
|
60
45
|
end
|
61
46
|
image.write(to_s) { self.quality = quality }
|
62
|
-
|
47
|
+
Piet.optimize(to_s, verbose: false) if optimize
|
48
|
+
self
|
49
|
+
ensure image&.destroy!
|
63
50
|
end
|
64
51
|
end
|
65
52
|
end
|