Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/rvillemeur/qrcode
A QRCode generator for Pharo
https://github.com/rvillemeur/qrcode
pharo pharo-smalltalk qrcode qrcode-generator
Last synced: 3 months ago
JSON representation
A QRCode generator for Pharo
- Host: GitHub
- URL: https://github.com/rvillemeur/qrcode
- Owner: rvillemeur
- License: mit
- Created: 2020-04-13T21:16:09.000Z (almost 5 years ago)
- Default Branch: master
- Last Pushed: 2023-10-28T18:47:35.000Z (about 1 year ago)
- Last Synced: 2024-09-25T21:41:05.329Z (4 months ago)
- Topics: pharo, pharo-smalltalk, qrcode, qrcode-generator
- Language: Smalltalk
- Size: 63.5 KB
- Stars: 8
- Watchers: 1
- Forks: 8
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# 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
```smalltalk
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/```smalltalk
T123Ticket>>#asQRCode^ self url asString asQRCode formWithQuietZone magnifyBy: 5
```It is also easy to combine the QR code with some text:
```smalltalk
T123Ticket >>#asQRCodeWithText| form font |
form := Form extent: 535 @ 185 depth: 1.
font := LogicalFont familyName: ‘Bitmap DejaVu Sans’ pointSize: 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:
```smalltalk
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:
```smalltalk
T123Ticket >>#asJPEGBytes
^ ByteArray streamContents: [ :out |
PluginBasedJPEGReadWriter putForm: self asQRCodeWithTextInTemplate onStream: out ]
```