Last active
July 17, 2021 09:26
-
-
Save dmitryfry/914edef3031e3f1f070e2963ae2bf551 to your computer and use it in GitHub Desktop.
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
class QrCodeController < ApplicationController | |
include Magick | |
def generate(issue_id, voucher_id) | |
qrcode = RQRCode::QRCode.new("https://example.com/issues/#{issue_id}") | |
# NOTE: showing with default options specified explicitly | |
png = qrcode.as_png( | |
bit_depth: 1, | |
border_modules: 4, | |
color_mode: ChunkyPNG::COLOR_GRAYSCALE, | |
color: 'black', | |
file: nil, | |
fill: 'white', | |
module_px_size: 6, | |
resize_exactly_to: false, | |
resize_gte_to: false, | |
size: 170 | |
) | |
IO.binwrite("public/images/voucher_#{voucher_id}.png", png.to_s) | |
add_logo_and_text(issue_id, voucher_id) | |
end | |
def add_logo_and_text(issue_id, voucher_id) | |
# now watermark with logo | |
# magick composite -gravity center App_qr_icon_small.png li-source.png final.png | |
my_text = "#{Issue.find_by_id(issue_id).custom_field_value(67)} #{CustomField.find_by_id(67).name}" | |
qr_image = Image.read("public/images/voucher_#{voucher_id}.png")[0] | |
logo_image = Image.read("plugins/qr_code/assets/images/shell_qr_logo.png")[0] | |
image_with_logo = qr_image.composite( logo_image, CenterGravity, OverCompositeOp) | |
draw = Magick::Draw.new | |
draw.annotate(image_with_logo, 0, 0, 55, 3, my_text) do | |
# self.font = Helvetica | |
self.pointsize = 12 | |
self.font_weight = Magick::BoldWeight | |
self.fill = "#000" | |
self.gravity = Magick::SouthEastGravity | |
end | |
image_with_logo.write("public/images/voucher_#{voucher_id}.png") | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment