https://github.com/goquati/qr
A Kotlin Multiplatform library for generating QR codes effortlessly across platforms.
https://github.com/goquati/qr
kotlin kotlin-multiplatform qr-code qr-code-generator
Last synced: 3 months ago
JSON representation
A Kotlin Multiplatform library for generating QR codes effortlessly across platforms.
- Host: GitHub
- URL: https://github.com/goquati/qr
- Owner: goquati
- License: mit
- Created: 2025-01-27T15:04:46.000Z (5 months ago)
- Default Branch: main
- Last Pushed: 2025-01-27T15:27:56.000Z (5 months ago)
- Last Synced: 2025-02-09T13:17:01.632Z (5 months ago)
- Topics: kotlin, kotlin-multiplatform, qr-code, qr-code-generator
- Language: Kotlin
- Homepage:
- Size: 124 KB
- Stars: 0
- Watchers: 0
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# QR Code Generator Library for Kotlin Multiplatform


A Kotlin Multiplatform (KMP) library for generating QR Codes. This library supports all QR Code Model 2 specifications, including versions 1 to 40, all error correction levels, and various encoding modes. It is designed to be lightweight and efficient, providing a flexible API for encoding text, binary data, and more into QR Codes.
## Features
- **Support for all QR Code versions (1–40)**: Generate QR Codes of various sizes.
- **Error correction levels**: Includes support for LOW, MEDIUM, QUARTILE, and HIGH error correction levels.
- **Encoding modes**: Numeric, alphanumeric, byte, and Extended Channel Interpretation (ECI).
- **Immutable and thread-safe**: Designed for concurrent use in a multithreaded environment.
- **Kotlin Multiplatform support**: Can be used on JVM, Android, iOS, and other Kotlin-supported platforms.## Installation
Add the dependency to your `build.gradle.kts` file:
```kotlin
dependencies {
implementation("io.github.goquati:qr:$VERSION")
}
```For multiplatform projects, include the library in the common dependencies block.
```kotlin
kotlin {
sourceSets {
val commonMain by getting {
dependencies {
implementation("io.github.goquati:qr:$VERSION")
}
}
}
}
```Replace `$VERSION` with the latest version available on Maven Central or your preferred package repository.
## Usage
### Encode Text into a QR Code
```kotlin
import io.github.goquati.qr.QrCode
import io.github.goquati.qr.QrCode.Eccval qrCode = QrCode.encodeText("Hello, World!", Ecc.HIGH)
println("QR Code size: ${qrCode.size}")
```### Retrieve Module Data
Access the color of specific modules (pixels) in the QR Code:
```kotlin
for (y in 0 until qrCode.size) {
for (x in 0 until qrCode.size) {
print(if (qrCode[x, y]) "██" else " ")
}
println()
}
```### Encode Binary Data
```kotlin
val binaryData = byteArrayOf(0x01, 0x02, 0x03)
val qrCode = QrCode.encodeBinary(binaryData, Ecc.MEDIUM)
```### Custom Segments
Use segments to optimize encoding and switch between modes:
```kotlin
import io.github.goquati.qr.QrSegmentval qrCode = QrCode.encodeSegments(Ecc.QUARTILE) {
addAlphanumeric("HELLO ")
addNumeric("12345")
}
```## License
This project is licensed under the MIT License. See the [LICENSE](LICENSE) file for details.
## Contributions
Contributions are welcome! Feel free to open an issue or submit a pull request. Please ensure that your code adheres to the existing coding standards and includes appropriate tests.