Created
December 19, 2023 10:15
-
-
Save sbounmy/41987e269338be4fae93a65fbf14fba4 to your computer and use it in GitHub Desktop.
Generate a QRCode BIP 21 with Bitcoin logo at its center
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'image_processing/vips' | |
require 'rqrcode' | |
qrcode_uri = "bitcoin:my-btc-address?amount=0.000015" | |
qrcode = RQRCode::QRCode.new(qrcode_uri) | |
options = { bit_depth: 1, | |
border_modules: 4, | |
color_mode: ChunkyPNG::COLOR_GRAYSCALE, | |
color: 'black', | |
file: 'qqrcode.png', | |
fill: 'white', | |
module_px_size: 6, | |
resize_exactly_to: false, | |
resize_gte_to: false, | |
size: 1200 } | |
dir = File.expand_path(File.dirname(__FILE__)) | |
logo_path = File.join(dir, 'bitcoin.svg') | |
logo_image = ImageProcessing::Vips.source(logo_path).resize_to_fit(300, 300).call(save: false) | |
tmp = Tempfile.new(['qrcode_image', '.png']) | |
qrcode.as_png(options).save(tmp.path) | |
qr = ImageProcessing::Vips.source(tmp).call(save: false) | |
center_x = (qr.width - logo_image.width) / 2 | |
center_y = (qr.height - logo_image.height) / 2 | |
qrcode_image = ImageProcessing::Vips.source(qr).composite(logo_image, gravity: 'south-west', offset: [center_x, center_y]).call(save: false) | |
result_path = File.join(File.dirname(__FILE__), 'qrcode_with_logo.jpg') | |
qrcode_image.write_to_file(result_path) | |
puts "QR code with logo saved to #{result_path}" | |
tmp.close | |
tmp.unlink |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
result

To test scan with a wallet (I tried with Binance)