Module: SvgInlineFileExtractor

Defined in:
lib/svg_inline_file_extractor.rb,
lib/svg_inline_file_extractor/version.rb,
lib/svg_inline_file_extractor/svg_file.rb,
lib/svg_inline_file_extractor/inline_image.rb

Defined Under Namespace

Classes: InlineImage, MiniMagickMissing, SvgFile

Constant Summary collapse

VERSION =
"0.2.5"

Class Method Summary collapse

Class Method Details

.binary_images(xml_string) ⇒ Array<String>

Returns an array of binary strings containing the images in the SVG file.

Parameters:

  • xml_string (String)

    should be a full raw SVG file

Returns:

  • (Array<String>)

    an array of binary strings containing the images in the SVG file



10
11
12
# File 'lib/svg_inline_file_extractor.rb', line 10

def self.binary_images(xml_string)
  SvgFile.binary_images(xml_string)
end

.identify_image(uri) ⇒ String | Nil

Note:

will return nil if MiniMagick is not present

Returns image type determined by MiniMagick.

Parameters:

  • uri (String)

    a URI to open and identify.

Returns:

  • (String | Nil)

    image type determined by MiniMagick.



24
25
26
27
28
29
30
# File 'lib/svg_inline_file_extractor.rb', line 24

def self.identify_image(uri)
  if use_mini_magick?
    return with_temp_image(uri) do |temp_image|
      MiniMagick::Image.open(temp_image).type.downcase
    end
  end
end

.inline_images(xml_string) ⇒ Array<InlineImage>

Returns an array of the inline images found in the document.

Parameters:

  • xml_string (String)

    should be a full raw SVG file

Returns:

  • (Array<InlineImage>)

    an array of the inline images found in the document

See Also:



17
18
19
# File 'lib/svg_inline_file_extractor.rb', line 17

def self.inline_images(xml_string)
  SvgFile.inline_images(xml_string)
end

.use_mini_magick?Boolean

Returns true if MiniMagick is found, false if not.

Returns:

  • (Boolean)

    true if MiniMagick is found, false if not.



33
34
35
# File 'lib/svg_inline_file_extractor.rb', line 33

def self.use_mini_magick?
  Object.const_defined?('MiniMagick::Image')
end

.with_temp_image(uri) ⇒ Object

do something with a temporary copy of uri in a block.

Parameters:

  • uri (String)
    • the location of the file to open into a temp file.



39
40
41
42
43
44
45
46
47
48
# File 'lib/svg_inline_file_extractor.rb', line 39

def self.with_temp_image(uri)
  temp = Tempfile.new('inline_image')
  temp.binmode
  puts "opening #{uri}"
  temp.write open(uri).binmode.read
  temp.close
  results = yield temp.path
  temp.delete
  results
end