obf 0.6.20 → 0.6.21

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/lib/obf/utils.rb +45 -13
  3. metadata +2 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 8c73acb37386325b5db5fd87c3797a56337d3e64
4
- data.tar.gz: c633ace8ad21a52f7653c963c7867a5c0a0b2102
3
+ metadata.gz: 03b9f2c5c9bf032340aaef0f589345218ff1935e
4
+ data.tar.gz: 0ded6c478c227820dfb01e8e517f365dc2f8bce2
5
5
  SHA512:
6
- metadata.gz: 1098bc2ffa35b73e3831cfbb89d299d16d63090830a8fc7b67487a856aa06964d7edc5c804f6c23bca60ce08ce9a878117ac2296eaf6dd7b7d59f84263a38ee6
7
- data.tar.gz: dbd87beb4db1f3361dea2d6d3d5d3365943138e55678975478691454cf010e2e3d412f9acff3df29d4ff3ae1b655aac96426e744e7e0e6f1fee42338588f6cda
6
+ metadata.gz: 4b2c2d8fcc92ef4411bf0f3606d011683a55cecbd1ee195d2a244b8349aac3bb62ea3a2436b0e20a65804f430dd2d78c41205d1d268302821bdc2801b5542a87
7
+ data.tar.gz: e0bcfef45b79fc50b214ccb3113e85392509e804e5878208d1873d6fc3eaf69183000881c5b881e8509869a4c2419e59a21e536def093459a1f4729fb90e8ea0
data/lib/obf/utils.rb CHANGED
@@ -20,11 +20,15 @@ module OBF::Utils
20
20
  elsif type.respond_to?(:extensions)
21
21
  extension = ("." + type.extensions[0]) if type && type.extensions && type.extensions.length > 0
22
22
  end
23
- {
23
+ res = {
24
24
  'content_type' => content_type,
25
25
  'data' => data,
26
26
  'extension' => extension
27
27
  }
28
+ if content_type && content_type.match(/^image/)
29
+ res = image_attrs(data).merge(res)
30
+ end
31
+ res
28
32
  end
29
33
 
30
34
  def self.identify_file(path)
@@ -103,6 +107,7 @@ module OBF::Utils
103
107
  'data' => File.read(url),
104
108
  'content_type' => types[0] && types[0].to_s
105
109
  }
110
+ image = image_attrs(url).merge(image)
106
111
  end
107
112
  return nil unless image
108
113
  str = "data:" + image['content_type']
@@ -147,6 +152,9 @@ module OBF::Utils
147
152
  return nil
148
153
  end
149
154
  file.close
155
+ # TODO: maybe convert to jpg instead of png?
156
+ # see https://github.com/prawnpdf/prawn/issues/324
157
+ # in that case, fill the image with a white background, perhaps?
150
158
  `convert #{file.path} -density 1200 -resize 300x300 -background none -gravity center -extent 300x300 #{file.path}.png`
151
159
  "#{file.path}.png"
152
160
  end
@@ -255,6 +263,41 @@ module OBF::Utils
255
263
  res
256
264
  end
257
265
 
266
+ def self.image_attrs(path)
267
+ if path.match(/^data:/)
268
+ raw = Base64.strict_decode64(url.split(/\,/, 2)[1])
269
+ file = Tempfile.new('file')
270
+ path = file.path
271
+ file.binmode
272
+ file.write raw
273
+ file.close
274
+ else
275
+ is_file = File.exist?(path) rescue false
276
+ if !is_file
277
+ file = Tempfile.new('file')
278
+ file.binmode
279
+ file.write path
280
+ path = file.path
281
+ file.close
282
+ end
283
+ end
284
+ data = `identify -verbose #{path}`
285
+ res = {}
286
+ data.split(/\n/).each do |line|
287
+ pre, post = line.sub(/^\s+/, '').split(/:\s/, 2)
288
+ if pre == 'Geometry'
289
+ match = post.match(/(\d+)x(\d+)/)
290
+ if match && match[1] && match[2]
291
+ res['width'] = match[1].to_i
292
+ res['height'] = match[2].to_i
293
+ end
294
+ elsif pre == 'Mime type'
295
+ res['content_type'] = post
296
+ end
297
+ end
298
+ res
299
+ end
300
+
258
301
  class Zipper
259
302
  def initialize(zipfile)
260
303
  @zipfile = zipfile
@@ -288,22 +331,11 @@ module OBF::Utils
288
331
  attrs['data'] = str
289
332
 
290
333
  if attrs['content_type'].match(/^image/)
291
- fn = OBF::Utils.temp_path('file')
292
334
  file = Tempfile.new('file')
293
335
  file.binmode
294
336
  file.write raw
295
337
  file.close
296
- data = `identify -verbose #{file.path}`
297
- data.split(/\n/).each do |line|
298
- pre, post = line.sub(/^\s+/, '').split(/:\s/, 2)
299
- if pre == 'Geometry'
300
- match = post.match(/(\d+)x(\d+)/)
301
- if match && match[1] && match[2]
302
- attrs['width'] = match[1].to_i
303
- attrs['height'] = match[2].to_i
304
- end
305
- end
306
- end
338
+ attrs = (OBF::Utils.image_attrs(file.path) || {}).merge(attrs)
307
339
  end
308
340
  attrs
309
341
  end
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.6.20
4
+ version: 0.6.21
5
5
  platform: ruby
6
6
  authors:
7
7
  - Brian Whitmer
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-12-11 00:00:00.000000000 Z
11
+ date: 2015-03-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: json