obf 0.9.8.7 → 0.9.8.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (4) hide show
  1. checksums.yaml +4 -4
  2. data/lib/obf/pdf.rb +14 -2
  3. data/lib/obf/utils.rb +23 -8
  4. metadata +1 -1
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 3e9744e7a34a7cf34c098f19e1fbc6ef9eb6ceb3e1c7eebfc3fb7d80779b502c
4
- data.tar.gz: 3a707ec782d9a9df24409a9e2ef4c3c96b8b59de9693a587c044826c6fe72cbd
3
+ metadata.gz: d2ed2e2f90f78fab2afac2c3d1f52af1c8b7345e7cb3d0fa6434832899b62a05
4
+ data.tar.gz: cd9e8521d222e51a9fe6ea760134465a93e2bb05b9c9ee03252bd57e986890ca
5
5
  SHA512:
6
- metadata.gz: efcf27be7401b4d904608f968e174b44b79c85b9346cbd174a1da9917e0e58faa4197338f5ba9cfaabd15c3e409bb603083f119e3a8ac73c10869a285d919a41
7
- data.tar.gz: fe94deb30f15448d792b4abcc7695c7e049f821d7a89250518410c320e6e82aaffca13bc1dcef256fc3eb390d473f37fa079f475cf85e83845c50af156de67b1
6
+ metadata.gz: 02ef108ce774799e4242d1818104d12ae2fcb9c725ef05218bc55b8784330adb458a2d89a1341a2cf7abdd90c61ce2d7374297155151271a9730777a1af5e195
7
+ data.tar.gz: 56c075245f5cb0421b556c2618ca2dbe81ffda55d199e0f73787cdc34c0df4c942ae1419379babbeafee64dd088a09ea38b4311423c00a24a50dfb3a9212a34f
@@ -196,14 +196,26 @@ module OBF::PDF
196
196
  uri = OBF::Utils.sanitize_url(uri)
197
197
  req = Typhoeus::Request.new(uri, followlocation: true)
198
198
  hydra.queue(req)
199
- grabs << {url: url, req: req, image: image}
199
+ grabs << {url: url, req: req, image: image, fill: btn['background_color'] ? OBF::Utils.fix_color(btn['background_color'], 'hex') : "ffffff"}
200
200
  end
201
201
  end
202
202
  hydra.run
203
+ threads = []
203
204
  grabs.each do |grab|
204
205
  grab[:image]['raw_data'] = grab[:req].response.body
206
+ grab[:image]['threadable'] = true
205
207
  grab[:image]['content_type'] = grab[:req].response.headers['Content-Type'] if grab[:req].response.headers['Content-Type']
208
+ bg = 'white'
209
+ if options['transparent_background'] || options['symbol_background'] == 'transparent'
210
+ bg = "\##{grab[:fill]}"
211
+ elsif options['symbol_background'] == 'black'
212
+ bg = 'black'
213
+ end
214
+ res = OBF::Utils.save_image(grab[:image], options['zipper'], bg)
215
+ threads << res unless res.is_a?(String)
206
216
  end
217
+ threads.each{|t| t.join }
218
+ grabs.each{|g| g[:image]['threadable'] = false }
207
219
  OBF::Utils.log " done with #{grabs.length} remote images!"
208
220
 
209
221
  obj['grid']['order'].each_with_index do |buttons, row|
@@ -255,7 +267,7 @@ module OBF::PDF
255
267
  elsif options['symbol_background'] == 'black'
256
268
  bg = 'black'
257
269
  end
258
- image_local_path = image && OBF::Utils.save_image(image, options['zipper'], bg)
270
+ image_local_path = image && (image['local_path'] || OBF::Utils.save_image(image, options['zipper'], bg))
259
271
  if image_local_path && File.exist?(image_local_path)
260
272
  pdf.image(image_local_path, :fit => [button_width - 10, button_height - text_height - 5], :position => :center, :vposition => :center) rescue nil
261
273
  File.unlink image_local_path
@@ -179,25 +179,40 @@ module OBF::Utils
179
179
  # png files need to be converted to make sure they don't have a transparent bg, or
180
180
  # else performance takes a huge hit.
181
181
  `cp #{file.path} #{file.path}#{extension}`
182
- "#{file.path}#{extension}"
182
+ image['local_path'] = "#{file.path}#{extension}"
183
183
  else
184
184
  background ||= 'white'
185
185
  size = 400
186
186
  path = file.path
187
187
  if image['content_type'] && image['content_type'].match(/svg/)
188
- OBF::Utils.log " convert -background \"#{background}\" -density 300 -resize #{size}x#{size} -gravity center -extent #{size}x#{size} #{file.path} -flatten #{file.path}.jpg"
189
- `convert -background "#{background}" -density 300 -resize #{size}x#{size} -gravity center -extent #{size}x#{size} #{file.path} -flatten #{file.path}.jpg`
188
+ cmd = "convert -background \"#{background}\" -density 300 -resize #{size}x#{size} -gravity center -extent #{size}x#{size} #{file.path} -flatten #{file.path}.jpg"
189
+ OBF::Utils.log " #{cmd}"
190
+ image['local_path'] = "#{file.path}.jpg"
191
+ if image['threadable']
192
+ thr = Process.detach(Process.spawn(cmd))
193
+ return thr
194
+ else
195
+ `#{cmd}`
196
+ end
197
+ # `convert -background "#{background}" -density 300 -resize #{size}x#{size} -gravity center -extent #{size}x#{size} #{file.path} -flatten #{file.path}.jpg`
190
198
  # `rsvg-convert -w #{size} -h #{size} -a #{file.path} > #{file.path}.png`
191
- path = "#{file.path}.jpg"
192
199
  else
193
- OBF::Utils.log " convert #{path} -density 300 -resize #{size}x#{size} -background "#{background}" -gravity center -extent #{size}x#{size} -flatten #{path}.jpg"
194
- `convert #{path} -density 300 -resize #{size}x#{size} -background "#{background}" -gravity center -extent #{size}x#{size} -flatten #{path}.jpg`
195
- path = "#{path}.jpg"
200
+ cmd = "convert #{path} -density 300 -resize #{size}x#{size} -background \"#{background}\" -gravity center -extent #{size}x#{size} -flatten #{path}.jpg"
201
+ OBF::Utils.log " #{cmd}"
202
+ image['local_path'] = "#{path}.jpg"
203
+ if image['threadable']
204
+ thr = Process.detach(Process.spawn(cmd))
205
+ return thr
206
+ else
207
+ `#{cmd}`
208
+ end
209
+ # `convert #{path} -density 300 -resize #{size}x#{size} -background "#{background}" -gravity center -extent #{size}x#{size} -flatten #{path}.jpg`
196
210
  end
197
211
 
198
212
  OBF::Utils.log " finished image"
199
- path
213
+ image['local_path']
200
214
  end
215
+ image['local_path']
201
216
  end
202
217
 
203
218
  def self.sound_raw(url)
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: obf
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.9.8.7
4
+ version: 0.9.8.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - Brian Whitmer