GithubHelp home page GithubHelp logo

Comments (13)

gazeldx avatar gazeldx commented on May 11, 2024 4

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.

nickgnd avatar nickgnd commented on May 11, 2024 2

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.

chrise86 avatar chrise86 commented on May 11, 2024 1

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.

kstratis avatar kstratis commented on May 11, 2024 1

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.

bjornblomqvist avatar bjornblomqvist commented on May 11, 2024

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.

kannathasan-san avatar kannathasan-san commented on May 11, 2024

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.

kannathasan-san avatar kannathasan-san commented on May 11, 2024

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.

bjornblomqvist avatar bjornblomqvist commented on May 11, 2024

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.

chrise86 avatar chrise86 commented on May 11, 2024

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.

bjornblomqvist avatar bjornblomqvist commented on May 11, 2024

Could you post the actual exception message and stacktrace?

from rqrcode.

bjornblomqvist avatar bjornblomqvist commented on May 11, 2024

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.

bjornblomqvist avatar bjornblomqvist commented on May 11, 2024

Do you have stacktrace?

from rqrcode.

samvandamme avatar samvandamme commented on May 11, 2024

@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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.