Sha256: c85de1a75134b1d95572edd3025cf254041574ea64f88f47473b2d1b137d516d

Contents?: true

Size: 818 Bytes

Versions: 4

Compression:

Stored size: 818 Bytes

Contents

# frozen-string-literal: true

module ChunkyPNG
  class Canvas
    # Methods to import a canvas from a PNG data URL.
    module DataUrlImporting
      # Imports a canvas from a PNG data URL.
      # @param [String] string The data URL string to load from.
      # @return [Canvas] The imported canvas.
      # @raise ChunkyPNG::SignatureMismatch if the provides string is not a properly
      #    formatted PNG data URL (i.e. it should start with "data:image/png;base64,")
      def from_data_url(string)
        if string =~ %r[^data:image/png;base64,((?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=)?)$]
          from_blob($1.unpack("m").first)
        else
          raise SignatureMismatch, "The string was not a properly formatted data URL for a PNG image."
        end
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
chunky_png-1.4.0 lib/chunky_png/canvas/data_url_importing.rb
chunky_png-1.3.15 lib/chunky_png/canvas/data_url_importing.rb
chunky_png-1.3.14 lib/chunky_png/canvas/data_url_importing.rb
chunky_png-1.3.13 lib/chunky_png/canvas/data_url_importing.rb