class Phantom::SVG::Parser::JPEGReader
JPEG reader.
Public Instance Methods
read(path, _options = {})
click to toggle source
Read jpeg file from path.
# File lib/phantom/parser/jpeg_reader.rb, line 13 def read(path, _options = {}) reset return if path.nil? || path.empty? frame = create_frame(path) @frames << frame @width = "#{frame.width}" @height = "#{frame.height}" end
Private Instance Methods
create_frame(path, duration = nil)
click to toggle source
Create frame.
# File lib/phantom/parser/jpeg_reader.rb, line 27 def create_frame(path, duration = nil) pixbuf = GdkPixbuf::Pixbuf.new(file: path) frame = Phantom::SVG::Frame.new frame.width = "#{pixbuf.width}px" frame.height = "#{pixbuf.height}px" frame.viewbox.set_from_text("0 0 #{pixbuf.width} #{pixbuf.height}") frame.surfaces = create_surfaces(path, pixbuf.width, pixbuf.height) frame.duration = duration unless duration.nil? frame.namespaces = { 'xmlns' => 'http://www.w3.org/2000/svg', 'xlink' => 'http://www.w3.org/1999/xlink' } frame end
create_surfaces(path, width, height)
click to toggle source
Create surfaces.
# File lib/phantom/parser/jpeg_reader.rb, line 42 def create_surfaces(path, width, height) bin = File.binread(path) base64 = [bin].pack('m') image = REXML::Element.new('image') image.add_attributes( 'width' => width, 'height' => height, 'xlink:href' => "data:image/jpeg;base64,#{base64}" ) [image] end