Skip to content
forked from rvillemeur/QRCode

A QRCode generator for Pharo

License

Notifications You must be signed in to change notification settings

OpenSmock/QRCode

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

18 Commits
 
 
 
 
 
 
 
 

Repository files navigation

QRCode

A QRCode generator for Pharo. QR Code generation based on the latest specifications: ISO/IEC 18004:2006(E). It includes generation of MicroQR codes, though these are not recommended for general use because few readers are available. The generation code is meant as a service for other applications; however, a small Zinc web application is included to generate QR code images.

'http://pharo.org' asQRCode form magnifyBy: 10

history

Initial code was created by Jochen Rick and hosted on smalltalkhub. http://smalltalkhub.com/#!/~JochenRick/QRCode/

loading

Metacello new
	baseline: 'QRCode';
	repository: 'github://rvillemeur/QRCode/src';
	load

usage

initial quote on using: https://pharoweekly.wordpress.com/2018/04/13/qrcode-a-thank-you-note/

T123Ticket>>#asQRCode

^ self url asString asQRCode formWithQuietZone magnifyBy: 5

It is also easy to combine the QR code with some text:

T123Ticket >>#asQRCodeWithText

| form font |
form := Form extent: 535 @ 185 depth: 1.
font := LogicalFont familyName:Bitmap DejaVu SanspointSize: 14.
self asQRCode displayOn: form at: 0 @ 0.
form getCanvas
drawString: self url asString at: 180 @ 20 font: font color: Color black;
drawString: self id36, ‘ – ‘, ticketId asString at: 180 @ 45 font: font color: Color black;
drawString: (name ifNil: [ ‘N.N’ ]) at: 180 @ 90  font: font color: Color black;
drawString: (email ifNil: [ ‘@’ ]) at: 180 @ 115 font: font color: Color black;
drawString: (phone ifNil: [ ‘+’ ]) at: 180 @ 140 font: font color: Color black.
^ form

Next we combine this with a nice template designed by a graphics artist:

T123Ticket >>#asQRCodeWithTextInTemplate
| templateFile form |
templateFile := ‘tickets123-template-{1}.jpg’ format: { self event id }.
form := PluginBasedJPEGReadWriter formFromFileNamed: templateFile.
self asQRCodeWithText displayOn: form at: 20@540.
^ form

And finally, the ticket form is encoded as a JPEG:

T123Ticket >>#asJPEGBytes
^ ByteArray streamContents: [ :out |
PluginBasedJPEGReadWriter putForm: self asQRCodeWithTextInTemplate onStream: out ]

About

A QRCode generator for Pharo

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Smalltalk 100.0%