I'm getting this error when I try to use the rqrcode gem to turn a QR code into a PNG file:
undefined method `as_png' for #<RQRCodeCore::QRCode:0x00007f90b42ec330>
Here is the code:
self.secure_hex = SecureRandom.hex
self.qr_code = RQRCodeCore::QRCode.new("https://app.mapviapp.com/check_ins/new?d=#{self.secure_hex}")
self.qr_code_image = RQRCodeCore::QRCode.new("https://app.mapviapp.com/check_ins/new?d=#{self.secure_hex}").as_png
and the API documentation.
Any thoughts on what could be going wrong?
I'm not sure why you're initializing RGRCodeCore::QRCode instead of RQRCode::QRCode as dinjas pointed out. Try changing it this way as the documentation suggests to do:
require 'rqrcode'
self.secure_hex = SecureRandom.hex
self.qr_code = RQRCode::QRCode.new("https://app.mapviapp.com/check_ins/new?d=#{self.secure_hex}")
self.qr_code_image = RQRCode::QRCode.new("https://app.mapviapp.com/check_ins/new?d=#{self.secure_hex}").as_png
Also, in the code you shared, you create an instance of self.qr_code, which contains the exact string as the self.qr_code_image instance. Are you sure you need that?
Related
Running this example
https://cloud.google.com/vision/docs/face-tutorial?hl=zh-tw
by rails on 'google-cloud-vision', '~> 0.31.0'
got the error
uninitialized constant Google::Cloud::Vision::ImageAnnotator
here's the code
require "google/cloud/vision"
project_id = 'xxxxxx'
vision = Google::Cloud::Vision.new project: project_id
image_annotator = Google::Cloud::Vision::ImageAnnotator.new
Did you added google-cloud-ruby gem in your Gemfile and other google related authentication details into your ruby project.
It turns out that the error was caused because I haven't use the latest version of gcloud-vision(0.32.x)
the way to do what I wanna do in gcloud-vision(0.31.0) is
image = vision.image "path/to/face.jpg"
face = image.face
instead of using class
Google::Cloud::Vision::ImageAnnotator
p ZBar::Image.from_jpeg(qrcode_tag("hello")).process
def qrcode_tag(text)
qr = ::RQRCode::QRCode.new(text).as_png
image = Magick::Image.from_blob((qr).read).first
image.format = 'JPEG'
return image
end
As I know, RQRCode doesn't support png file type, so I tried to convert a qr code that its file type is png to jpeg then an error that I indicated occurred.
ChunkyPNG::Image does not provide a read method. You probably want to call to_datastream on it. See the documentation of the chunky_png gem: http://www.rubydoc.info/github/wvanbergen/chunky_png/ChunkyPNG/Image
I am developing Rails 4 application where have to modify existing PDF file.
User can write some comments and click then comments write in existing PDF as well. For this, i used gem 'pdf-toolkit'
But i got below error:
Error invoking PDFTK
My Code:
my_pdf = PDF::Toolkit.open("Credit_One.pdf")
my_pdf.updated_at = Time.now # ModDate
my_pdf["SomeAttribute"] = "Some value"
my_pdf.save!
Where is wrong any one have a idea.
Thanks
I am trying to write a method that uses the EXIFR gem to retrieve data (in this case camera model) about photos as they are uploaded using Carrierwave. The current method I am using looks like this in my model:
before_save :get_exif_data
def get_exif_data
imgfile = EXIFR::JPEG.new(photo.filename)
return
self.model = imgfile.model
end
However, I get an error "No such file or directory - IMG_0953.JPG" (or another filename).
My goal is to extract the "type of camera" data using the EXIFR gem's .model method before saving. From the EXIFR gem documentation:
EXIFR::JPEG.new('IMG_6841.JPG').model # => "Canon PowerShot G3"
The error suggests to me that my photo.filename has not yet been created. How might I process the image before it is saved?
Actually, something like the following ended up working for me:
before_save :get_camera
private
def get_camera
self.model = EXIFR::JPEG.new(photo.file.path).model
end
end
Try
EXIFR::JPEG.new(Rails.root.to_s + photo.filename_url)
carrierwave return an url look like /uploads/...
its a relative path to webapp, but EXIFR::JPEG will think it a path of system file
I am trying load a file in controller, like
Avatar.all.each do |avatar|
if avatar.avatar_file_name
file = "lib/data/#{avatar.avatar_file_name}"
image = MiniMagick::Image.open("#{file}")
...
end
end
But whenever I run this code, I get the error message
MiniMagick::Invalid
I already tried to reinstall the imagemagick as is mentioned here, but it didn't really help me.
Where could be a problem? Am I missing a component or something?
Thank you
Maybe you should check if file exists first
if File.exist?(file)
image = MiniMagick::Image.open(file)
end
To get path to the file you should do something like this:
file = "#{Rails.root}/lib/data/#{avatar.avatar_file_name}"
btw lib is not the best place to save your images.