lib/utils/image.rb in metanorma-utils-1.2.5 vs lib/utils/image.rb in metanorma-utils-1.2.6
- old
+ new
@@ -21,10 +21,10 @@
.gsub(%r{\[([a-zA-z][a-z0-9A-Z@/]*\])}, "[xmlns:\\1")
end
end
def save_dataimage(uri)
- %r{^data:(image|application)/(?<imgtype>[^;]+);base64,(?<imgdata>.+)$} =~ uri
+ %r{^data:(image|application)/(?<imgtype>[^;]+);(charset=[^;]+;)?base64,(?<imgdata>.+)$} =~ uri
imgtype.sub!(/\+[a-z0-9]+$/, "") # svg+xml
imgtype = "png" unless /^[a-z0-9]+$/.match? imgtype
Tempfile.open(["image", ".#{imgtype}"]) do |f|
f.binmode
f.write(Base64.strict_decode64(imgdata))