zooniverse_data 0.0.14 → 0.0.15

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 9e7fad0328799e864d6969d8b8dff3bbf63027bf
4
- data.tar.gz: 561683b823a9fb7a8909d71261c7b2b6a0db7d76
3
+ metadata.gz: a73655436923b23c1271dd3a779b0c4391aefdfe
4
+ data.tar.gz: 107d49c5c3183d4f5d9efd27f0b3ab15733a3aff
5
5
  SHA512:
6
- metadata.gz: 6a99e17fccb401d74149638524979b579b87b848153374248de025b94d1084099b4c3285c06123982da811a3e353798342a6bcfa0da6e9d86728afe2591aedcb
7
- data.tar.gz: 14281775a0b77af3c13b8976895dbb6f6ea83a7d96fc167e0233ccdccc32f7abdf9dee3832f007dc74d5da6d8ed3b8f7884ac3f6df2b2292429682b68f821ef5
6
+ metadata.gz: e84d60b607e71bd17aeaf0e6df1241443124308c5751830e8abf93e28212480953c02d4a548d878da980a3db8861feae3b7f868c949c010ca1163ebd46c1c260
7
+ data.tar.gz: f4a18bbc0fc648225ef2e72346a90dbe2e681b705cf8f09918fac32de22a8a91aaa21e162276de18340553b15d1a78adacf78e7cb3fd5fdc84acfdee4d01ffa7
@@ -6,82 +6,94 @@ module ZooniverseData
6
6
  module Images
7
7
  class ImageConversionError < StandardError; end
8
8
  class ImageOptimizationError < StandardError; end
9
-
9
+
10
10
  class Image
11
11
  attr_accessor :path, :raise_exceptions
12
-
12
+
13
13
  def initialize(path: path, raise_exceptions: true)
14
14
  self.path = path
15
15
  self.raise_exceptions = raise_exceptions
16
16
  end
17
-
17
+
18
18
  def size
19
19
  width, height = info.size
20
20
  OpenStruct.new width: width, height: height
21
21
  end
22
-
22
+
23
23
  def type
24
24
  info.type
25
25
  end
26
-
26
+
27
27
  def info
28
28
  @info ||= FastImage.new(path, raise_on_failure: raise_exceptions)
29
29
  end
30
-
30
+
31
31
  def optimize
32
32
  tap do
33
33
  case type
34
34
  when :jpeg
35
35
  _run_optimization "jpegtran -copy none -optimize -progressive -outfile '#{ tempfile.path }' '#{ path }'"
36
36
  when :png, :bmp, :gif, :tiff
37
- _run_optimization "optipng -strip all -o2 -quiet '#{ path }'"
37
+ _run_optimization "optipng #{optipng_options} '#{ path }'"
38
38
  end
39
39
  end
40
40
  end
41
-
41
+
42
42
  def tempfile
43
43
  return @tempfile if @tempfile
44
44
  @tempfile = Tempfile.new File.basename path
45
45
  end
46
-
46
+
47
47
  def remove_tempfile
48
48
  tempfile.delete
49
49
  @tempfile = nil
50
50
  end
51
-
51
+
52
52
  def replace_with_tempfile
53
53
  `cp '#{ tempfile.path }' '#{ path }'`
54
54
  remove_tempfile
55
55
  end
56
-
56
+
57
+ # -strip all only available after 0.7.0
58
+ # http://sourceforge.net/p/optipng/bugs/44/
59
+ def optipng_options
60
+ [ "-o2" , "-quiet" ].tap do |optipng_options|
61
+ if optipng_version = `optipng -v | sed -n 1p`.strip.match(/\s(\d.+):/)
62
+ if optipng_version[1].gsub(".", "").to_i > 70
63
+ optipng_options.unshift("-strip all")
64
+ end
65
+ end
66
+ end.join(" ")
67
+ end
68
+
57
69
  def _run_optimization(command)
58
70
  success = system command
59
71
  raise ImageOptimizationError.new('Image optimization failed') unless success
60
72
  replace_with_tempfile if @tempfile
61
73
  end
62
74
  end
63
-
75
+
64
76
  class Converter
65
77
  attr_accessor :input_image, :output_image, :flags
66
78
  attr_accessor :raise_exceptions, :remove_original, :optimize
67
-
79
+
68
80
  def initialize(path: path, raise_exceptions: true, remove_original: true, optimize: true)
69
81
  self.input_image = Image.new path: path, raise_exceptions: raise_exceptions
70
82
  self.remove_original = remove_original
71
83
  self.optimize = optimize
72
84
  self.flags = []
73
85
  end
74
-
86
+
75
87
  def command(string)
76
88
  tap do
77
89
  self.flags << string
78
90
  end
79
91
  end
80
-
92
+
81
93
  def resize(width: nil, height: nil, force: true, type: nil)
82
94
  tap do
83
95
  resize_type = type ? "#{ type }-resize" : 'resize'
84
-
96
+
85
97
  if width && height
86
98
  self.flags << "-#{ resize_type } #{ width }x#{ height }#{ force ? '\!' : '' }"
87
99
  elsif width || height
@@ -89,51 +101,51 @@ module ZooniverseData
89
101
  end
90
102
  end
91
103
  end
92
-
104
+
93
105
  def adaptive_resize(width: width, height: height, force: true)
94
106
  resize width: width, height: height, type: 'adaptive', force: force
95
107
  end
96
-
108
+
97
109
  def percentage_resize(percentage, type: nil)
98
110
  tap do
99
111
  resize_type = type ? "#{ type }-resize" : 'resize'
100
112
  self.flags << "-#{ resize_type } #{ percentage }% +repage"
101
113
  end
102
114
  end
103
-
115
+
104
116
  def adaptive_percentage_resize(percentage)
105
117
  percentage_resize percentage, type: 'adaptive'
106
118
  end
107
-
119
+
108
120
  def quality(percentage)
109
121
  tap do
110
122
  self.flags << "-quality #{ percentage }%"
111
123
  end
112
124
  end
113
-
125
+
114
126
  def crop(width: width, height: height, top: top, left: left)
115
127
  tap do
116
128
  self.flags << "-crop #{ width }x#{ height }+#{ left }+#{ top } +repage"
117
129
  end
118
130
  end
119
-
131
+
120
132
  def crop_center(width: width, height: height, top: 0, left: 0)
121
133
  tap do
122
134
  self.flags << "-gravity Center -crop #{ width }x#{ height }+#{ left }+#{ top } +repage"
123
135
  end
124
136
  end
125
-
137
+
126
138
  def negate
127
139
  tap do
128
140
  self.flags << "-negate"
129
141
  end
130
142
  end
131
143
  alias_method :invert, :negate
132
-
144
+
133
145
  def write_to(path: nil, prefix: nil, postfix: nil)
134
146
  to(path: path, prefix: prefix, postfix: postfix).write
135
147
  end
136
-
148
+
137
149
  def to(path: nil, prefix: nil, postfix: nil)
138
150
  raise ImageConversionError.new('Cannot convert an image without an output path') unless path || prefix || postfix
139
151
  tap do
@@ -142,19 +154,19 @@ module ZooniverseData
142
154
  input_path = File.dirname input_file
143
155
  input_ext = File.extname input_file
144
156
  input_name = File.basename(input_file).sub input_ext, ''
145
-
157
+
146
158
  input_name = "#{ prefix }_#{ input_name }" if prefix
147
159
  input_name = "#{ input_name }_#{ postfix }" if postfix
148
160
  path = "#{ input_path }/#{ input_name }#{ input_ext }"
149
161
  end
150
-
162
+
151
163
  self.output_image = Image.new path: path, raise_exceptions: raise_exceptions
152
164
  end
153
165
  end
154
-
166
+
155
167
  def write
156
168
  raise ImageConversionError.new('Cannot convert an image without an output path') unless output_image
157
-
169
+
158
170
  output_image.tap do
159
171
  success = system "convert #{ input_image.path } #{ flags.join(' ') } #{ output_image.path }"
160
172
  raise ImageConversionError.new('Image conversion failed') unless success
@@ -163,23 +175,23 @@ module ZooniverseData
163
175
  end
164
176
  end
165
177
  end
166
-
178
+
167
179
  def convert_image(path, remove_original: true, optimize: true)
168
180
  Converter.new path: path, remove_original: remove_original, optimize: optimize
169
181
  end
170
-
182
+
171
183
  def invert_image(path, remove_original: false, optimize: true)
172
184
  convert_image(path, remove_original: remove_original).invert.write_to prefix: 'inverted'
173
185
  end
174
-
186
+
175
187
  def convert_to_jpeg(path, remove_original: true, optimize: true)
176
188
  _simple_convert path, 'jpg', remove_original: remove_original, optimize: optimize
177
189
  end
178
-
190
+
179
191
  def convert_to_png(path, remove_original: true, optimize: true)
180
192
  _simple_convert path, 'png', remove_original: remove_original, optimize: optimize
181
193
  end
182
-
194
+
183
195
  def _simple_convert(path, extension, remove_original: true, optimize: true)
184
196
  out_path = path.sub(/#{ File.extname(path) }$/, ".#{ extension }")
185
197
  convert_image(path, remove_original: remove_original, optimize: optimize).to(path: out_path).write
@@ -0,0 +1,42 @@
1
+ module ZooniverseData
2
+ module Projects
3
+ class HiggsHunter
4
+ include Helpers
5
+
6
+ def customize_subject
7
+ new_locations = default_empty_locations
8
+ entry.location['standard'].each do |image_path|
9
+ standard_image = standard_image(image_path)
10
+ new_locations['standard'] << standard_image
11
+ thumbnail_image = converter_for(standard_image, type: 'thumbnail', max_size: 400)
12
+ new_locations['thumbnail'] << thumbnail_image
13
+ end
14
+ set_location new_locations
15
+ end
16
+
17
+ private
18
+
19
+ def standard_image(path)
20
+ convert_image(path)
21
+ .write_to(prefix: 'standard')
22
+ .path
23
+ end
24
+
25
+ def converter_for(path, type: type, max_size: max_size)
26
+ convert_image(path, remove_original: false)
27
+ .resize(width: max_size, height: max_size, force: false)
28
+ .quality(80)
29
+ .write_to(prefix: type)
30
+ .path
31
+ end
32
+
33
+
34
+ def default_empty_locations
35
+ {
36
+ 'standard' => [],
37
+ 'thumbnail' => []
38
+ }
39
+ end
40
+ end
41
+ end
42
+ end
@@ -3,9 +3,10 @@ module ZooniverseData
3
3
  require 'zooniverse_data/projects/default'
4
4
  require 'zooniverse_data/projects/asteroid'
5
5
  require 'zooniverse_data/projects/condor'
6
+ require 'zooniverse_data/projects/higgs_hunter'
6
7
  require 'zooniverse_data/projects/milky_way'
8
+ require 'zooniverse_data/projects/penguin'
7
9
  require 'zooniverse_data/projects/serengeti'
8
10
  require 'zooniverse_data/projects/sunspot'
9
- require 'zooniverse_data/projects/penguin'
10
11
  end
11
12
  end
@@ -1,3 +1,3 @@
1
1
  module ZooniverseData
2
- VERSION = '0.0.14'
2
+ VERSION = '0.0.15'
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: zooniverse_data
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.14
4
+ version: 0.0.15
5
5
  platform: ruby
6
6
  authors:
7
7
  - Michael Parrish
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-06-10 00:00:00.000000000 Z
11
+ date: 2014-08-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -115,6 +115,7 @@ files:
115
115
  - lib/zooniverse_data/projects/asteroid.rb
116
116
  - lib/zooniverse_data/projects/condor.rb
117
117
  - lib/zooniverse_data/projects/default.rb
118
+ - lib/zooniverse_data/projects/higgs_hunter.rb
118
119
  - lib/zooniverse_data/projects/milky_way.rb
119
120
  - lib/zooniverse_data/projects/penguin.rb
120
121
  - lib/zooniverse_data/projects/serengeti.rb
@@ -141,7 +142,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
141
142
  version: '0'
142
143
  requirements: []
143
144
  rubyforge_project:
144
- rubygems_version: 2.2.1
145
+ rubygems_version: 2.2.2
145
146
  signing_key:
146
147
  specification_version: 4
147
148
  summary: Zooniverse data library