Class: RQRCode::Renderer::ImageBody

Inherits:
Body
  • Object
show all
Defined in:
lib/rqrcode/renderer.rb

Constant Summary collapse

FORMATS =
Hash[*Magick.formats.select { |key, value| value.include? 'w' }.map do |key, value|
  extension = key.downcase
  MIME::Types.of(extension).select { |type| type.media_type == "image" }.map do |type|
    Mime::Type.register type.to_s, extension unless Mime::Type.lookup_by_extension extension
    [type.to_s, key]
  end
end.flatten.compact].freeze
TYPES =
FORMATS.keys.freeze
COLORS =
{true => 0, false => Magick::QuantumRange}.freeze

Instance Attribute Summary

Attributes inherited from Body

#modules, #options, #type

Instance Method Summary collapse

Methods inherited from Body

#height, #initialize, new, #scale, #width

Constructor Details

This class inherits a constructor from RQRCode::Renderer::Body

Instance Method Details

#each {|image.to_blob| ... } ⇒ Object

Yields:



90
91
92
# File 'lib/rqrcode/renderer.rb', line 90

def each
  yield image.to_blob
end

#imageObject



82
83
84
85
86
87
88
# File 'lib/rqrcode/renderer.rb', line 82

def image
  # "I" = greyscale integers
  Magick::Image.constitute(width, height, "I", pixels).tap do |image|
    image.format = FORMATS[type]
    image.scale! scale unless scale == 1
  end
end

#pixelsObject



78
79
80
# File 'lib/rqrcode/renderer.rb', line 78

def pixels
  modules.flatten.map { |dark| COLORS[dark] }
end