obf 0.9.8.18 → 0.9.8.19

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
  SHA256:
3
- metadata.gz: 68e9d9642a7a14c4324b0518f7f45b599009d40d1caaa6f414b1deeaab377ca1
4
- data.tar.gz: 3d6ae2cada6b30884bdd964a09ea90c6d7281393aa3781f51d693c35d2d2ec17
3
+ metadata.gz: 0e5d0262b2cc796234c4178adfe3f88bc38dfcf393a154b1bc2de1448334b61b
4
+ data.tar.gz: d40fe3b676d0adbd132b9156c0e123749029635b072caeb33dff06f11cf2045b
5
5
  SHA512:
6
- metadata.gz: 6772974b0b9f4d842dba7f7ca6e8bbfafc34dab19816ee4ef0e3239c31626ab9247b5cccb3899dc0b91ca09363bb30acccd788b776764ec83260f87c7e209032
7
- data.tar.gz: a2f165e74c25da9d3102dc5b968d21efdad12b40f94680489778d52d87e53843e05ea83edc8d35a9c52cf2faa8212de20f975e6be5a40cd51776bc9a2100321f
6
+ metadata.gz: 227928642c1f9afa5951d893850698a7b1341bb9fa43de23319234e1f47a17a8131ad26c59362edb54053c65296347a37f13b24257fae059d1ed1e7558f95648
7
+ data.tar.gz: cfc750c84d1bdc5f29612d28543987073e40a1d8198d717725003f20ba52fc80b885bc93d8b5e8457296749119bd48b7d2b1883f1ee1f890f329d2098d7ec88e
data/lib/obf/external.rb CHANGED
@@ -130,6 +130,7 @@ module OBF::External
130
130
  end
131
131
  end
132
132
  hydra.run
133
+
133
134
  grabs.each do |grab|
134
135
  if grab[:res] && grab[:res]['data']
135
136
  str = "data:" + grab[:res]['content_type']
data/lib/obf/pdf.rb CHANGED
@@ -126,6 +126,7 @@ module OBF::PDF
126
126
  @res ||= /[#{RTL_SCRIPTS.map{ |script| "\\p{#{script}}" }.join}]/
127
127
  end
128
128
 
129
+ # b.generate_download('1_2', 'pdf', {'include' => 'all', 'headerless' => true, 'symbol_background' => 'transparent'})
129
130
  def self.build_page(pdf, obj, options)
130
131
  OBF::Utils.as_progress_percent(0, 1.0) do
131
132
  pdf.font(options['font']) if options['font'] && File.exists?(options['font'])
@@ -191,36 +192,52 @@ module OBF::PDF
191
192
  obj['buttons'].each do |btn|
192
193
  image = (obj['images_hash'] || {})[btn['image_id']]
193
194
  if image && image['url'] && !image['data'] && !(image['path'] && options['zipper'])
195
+ # download the raw data from the remote URL
194
196
  url = image['url']
195
197
  res = OBF::Utils.get_url(url, true)
196
198
  if res['request']
197
199
  hydra.queue(res['request'])
198
200
  grabs << {url: url, res: res, req: res['request'], image: image, fill: btn['background_color'] ? OBF::Utils.fix_color(btn['background_color'], 'hex') : "ffffff"}
199
201
  end
200
- elsif image && image['data'] && !(image['path'] && options['zipper'])
202
+ elsif image && (image['data'] || (image['path'] && options['zipper']))
203
+ # process the data-uri or zipped image
201
204
  grabs << {image: image, fill: btn['background_color'] ? OBF::Utils.fix_color(btn['background_color'], 'hex') : "ffffff"}
202
205
  end
203
206
  end
204
207
  hydra.run
205
- threads = []
208
+ blocks = []
209
+ block = {}
206
210
  grabs.each do |grab|
207
- if grab[:res] && grab[:res]['data']
208
- grab[:image]['raw_data'] = grab[:res]['data']
209
- grab[:image]['content_type'] ||= grab[:res]['content_type']
210
- grab[:image]['extension'] ||= grab[:res]['extension']
211
+ # prevent too many svg converts from happening at the same time
212
+ block = block || {grabs: []}
213
+ block[:grabs] << grab
214
+ block[:has_svg] = true if grab[:type] == 'svg'
215
+ if block[:grabs].length > 5 && block[:has_svg]
216
+ blocks << block
217
+ block = nil
211
218
  end
212
- grab[:image]['threadable'] = true
213
- bg = 'white'
214
- if options['transparent_background'] || options['symbol_background'] == 'transparent'
215
- bg = "\##{grab[:fill]}"
216
- elsif options['symbol_background'] == 'black'
217
- bg = 'black'
219
+ end
220
+ blocks.each do |block|
221
+ threads = []
222
+ block[:grabs].each do |grab|
223
+ if grab[:res] && grab[:res]['data']
224
+ grab[:image]['raw_data'] = grab[:res]['data']
225
+ grab[:image]['content_type'] ||= grab[:res]['content_type']
226
+ grab[:image]['extension'] ||= grab[:res]['extension']
227
+ end
228
+ grab[:image]['threadable'] = true
229
+ bg = 'white'
230
+ if options['transparent_background'] || options['symbol_background'] == 'transparent'
231
+ bg = "\##{grab[:fill]}"
232
+ elsif options['symbol_background'] == 'black'
233
+ bg = 'black'
234
+ end
235
+ res = OBF::Utils.save_image(grab[:image], options['zipper'], bg)
236
+ threads << res if res && !res.is_a?(String)
218
237
  end
219
- res = OBF::Utils.save_image(grab[:image], options['zipper'], bg)
220
- threads << res if res && !res.is_a?(String)
238
+ threads.each{|t| t[:thred].join }
221
239
  end
222
- threads.each{|t| t[:thread].join }
223
- grabs.each{|g| g[:image].delete('threadable') }
240
+ grabs.each{|g| g[:image].delete('threadable'); g[:image].delete('local_path') unless File.exist?(g[:image]['local_path']) }
224
241
  OBF::Utils.log " done with #{grabs.length} remote images!"
225
242
 
226
243
  obj['grid']['order'].each_with_index do |buttons, row|
@@ -273,11 +290,14 @@ module OBF::PDF
273
290
  elsif options['symbol_background'] == 'black'
274
291
  bg = 'black'
275
292
  end
293
+ image['threadable'] = false
276
294
  image_local_path = image['local_path'] if image && image['local_path'] && File.exist?(image['local_path'])
277
295
  image_local_path ||= image && OBF::Utils.save_image(image, options['zipper'], bg)
278
296
  if image_local_path && File.exist?(image_local_path)
279
297
  pdf.image(image_local_path, :fit => [button_width - 10, button_height - text_height - 5], :position => :center, :vposition => :center) rescue nil
280
298
  File.unlink image_local_path
299
+ else
300
+ OBF::Utils.log(" missing image #{image['id']} #{image_local_path}")
281
301
  end
282
302
  end
283
303
  end
data/lib/obf/utils.rb CHANGED
@@ -160,7 +160,7 @@ module OBF::Utils
160
160
  end
161
161
 
162
162
  def self.hydra
163
- Typhoeus::Hydra.new(max_concurrency: 20)
163
+ Typhoeus::Hydra.new(max_concurrency: 10)
164
164
  end
165
165
 
166
166
  def self.save_image(image, zipper=nil, background=nil)
@@ -217,39 +217,34 @@ module OBF::Utils
217
217
  if image['content_type'] && image['content_type'].match(/svg/)
218
218
  cmd = "convert -background \"#{background}\" -density 300 -resize #{size}x#{size} -gravity center -extent #{size}x#{size} #{file.path} -flatten #{file.path}.jpg"
219
219
  OBF::Utils.log " #{cmd}"
220
+ image['local_path'] = "#{file.path}.jpg"
220
221
  if image['threadable']
221
- thr = Thread.new do
222
- pid = Process.spawn(cmd)
223
- Process.wait(pid)
224
- if $?.exitstatus == 0 && File.exist?("#{file.path}.jpg")
225
- image['local_path'] = "#{file.path}.jpg"
226
- end
227
- end
228
- return {thread: thr, image: image, type: 'svg'}
222
+ pid = Process.spawn(cmd)
223
+ thr = Process.detach(pid)
224
+ OBF::Utils.log " scheduled image"
225
+ return {thread: thr, image: image, type: 'svg', pid: pid}
229
226
  else
230
227
  `#{cmd}`
228
+ OBF::Utils.log " finished image #{File.size(image['local_path'])}"
231
229
  end
232
230
  # `convert -background "#{background}" -density 300 -resize #{size}x#{size} -gravity center -extent #{size}x#{size} #{file.path} -flatten #{file.path}.jpg`
233
231
  # `rsvg-convert -w #{size} -h #{size} -a #{file.path} > #{file.path}.png`
234
232
  else
235
233
  cmd = "convert #{path} -density 300 -resize #{size}x#{size} -background \"#{background}\" -gravity center -extent #{size}x#{size} -flatten #{path}.jpg"
236
234
  OBF::Utils.log " #{cmd}"
235
+ image['local_path'] = "#{path}.jpg"
237
236
  if image['threadable']
238
- thr = Thread.new do
239
- pid = Process.spawn(cmd)
240
- Process.wait(pid)
241
- if $?.exitstatus == 0 && File.exist?("#{path}.jpg")
242
- image['local_path'] = "#{path}.jpg"
243
- end
244
- end
245
- return {thread: thr, image: image, type: 'not_svg'}
237
+ pid = Process.spawn(cmd)
238
+ thr = Process.detach(pid)
239
+ OBF::Utils.log " scheduled image"
240
+ return {thread: thr, image: image, type: 'not_svg', pid: pid}
246
241
  else
247
242
  `#{cmd}`
243
+ OBF::Utils.log " finished image #{File.size(image['local_path'])}"
248
244
  end
249
245
  # `convert #{path} -density 300 -resize #{size}x#{size} -background "#{background}" -gravity center -extent #{size}x#{size} -flatten #{path}.jpg`
250
246
  end
251
247
 
252
- OBF::Utils.log " finished image"
253
248
  image['local_path']
254
249
  end
255
250
  image['local_path']
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: obf
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.9.8.18
4
+ version: 0.9.8.19
5
5
  platform: ruby
6
6
  authors:
7
7
  - Brian Whitmer
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-01-15 00:00:00.000000000 Z
11
+ date: 2020-01-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: json