Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/jd557/qrgen
Scala port of https://github.com/nayuki/QR-Code-generator
https://github.com/jd557/qrgen
qrcode qrcode-generator scala scala-js scala-native
Last synced: 4 days ago
JSON representation
Scala port of https://github.com/nayuki/QR-Code-generator
- Host: GitHub
- URL: https://github.com/jd557/qrgen
- Owner: JD557
- License: other
- Created: 2024-12-29T16:48:47.000Z (12 days ago)
- Default Branch: master
- Last Pushed: 2025-01-04T13:44:43.000Z (7 days ago)
- Last Synced: 2025-01-06T17:28:15.832Z (4 days ago)
- Topics: qrcode, qrcode-generator, scala, scala-js, scala-native
- Language: Scala
- Homepage:
- Size: 135 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# QRgen
An opinionated port of https://github.com/nayuki/QR-Code-generator to Scala.
Targets the JVM, JS and Native.
## Usage examples
Print QR Code to the standard output:
```scala
//> using scala 3.3.4
//> using dep eu.joaocosta::qrgen::0.1.0import eu.joaocosta.qrgen.*
val qrCode = QrCode.encodeText("https://www.scala-lang.org/", Ecc.LOW)
qrCode.foreach { line =>
println(line.map(x => if (x) "\u2588" else " ").mkString)
}
```Store QR Code as a BMP:
```scala
//> using scala 3.3.4
//> using dep eu.joaocosta::qrgen::0.1.0
//> using dep eu.joaocosta::minart::0.6.2import eu.joaocosta.minart.backend.defaults.given
import eu.joaocosta.minart.graphics.*
import eu.joaocosta.minart.graphics.image.Image
import eu.joaocosta.minart.runtime.Resource
import eu.joaocosta.qrgen.*val qrCode = QrCode.encodeText("https://www.scala-lang.org/", Ecc.LOW)
val surface = RamSurface(
qrCode.map(_.map(set => Color.grayscale(if (set) 0 else 255)))
)Image.storeBmpImage(surface.view.scale(4), Resource("qrcode.bmp"))
```## Differences from the Java version
The code here was heavily based on [nayuki/QR-Code-generator/java](https://github.com/nayuki/QR-Code-generator/tree/master/java),
with a few differences, some of which include:- Splitting the code in smaller, self contained classes
- Favor immutability (there's still some internal mutability, though)
- Remove `QrSegmentAdvanced`
- Use `String` instead of `CharSequence`
- Make QR Codes extend `IndexedSeq[IndexedSeq[Boolean]]`This can have some performance impact, so the original version might be faster.