Can‘t generate PNG without setting path.
kncxstudio opened this issue · 3 comments
Can‘t generate PNG without setting path (default options).
It works when I setting the path when generate PNG.
require 'rqrcode'
qrcode = RQRCode::QRCode.new('http://github.com/')
png = qrcode.as_png(
resize_gte_to: false,
resize_exactly_to: false,
fill: 'white',
color: 'black',
size: 120,
border_modules: 4,
module_px_size: 6,
file: nil # path to write
)IO.write('./test.png', png.to_s)
It didn't work.
require 'rqrcode'
qrcode = RQRCode::QRCode.new('http://github.com/')
png = qrcode.as_png(
resize_gte_to: false,
resize_exactly_to: false,
fill: 'white',
color: 'black',
size: 120,
border_modules: 4,
module_px_size: 6,
file: './test.png'
)
It works!
Have you figured out why i didnt work for you?
try this, file: "#{Rails.root}/tmp/github-qrcode.png" is working on windows
@kncxstudio I have just run code that you provided inside a script (call the file pngtest.rb
) using ruby 2.5.1 and rqrcode v0.10.1 and the example run without issues:
#!/bin/env ruby
require 'rqrcode'
qrcode = RQRCode::QRCode.new('http://github.com/')
png = qrcode.as_png(
resize_gte_to: false,
resize_exactly_to: false,
fill: 'white',
color: 'black',
size: 120,
border_modules: 4,
module_px_size: 6,
file: nil # path to write
)
IO.write('test.png', png.to_s) # only removed the ./ but runs fine without it also
Then run pngtest.rb
should see test.png
on the same directory has the script.
Can you provide more context on the system that you are running including gem version and any error?