lib/html2doc/mime.rb in html2doc-1.0.6 vs lib/html2doc/mime.rb in html2doc-1.0.7

- old
+ new

@@ -66,11 +66,11 @@ # max width for Word document is 400, max height is 680 def self.image_resize(i, path, maxheight, maxwidth) realSize = ImageSize.path(path).size s = [i["width"].to_i, i["height"].to_i] s = realSize if s[0].zero? && s[1].zero? - return [nil, nil] if realSize[0].nil? || realSize[1].nil? + return [nil, nil] if realSize.nil? || realSize[0].nil? || realSize[1].nil? s[1] = s[0] * realSize[1] / realSize[0] if s[1].zero? && !s[0].zero? s[0] = s[1] * realSize[0] / realSize[1] if s[0].zero? && !s[1].zero? s = [(s[0] * maxheight / s[1]).ceil, maxheight] if s[1] > maxheight s = [maxwidth, (s[1] * maxwidth / s[0]).ceil] if s[0] > maxwidth s @@ -90,11 +90,11 @@ def self.image_cleanup(docxml, dir, localdir) docxml.traverse do |i| next unless i.element? && %w(img v:imagedata).include?(i.name) #warnsvg(i["src"]) next if /^http/.match i["src"] - next if %r{^data:image/[^;]+;base64}.match i["src"] + next if %r{^data:(image|application)/[^;]+;base64}.match i["src"] local_filename = %r{^([A-Z]:)?/}.match(i["src"]) ? i["src"] : File.join(localdir, i["src"]) new_filename = "#{mkuuid}#{File.extname(i["src"])}" FileUtils.cp local_filename, File.join(dir, new_filename) i["width"], i["height"] = image_resize(i, local_filename, 680, 400) @@ -111,10 +111,10 @@ end.join end def self.header_image_cleanup1(a, dir, filename, localdir) if a.size == 2 && !(/ src="https?:/.match a[1]) && - !(%r{ src="data:image/[^;]+;base64}.match a[1]) + !(%r{ src="data:(image|application)/[^;]+;base64}.match a[1]) m = / src=['"](?<src>[^"']+)['"]/.match a[1] #warnsvg(m[:src]) m2 = /\.(?<suffix>[a-zA-Z_0-9]+)$/.match m[:src] new_filename = "#{mkuuid}.#{m2[:suffix]}" old_filename = %r{^([A-Z]:)?/}.match(m[:src]) ? m[:src] : File.join(localdir, m[:src])