class Asciidoctor::AbstractNode
def generate_data_uri_from_uri image_uri, cache_uri = false
Returns A data URI string built from Base64 encoded data read from the URI
is used to cache the image for subsequent reads. (default: false)
cache_uri - A Boolean to control caching. When true, the open-uri-cached library
image_uri - The URI from which to read the image data. Can be http://, https:// or ftp://
which can then be used in an image tag.
constructed from the content_type header and Base64 data and returned,
The image data is read from the URI and converted to Base64. A data URI is
Public: Read the image data from the specified URI and generate a data URI
def generate_data_uri_from_uri image_uri, cache_uri = false if cache_uri # caching requires the open-uri-cached gem to be installed # processing will be automatically aborted if these libraries can't be opened Helpers.require_library 'open-uri/cached', 'open-uri-cached' elsif !RUBY_ENGINE_OPAL # autoload open-uri ::OpenURI end begin mimetype, bindata = ::OpenURI.open_uri(image_uri, URI_READ_MODE) {|f| [f.content_type, f.read] } # NOTE pack 'm0' is equivalent to Base64.strict_encode64 %(data:#{mimetype};base64,#{[bindata].pack 'm0'}) rescue logger.warn %(could not retrieve image data from URI: #{image_uri}) image_uri # uncomment to return empty data (however, mimetype needs to be resolved) #%(data:#{mimetype}:base64,) # uncomment to return 1 pixel white dot instead #'data:image/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw==' end end