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.
Files changed (3) hide show
  1. checksums.yaml +4 -4
  2. data/workspace-media.rb +11 -24
  3. metadata +1 -1
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: cd9f38a74821f07bf754d56f85f10ae86455296e
4
- data.tar.gz: 0de1057bbcae94e5c5b4fdfbbff92ee8ef36b377
3
+ metadata.gz: f051d57f039398dbe338d8c99ca85d4666aba3c6
4
+ data.tar.gz: 63288e8b21f0993813e841bf2904cf49d783de18
5
5
  SHA512:
6
- metadata.gz: 15e105a18bf8e188e238d13e59462c0810ac4253bb144c7f7488b558124632cdfc1f4b2afade93ca811e1870007f07f8e1c680ae51c9b3d9509ab9942ef12e82
7
- data.tar.gz: 17662040b8d4c20b3460f124f134f5c9cc42563b3d519e7b04377e032632bb48204e036213dbc4ae83988f2888f31ea680164e12e1f9af89e8ff01a6065be002
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
- size = { width: image.columns, height: image.rows }
21
- image.destroy!
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!(options = {})
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
- image.change_geometry!("#{image_max_width}>x") { |cols, rows, img| img.resize!(cols, rows) } if image.columns > image_max_width
57
- if !image.alpha? or image.resize(1, 1).pixel_color(0, 0).opacity == 0
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
- image.destroy!
47
+ Piet.optimize(to_s, verbose: false) if optimize
48
+ self
49
+ ensure image&.destroy!
63
50
  end
64
51
  end
65
52
  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.3
4
+ version: 1.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tobias Strebitzer