class Algoheader::PngTransformer

PngTransformer

Author

Dick Davis

Copyright

Copyright 2021 Dick Davis

License

GNU Public License 3

Service object that writes SVG blobs to PNG files.

Attributes

dir[R]
filename[R]
svg[R]

Public Class Methods

new(svg, dir, filename) click to toggle source

rubocop:disable Lint/MissingSuper

# File lib/algoheader/png_transformer.rb, line 35
def initialize(svg, dir, filename)
  @svg = svg
  @dir = dir
  @filename = filename
end

Public Instance Methods

call() click to toggle source

rubocop:enable Lint/MissingSuper

# File lib/algoheader/png_transformer.rb, line 42
def call
  img = Magick::Image.from_blob(svg) do
    self.format = 'SVG'
    self.background_color = 'transparent'
  end
  img[0].write("#{dir}/#{filename}.png")
end