问题
I am using rqrcode_png
gem to generate QR codes images in png format https://github.com/DCarper/rqrcode_png.
QR codes are generated successfully in png image format but the color of QR code is black & white and I want to generate QR code in blue & white format.
I search a lot on the internet but not found any answer on this. Also the documentation of rqrcode_png
gem doesn't specify any way to change the color of QR code.
Please help
Thanks,
回答1:
The rqrcode_png
uses chunky_png
to generate images. The colors are defined in rqrcode_png/lib/rqrcode_png/image.rb
module RQRCodePNG
class Image
BLACK = ::ChunkyPNG::Color::BLACK
WHITE = ::ChunkyPNG::Color::WHITE
TRANSPARENT = ::ChunkyPNG::Color::TRANSPARENT
...
I would try to overwrite that method and set blue as a constant
BLUE = ::ChunkyPNG::Color.rgb(0,0,205)
or, you can use the predefined colors in chunky_png
BLUE = ::ChunkyPNG::Color::PREDEFINED_COLORS[:blue]
Have not tested it but it's a theory. Hope it helps.
来源:https://stackoverflow.com/questions/29531726/ruby-rails-how-to-generate-qr-code-images-in-different-color