Ruby Rails: How to generate QR code images in different color

与世无争的帅哥 提交于 2019-12-08 09:37:46

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!