Sha256: 1bee8d15c95297121f647c2754dadcda1a8aacc0824ac51acac03ecc2ae87ac0
Contents?: true
Size: 1.61 KB
Versions: 10
Compression:
Stored size: 1.61 KB
Contents
require 'rsvg2' require 'rexml/document' require_relative '../frame' require_relative 'abstract_image_reader' module Phantom module SVG module Parser # JPEG reader. class JPEGReader < AbstractImageReader # Read jpeg file from path. def read(path, _options = {}) reset return if path.nil? || path.empty? frame = create_frame(path) @frames << frame @width = "#{frame.width}px" @height = "#{frame.height}px" end private # Create frame. def create_frame(path, duration = nil) pixbuf = Gdk::Pixbuf.new(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. 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 end # class JPEGReader end # module Parser end # module SVG end # module Phantom
Version data entries
10 entries across 10 versions & 1 rubygems