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.
Files changed (3) hide show
  1. checksums.yaml +4 -4
  2. data/workspace-media.rb +21 -1
  3. metadata +1 -1
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: f051d57f039398dbe338d8c99ca85d4666aba3c6
4
- data.tar.gz: 63288e8b21f0993813e841bf2904cf49d783de18
3
+ metadata.gz: 4620f799e694fe73ff51c65366e4ba1911fa0d01
4
+ data.tar.gz: 1219574f0407cf2fc0d0e4353cefa68f30833d5d
5
5
  SHA512:
6
- metadata.gz: 2d5c39f30be004d2c435a2a1000a189f316c470e19b9f21da6e33ca7095c66a945dfa6682c2febf9a5224ab45551d2106350e0f8013eee248524829eb1a81995
7
- data.tar.gz: 7fa5e6be831f04a59f6ea72488fe401ad0ee13466f68a82d6dccd8fa22e55b0e57cee9d72e31ae1a30bfbc1b826bb5d84ab6fd8bace592434f2b77447cfb8d3e
6
+ metadata.gz: 3cee6f32953d81a7efbae53e18c2b61895e41c233711d9ae921dafa10ff5b2d5cbf0cdc71feaccdbbbbf817f1ec718784172db51181014c0c004b554747153b4
7
+ data.tar.gz: 126389fb3ea71a5a913a1c3d58c1742de8808a25d130e95cefc0852317495f5557a0bc060ec50be1b83a546df3770c964aff50e34efc657281dd3093c020fd24
@@ -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
- Piet.optimize(to_s, verbose: false) if optimize
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
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: workspace-media
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.4
4
+ version: 1.0.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tobias Strebitzer