Sha256: 95b12737acba66fd292ce2cd15cd1bde43a809ff83777efde3f94519dc27a26a

Contents?: true

Size: 789 Bytes

Versions: 22

Compression:

Stored size: 789 Bytes

Contents

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

22 entries across 20 versions & 5 rubygems

Version Path
chunky_png-1.3.11 lib/chunky_png/canvas/data_url_importing.rb
chunky_png-1.3.10 lib/chunky_png/canvas/data_url_importing.rb
chunky_png-1.3.9 lib/chunky_png/canvas/data_url_importing.rb
arcabouco-0.2.13 vendor/bundle/gems/chunky_png-1.3.8/lib/chunky_png/canvas/data_url_importing.rb
arcabouco-0.2.13 vendor/bundle/gems/chunky_png-1.3.6/lib/chunky_png/canvas/data_url_importing.rb
chunky_png-1.3.8 lib/chunky_png/canvas/data_url_importing.rb
second_step-0.1.2 secondstep-notify-1.0.0-osx/lib/ruby/lib/ruby/gems/2.2.0/gems/chunky_png-1.3.7/lib/chunky_png/canvas/data_url_importing.rb
chunky_png-1.3.7 lib/chunky_png/canvas/data_url_importing.rb
chunky_png-1.3.6 lib/chunky_png/canvas/data_url_importing.rb
bench9000-0.1 vendor/chunky_png/lib/chunky_png/canvas/data_url_importing.rb
chunky_png-1.3.5 lib/chunky_png/canvas/data_url_importing.rb
chunky_png-1.3.4 lib/chunky_png/canvas/data_url_importing.rb
chunky_png-1.3.3 lib/chunky_png/canvas/data_url_importing.rb
chunky_png-1.3.2 lib/chunky_png/canvas/data_url_importing.rb
chunky_png-1.3.1 lib/chunky_png/canvas/data_url_importing.rb
sadui-0.0.4 vendor/bundle/ruby/2.0.0/gems/chunky_png-1.3.0/lib/chunky_png/canvas/data_url_importing.rb
sadui-0.0.4 vendor/bundle/ruby/2.1.0/gems/chunky_png-1.3.0/lib/chunky_png/canvas/data_url_importing.rb
chunky_png-1.3.0 lib/chunky_png/canvas/data_url_importing.rb
chunky_png-1.2.9 lib/chunky_png/canvas/data_url_importing.rb
chunky_png-1.2.8 lib/chunky_png/canvas/data_url_importing.rb