Sha256: 14930c60b04e2dbd99c9e8689e479743b4f71ffc6b16bf37d5db426cc97a2c18

Contents?: true

Size: 438 Bytes

Versions: 4

Compression:

Stored size: 438 Bytes

Contents

require 'base64'

module Prawn::SVG::Loaders
  class Data
    REGEXP = %r[\Adata:image/(png|jpeg);base64(;[a-z0-9]+)*,]i

    def from_url(url)
      return if url[0..4].downcase != "data:"

      matches = url.match(REGEXP)
      if matches.nil?
        raise Prawn::SVG::UrlLoader::Error, "prawn-svg only supports base64-encoded image/png and image/jpeg data URLs"
      end

      Base64.decode64(matches.post_match)
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
prawn-svg-0.33.0 lib/prawn/svg/loaders/data.rb
prawn-svg-0.32.0 lib/prawn/svg/loaders/data.rb
prawn-svg-0.31.0 lib/prawn/svg/loaders/data.rb
prawn-svg-0.30.0 lib/prawn/svg/loaders/data.rb