Class: RQRCode::Renderer::ImageBody
- Inherits:
-
Body
- Object
- Body
- RQRCode::Renderer::ImageBody
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
Instance Method Details
#each {|image.to_blob| ... } ⇒ Object
90
91
92
|
# File 'lib/rqrcode/renderer.rb', line 90
def each
yield image.to_blob
end
|
#image ⇒ Object
82
83
84
85
86
87
88
|
# File 'lib/rqrcode/renderer.rb', line 82
def image
Magick::Image.constitute(width, height, "I", pixels).tap do |image|
image.format = FORMATS[type]
image.scale! scale unless scale == 1
end
end
|
#pixels ⇒ Object
78
79
80
|
# File 'lib/rqrcode/renderer.rb', line 78
def pixels
modules.flatten.map { |dark| COLORS[dark] }
end
|