workspace-media 1.0.4 → 1.0.5
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 +21 -1
- 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: 4620f799e694fe73ff51c65366e4ba1911fa0d01
|
4
|
+
data.tar.gz: 1219574f0407cf2fc0d0e4353cefa68f30833d5d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3cee6f32953d81a7efbae53e18c2b61895e41c233711d9ae921dafa10ff5b2d5cbf0cdc71feaccdbbbbf817f1ec718784172db51181014c0c004b554747153b4
|
7
|
+
data.tar.gz: 126389fb3ea71a5a913a1c3d58c1742de8808a25d130e95cefc0852317495f5557a0bc060ec50be1b83a546df3770c964aff50e34efc657281dd3093c020fd24
|
data/workspace-media.rb
CHANGED
@@ -3,6 +3,18 @@ require "rmagick"
|
|
3
3
|
|
4
4
|
module Workspace
|
5
5
|
class File
|
6
|
+
def jpg?
|
7
|
+
["jpg", "jpeg"].include?(extension)
|
8
|
+
end
|
9
|
+
|
10
|
+
def png?
|
11
|
+
["png"].include?(extension)
|
12
|
+
end
|
13
|
+
|
14
|
+
def gif?
|
15
|
+
["gif"].include?(extension)
|
16
|
+
end
|
17
|
+
|
6
18
|
def image?
|
7
19
|
["jpg", "jpeg", "gif", "png"].include?(extension)
|
8
20
|
end
|
@@ -44,9 +56,17 @@ module Workspace
|
|
44
56
|
rename("#{basename}.jpg")
|
45
57
|
end
|
46
58
|
image.write(to_s) { self.quality = quality }
|
47
|
-
|
59
|
+
available = (jpg? and command?("jpegoptim")) or (png? and command?("optipng"))
|
60
|
+
Piet.optimize(to_s, verbose: false) if optimize and available
|
48
61
|
self
|
49
62
|
ensure image&.destroy!
|
50
63
|
end
|
64
|
+
|
65
|
+
private
|
66
|
+
|
67
|
+
def command?(name)
|
68
|
+
`which #{name}`
|
69
|
+
$?.success?
|
70
|
+
end
|
51
71
|
end
|
52
72
|
end
|