QR Codes

Thomas Bennett bennetttm at APPSTATE.EDU
Mon Apr 16 13:44:58 EDT 2012


I've used PyQRNative, ported from the Javascript Library, with python and Zope. 

#QRCode for Javascript
http://d-project.googlecode.com/svn/trunk/misc/qrcode/js/qrcode.js

 The code below, written for use with a form on our WEB site, could probably be easily modified for ModPython or command line script and save PNG file to disk.  PyQRNative requires PIL (Python Imaging Library) to be installed.


Thomas


def pqn(self,qr_type,my_url,lastname,firstname,organization,job_title,phone_number,address,my_email,message,subject):

  from PyQRNative import *
  from StringIO import StringIO
  from OFS.Image import manage_addImage

  # DATA
  qr = QRCode(24, QRErrorCorrectLevel.L)
  my_image_id = "pqn_test.png"
  if qr_type in ['short_url','long_url','vcard','message','telephone','sms','email','geo','anytelephone'] :

    if qr_type=='long_url':
      qr.addData(my_url)
      my_image_id="pqn_url.png"

    elif qr_type=='short_url':
      qr = QRCode(4, QRErrorCorrectLevel.L)
      qr.addData(my_url)
      my_image_id = "pqn_url.png"

    elif qr_type=='vcard':
      qr = QRCode(12, QRErrorCorrectLevel.L)   # NEED TO ADJUST FOR MORE DATA
      qr.addData("MECARD:N:%s, %s;ADR:%s;TEL:+1828262%s;E:%s;URL:%s;NOTE:%s %s;;"%(lastname,firstname,address,str(phone_number),my_email,my_url,organization,job_title))
      my_image_id = "pqn_vcard.png"

    elif qr_type=='message':
      qr.addData("TEXT:%s"%message)
      my_image_id = "pqn_message.png"

    elif qr_type=='telephone':
      qr = QRCode(2, QRErrorCorrectLevel.L)
      qr.addData("tel:+1828262%s"%phone_number)
      my_image_id = "pqn_telephone.png"

    elif qr_type=='anytelephone':
      qr = QRCode(2, QRErrorCorrectLevel.L)
      qr.addData("tel:+%s"%phone_number)
      my_image_id = "pqn_telephone.png"

    elif qr_type=='sms':
      qr = QRCode(2, QRErrorCorrectLevel.L)   # NEED TO ADJUST FOR DATA
      qr.addData("sms:+1828%s"%(phone_number))
      my_image_id = "pqn_sms.png"

    elif qr_type=='email':
      qr = QRCode(2, QRErrorCorrectLevel.L)   # NEED TO ADJUST FOR DATA
      qr.addData("mailto:%s"%(email))
      my_image_id = "pqn_sms.png"

    elif qr_type=='geo':
      qr = QRCode(2, QRErrorCorrectLevel.L)
      qr.addData("geo:36.2,-81.2")
      my_image_id = "pqn_geo.png"

    qr.make()
    im = qr.makeImage()

    # PUT THE IMAGE INTO MEMORY AND SAVE IMAGE TO MEMORY
    imageFile = StringIO()
    im.save(imageFile,"png")

    # IF THERE IS A pqn_test.png IN THE CURRENT DIRECTORY, DELETE IT SO UNDO WON'T BUILD UP THE UNDO OR HISTORY
    if my_image_id in self.objectIds():
      self.manage_delObjects([my_image_id])
    #  Add image to directory in Zope
    manage_addImage(self,my_image_id,imageFile)

    # WRITE THE IMAGE AND FORM CODE TO THE PAGE
    # These sizes seem to work well for Andoid and IPhone QR Code readers.
    if qr_type=='vcard':
      my_text = '\n<img src="%s" height=250px width=250px><br />%s' %(my_image_id,my_image_id)
    else:
      my_text = '\n<img src="%s" height=125px width=125px><br />%s' %(my_image_id,my_image_id)
  else:
    my_text = '<h2>DATA ERROR - incorrect qr_type</h2>'
  return my_text




====================================================
Thomas McMillan Grant Bennett           Appalachian State University
Operations & Systems Analyst            P O Box 32026
University Library                                Boone, North Carolina 28608
(828) 262 6587
Library Systems                              http://www.library.appstate.edu
====================================================

On Apr 13, 2012, at 6:17 PM, wylie ackerman wrote:

> You can use Google’s chart API (https://google-developers.appspot.com/chart/infographics/docs/qr_codes) to generate dynamic images for display on the web (you can also copy and paste them into other apps).
>  
> Sample QR Code:  https://chart.googleapis.com/chart?chs=500x500&cht=qr&choe=UTF-8&chl=http%3a%2f%2fwww.deschuteslibrary.org
>  
> I’m using it to dynamically insert QR codes into our catalog:  http://catalog.dpls.lib.or.us/record=b1435909
>  
>  
> Wylie Ackerman
> eServices Manager
> Deschutes Public Library
> (541) 312-1042
> http://www.deschuteslibrary.org
>  
>  
> From: Web technologies in libraries [mailto:WEB4LIB at LISTSERV.ND.EDU] On Behalf Of Liz Hubert
> Sent: Friday, April 13, 2012 2:56 PM
> To: WEB4LIB at LISTSERV.ND.EDU
> Subject: [WEB4LIB] QR Codes
>  
> Hi all,
>  
> I could use a little help. For the past year or two, I've been doing a lot of work with QR codes at my library. We've got a pretty good program going, and I'm really excited about it. We have unfortunately run into problems with the longevity of our codes as well as flaky creators. We first used Kaywa to create codes, but our codes all died about four months after we created them. We've been using myqr.co since, but have been noticing lots of problems with the generator in the past month or so. We're ready to switch. I know lots and lots of creators since I've researched this extensively, but I'd like to get your feedback. Has anyone been using the same creator for a significant period of time? I don't care much about how they look, since we have a great graphic designer. I put the codes through bitly, so it doesn't need to have a tracker either. I really just need something that is reliable and will last a long time. Can anyone share their experiences? I'd be so grateful!
> ============================
> To unsubscribe: http://bit.ly/web4lib
> 
> Web4Lib Web Site: http://web4lib.org/
> 
> 2012-04-13
> 
> ============================
> To unsubscribe: http://bit.ly/web4lib
> 
> Web4Lib Web Site: http://web4lib.org/
> 
> 2012-04-13
> 


============================

To unsubscribe: http://bit.ly/web4lib

Web4Lib Web Site: http://web4lib.org/

2012-04-16
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://listserv.nd.edu/pipermail/web4lib/attachments/20120416/c8d20e8e/attachment.htm>


More information about the Web4lib mailing list