Class: Algoheader::PngTransformer

Inherits:
ServiceObject show all
Defined in:
lib/algoheader/png_transformer.rb

Overview

PngTransformer

Author

Dick Davis

Copyright

Copyright 2021 Dick Davis

License

GNU Public License 3

Service object that writes SVG blobs to PNG files.

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from ServiceObject

call

Constructor Details

#initialize(svg, dir, filename) ⇒ PngTransformer

rubocop:disable Lint/MissingSuper



35
36
37
38
39
# File 'lib/algoheader/png_transformer.rb', line 35

def initialize(svg, dir, filename)
  @svg = svg
  @dir = dir
  @filename = filename
end

Instance Attribute Details

#dirObject (readonly)

Returns the value of attribute dir.



32
33
34
# File 'lib/algoheader/png_transformer.rb', line 32

def dir
  @dir
end

#filenameObject (readonly)

Returns the value of attribute filename.



32
33
34
# File 'lib/algoheader/png_transformer.rb', line 32

def filename
  @filename
end

#svgObject (readonly)

Returns the value of attribute svg.



32
33
34
# File 'lib/algoheader/png_transformer.rb', line 32

def svg
  @svg
end

Instance Method Details

#callObject

rubocop:enable Lint/MissingSuper



42
43
44
45
46
47
48
# 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