Comments (13)
I met the same problem today. I fixed it by
replace IO.write("your_image_name.png", png.to_s)
to
png.save("your_image_name.png", :interlace => true)
from rqrcode.
For me :interlace => true
didn't work.
I solved using File.open("path/to/your_image_name.png", 'wb') { |f| f.write(png.to_s) }
The exception is raised by chunky_png
gem, see this issue and this comment
hope it helps!
from rqrcode.
Using that exact example I get:
Encoding::UndefinedConversionError: "\x89" from ASCII-8BIT to UTF-8
Using html works, however, when scanned it only shows the last event.
from rqrcode.
A bit late to the party but bumped to the same problem earlier today.
Managed to put together the pieces and here's the full solution that worked for me:
# Use the `VCardigan` gem to generate the vcard
# Ref: https://github.com/brewster/vcardigan/
@vcard = ::VCardigan.create(:version => '4.0')
@vcard.fullname 'John Smith'
@vcard.tel '+33644608263', :type => 'work'
@vcard.email '[email protected]', :type => 'work'
# Wrap it properly within `RQRCode::QRCode` (Thanks @bjornblomqvist!)
qr = RQRCode::QRCode.new(@vcard.to_s, :level => :l)
# Generate the image (Thanks @nickgnd!)
File.open("/tmp/test.png", 'wb') { |f| f.write(qr.as_png(:size => 600)) }
Hope this gives the full picture and helps someone else in the future!
Peace π
from rqrcode.
You can put whatever you want in the qrcode. I have never created any vCard qrcode myself so i cant tell you how to do it. But if you google and experiment you will probably figure it out.
/BjΓΆrn
from rqrcode.
Thanks for the update.. I tried google and didn't the exact solution.
Can you please give me some example to do it.
My current code will like
def generate_qr_code(field_names, url)
field_string = template.host_url_id.present? ? "Id: #{id} \n" : ""
field_names.each_with_index{|(k, v), index|
break if index == 3
field_string += template.host_url_id.present? ? "#{k}: #{v}\n" : "#{v}\n"
}
field_string = truncate(field_string, :length => 250, omission: "...\n")
field_string += "For more detail click #{url}?product_token=#{auth_token} \n" if template.host_url_id.present?
qr = RQRCode::QRCode.new(field_string)
target="#{Rails.root}/public/system/tmp/#{id}.svg"
File.open(target, "w+") do |f|
f.write(qr.as_svg(offset: 0, color: 'green', shape_rendering: 'crispEdges', module_size: 5))
end
update_attributes(:qr => File.open(target))
system("rm #{target}")
end
end
from rqrcode.
Please advise how to generate Vcard in the above codebase.(when we scan the QR code it should automatically ask like "add to contacts"...)
from rqrcode.
Av far as i can see the only thing you need to do is to use the vcard text as the content of the qrcode. How to create a vcard you will have to figure out youself.
Maybe these pages can help you.
http://snapmyinfo.com/blog/how-to-create-a-business-card-qr-code/
https://lrvick.net/blog/accessibly_importing_vcards_from_qr_codes/
from rqrcode.
I'm having difficulty when trying to generate a vCalendar event too:
BEGIN:VCALENDAR
VERSION:2.0
PRODID:-//bobbin v0.1//NONSGML iCal Writer//EN
CALSCALE:GREGORIAN
METHOD:PUBLISH
BEGIN:VEVENT
DTSTART:20100701T080000Z
DTEND:20100701T110000Z
DTSTAMP:20091130T213238Z
UID:[email protected]
CREATED:20091130T213238Z
DESCRIPTION:Example event 1
LAST-MODIFIED:20091130T213238Z
SEQUENCE:0
STATUS:CONFIRMED
SUMMARY:Example event 1
TRANSP:OPAQUE
END:VEVENT
BEGIN:VEVENT
DTSTART:20100701T120000Z
DTEND:20100701T130000Z
DTSTAMP:20091130T213238Z
UID:[email protected]
CREATED:20091130T213238Z
DESCRIPTION:Example event 2
LAST-MODIFIED:20091130T213238Z
SEQUENCE:0
STATUS:CONFIRMED
SUMMARY:Example event 2
TRANSP:OPAQUE
END:VEVENT
END:VCALENDAR
I get varying code length overflow
issues - can this be done?
from rqrcode.
Could you post the actual exception message and stacktrace?
from rqrcode.
This works for me.
require 'rqrcode'
t = "BEGIN:VCALENDAR
VERSION:2.0
PRODID:-//bobbin v0.1//NONSGML iCal Writer//EN
CALSCALE:GREGORIAN
METHOD:PUBLISH
BEGIN:VEVENT
DTSTART:20100701T080000Z
DTEND:20100701T110000Z
DTSTAMP:20091130T213238Z
UID:[email protected]
CREATED:20091130T213238Z
DESCRIPTION:Example event 1
LAST-MODIFIED:20091130T213238Z
SEQUENCE:0
STATUS:CONFIRMED
SUMMARY:Example event 1
TRANSP:OPAQUE
END:VEVENT
BEGIN:VEVENT
DTSTART:20100701T120000Z
DTEND:20100701T130000Z
DTSTAMP:20091130T213238Z
UID:[email protected]
CREATED:20091130T213238Z
DESCRIPTION:Example event 2
LAST-MODIFIED:20091130T213238Z
SEQUENCE:0
STATUS:CONFIRMED
SUMMARY:Example event 2
TRANSP:OPAQUE
END:VEVENT
END:VCALENDAR"
qrcode = RQRCode::QRCode.new(t, :level => :l)
IO.write("/tmp/vcard-qrcode.png", qrcode.as_png(:size => 600))
from rqrcode.
Do you have stacktrace?
from rqrcode.
@bjornblomqvist I have a stack trace of the same problem:
2.3.3 :028 > IO.write("/tmp/github-qrcode.png", png.to_s)
Encoding::UndefinedConversionError: "\x89" from ASCII-8BIT to UTF-8
from (irb):28:in `write'
from (irb):28
from /Users/sam/.rvm/gems/ruby-2.3.3/gems/railties-5.0.1/lib/rails/commands/console.rb:65:in `start'
from /Users/sam/.rvm/gems/ruby-2.3.3/gems/railties-5.0.1/lib/rails/commands/console_helper.rb:9:in `start'
from /Users/sam/.rvm/gems/ruby-2.3.3/gems/railties-5.0.1/lib/rails/commands/commands_tasks.rb:78:in `console'
from /Users/sam/.rvm/gems/ruby-2.3.3/gems/railties-5.0.1/lib/rails/commands/commands_tasks.rb:49:in `run_command!'
from /Users/sam/.rvm/gems/ruby-2.3.3/gems/railties-5.0.1/lib/rails/commands.rb:18:in `<top (required)>'
from /Users/sam/.rvm/gems/ruby-2.3.3/gems/skylight-1.0.1/lib/skylight/probes.rb:81:in `require'
from /Users/sam/.rvm/gems/ruby-2.3.3/gems/skylight-1.0.1/lib/skylight/probes.rb:81:in `require'
from /Users/sam/.rvm/gems/ruby-2.3.3/gems/activesupport-5.0.1/lib/active_support/dependencies.rb:293:in `block in require'
from /Users/sam/.rvm/gems/ruby-2.3.3/gems/activesupport-5.0.1/lib/active_support/dependencies.rb:259:in `load_dependency'
from /Users/sam/.rvm/gems/ruby-2.3.3/gems/activesupport-5.0.1/lib/active_support/dependencies.rb:293:in `require'
from /Users/sam/Dropbox/Private/Development/Trixx/projects/trixx/code/website_app/trixx/bin/rails:9:in `<top (required)>'
from /Users/sam/.rvm/gems/ruby-2.3.3/gems/activesupport-5.0.1/lib/active_support/dependencies.rb:287:in `load'
from /Users/sam/.rvm/gems/ruby-2.3.3/gems/activesupport-5.0.1/lib/active_support/dependencies.rb:287:in `block in load'
from /Users/sam/.rvm/gems/ruby-2.3.3/gems/activesupport-5.0.1/lib/active_support/dependencies.rb:259:in `load_dependency'
from /Users/sam/.rvm/gems/ruby-2.3.3/gems/activesupport-5.0.1/lib/active_support/dependencies.rb:287:in `load'
from /Users/sam/.rvm/gems/ruby-2.3.3/gems/spring-2.0.0/lib/spring/commands/rails.rb:6:in `call'
from /Users/sam/.rvm/gems/ruby-2.3.3/gems/spring-2.0.0/lib/spring/command_wrapper.rb:38:in `call'
from /Users/sam/.rvm/gems/ruby-2.3.3/gems/spring-2.0.0/lib/spring/application.rb:191:in `block in serve'
from /Users/sam/.rvm/gems/ruby-2.3.3/gems/spring-2.0.0/lib/spring/application.rb:161:in `fork'
from /Users/sam/.rvm/gems/ruby-2.3.3/gems/spring-2.0.0/lib/spring/application.rb:161:in `serve'
from /Users/sam/.rvm/gems/ruby-2.3.3/gems/spring-2.0.0/lib/spring/application.rb:131:in `block in run'
from /Users/sam/.rvm/gems/ruby-2.3.3/gems/spring-2.0.0/lib/spring/application.rb:125:in `loop'
from /Users/sam/.rvm/gems/ruby-2.3.3/gems/spring-2.0.0/lib/spring/application.rb:125:in `run'
from /Users/sam/.rvm/gems/ruby-2.3.3/gems/spring-2.0.0/lib/spring/application/boot.rb:19:in `<top (required)>'
from /Users/sam/.rvm/rubies/ruby-2.3.3/lib/ruby/site_ruby/2.3.0/rubygems/core_ext/kernel_require.rb:55:in `require'
from /Users/sam/.rvm/rubies/ruby-2.3.3/lib/ruby/site_ruby/2.3.0/rubygems/core_ext/kernel_require.rb:55:in `require'
from -e:1:in `<main>'
from rqrcode.
Related Issues (20)
- Encore text in UTF-8 with ECI (Extended Channel Interpretation) HOT 1
- Resulting image blank HOT 3
- Problem SVG in PDF
- RQRCodeCore HOT 2
- SVG formatting is done with style attribute instead of fill, causing strict content security policies to fail
- How to set width and height of generated svg HOT 1
- Logo/text in center HOT 2
- Can't generate black QR codes using `000000` HOT 1
- An error occurred while updating rqcode
- undefined method `dark?' for #<RQRCode::QRCode:0x00005649dee622a0 HOT 2
- Rails HTML safe strings HOT 2
- The examples under the "Advanced Options" section in the README.md do not work HOT 1
- Lacking a CHANGELOG.md file HOT 2
- Not able to create image HOT 3
- Attributing Source HOT 1
- Edit @data of RQRCode::QRCode instance HOT 1
- Ability to add image to centre of QR code HOT 4
- Production server problem
- Logo inclusion HOT 2
- Ruby 3.0 support HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
π Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. πππ
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google β€οΈ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from rqrcode.