npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

qrcode-kotlin

v4.1.1

Published

[![License](https://img.shields.io/github/license/g0dkar/qrcode-kotlin)](LICENSE) [![Maven Central](https://img.shields.io/maven-central/v/io.github.g0dkar/qrcode-kotlin.svg?label=Maven%20Central)](https://search.maven.org/search?q=g:%22io.github.g0dkar%2

Downloads

17

Readme

QRCode-Kotlin

License Maven Central

💚 Disponível em Português (Brasil) 💛

QRCode Kotlin Logo

Creating QRCodes in Kotlin (and Java) is harder than it should be. QRCode-Kotlin aims to bring a simple, straightforward and customizable way to create QRCodes, especially in the backend.

It is with this mission in mind that we keep doing our best to learn how developers use this library and their goals so that we can provide a better library/API for them. Please, feel free to share if and how you're using this project ^^

  • Pure Kotlin: Rewritten on pure Kotlin from a reference implementation of the QRCode spec by Kazuhiko Arase
  • Lightweight: No dependencies, ~115KB and it does what it says on the tin.
  • Easy to use: Quickly and easily implement QRCodes with few lines of code.
  • Good-looking: Many developers don't have time and sometimes knowledge to implement the perfect QRCode, so this library tries to generate good-looking QRCodes by default.
  • Server friendly: The JVM version is mainly focused on a personal use-case where I needed to generate QRCodes on the backend, but all libraries I found were either complex or huge, usually both.
  • Multiplatform: This is a KMP library with support to Java, JavaScript, Android, iOS and tvOS.

Table of Contents

1. Installation

The library is available from Maven Central and NPM JS, so you can add it to your project as a dependency like any other:

Gradle:

// Use this for both Android and JVM
implementation("io.github.g0dkar:qrcode-kotlin:4.1.1")

Maven - JVM:

<dependency>
    <groupId>io.github.g0dkar</groupId>
    <artifactId>qrcode-kotlin-jvm</artifactId>
    <version>4.1.1</version>
</dependency>

Maven - Android:

<dependency>
    <groupId>io.github.g0dkar</groupId>
    <artifactId>qrcode-kotlin-android</artifactId>
    <version>4.1.1</version>
</dependency>

NodeJS:

npm install [email protected]

Browser:

<script src="https://cdn.jsdelivr.net/gh/g0dkar/qrcode-kotlin@main/release/qrcode-kotlin.min.js" type="application/javascript"></script>

Usage

To create QRCodes, the main class that should be used is the qrcode.render.QRCode class. It has static methods to help you create a QRCode the way you want:

// Use one of these:

val squares = QRCode.ofSquares()

val circles = QRCode.ofCircles()

val roundedSquares = QRCode.ofRoundedSquares()

With that, you'll have a QRCodeBuilder instance. It has methods to adjust colors, size, spacing, add a logo and more! Also, make sure to check the Colors class as well.

Here's a code to get you started:

val helloWorld = QRCode.ofSquares()
    .withColor(Colors.DEEP_SKY_BLUE) // Default is Colors.BLACK
    .withSize(10) // Default is 25
    .build("Hello world!")

// By default, QRCodes are rendered as PNGs.
val pngBytes = helloWorld.render()

FileOutputStream("hello-world.png").use { it.write(pngBytes) }

We highly recommend that you check out some examples:

The examples show pretty much all that can be done with the library! Even how to extend it so that it can create SVG QRCodes ;)

You can mix and match all those together. Try generating the library logo and banner with gradients and all in SVG ;)

Spring Framework and/or Spring Boot

As said earlier, one of the main reasons I developed this library was to use it on a backend application. So it is only natural to show how to do that :)

This Spring Framework/Boot controller method can generate QRCodes of a given content:

import org.springframework.core.io.ByteArrayResource
import org.springframework.http.HttpHeaders.CONTENT_DISPOSITION
import org.springframework.http.MediaType.IMAGE_PNG_VALUE

@GetMapping("/qrcode")
fun generateQrCode(content: String): ResponseEntity<ByteArrayResource> {
    val pngData = QRCode().ofSquares()
        .build(content)
        .render()
    val resource = ByteArrayResource(pngData, IMAGE_PNG_VALUE)

    return ResponseEntity.ok()
        .header(CONTENT_DISPOSITION, "attachment; filename=\"qrcode.png\"")
        .body(resource)
}

Changes from v3

The main changes coming from v3.3.0 are:

  1. The main package of the classes was changed from io.github.g0dkar.qrcode to simply qrcode
    • The old name doesn't help languages that don't have the "package" concept, and other Kotlin libraries already name their main package this way.
  2. The old QRCode class was rewritten to be easier to create better looking QRCodes . The previous QRCode class was renamed to QRCodeProcessor, with very minor API changes.
    • For most of the simple cases, the new QRCode class is compatible with the old one!
  3. A bunch of optimizations on how the QRCode is drawn. Previously, we'd had a canvas for each square, which would then be copied into the QRCode. This was changed to have just one large canvas where each square will be individually drawn directly.
  4. iOS and tvOS Support: Starting from v4.0.7 an initial implementation of the QRCodeGraphics so that iOS and tvOS are now supported. Any and all feedback are very welcome! - Thanks a lot to ruicanas for all his contributions to this feature :D

License

Copyright since 2021 Rafael M. Lins, Licensed under the MIT License.

QR Code is trademarked by Denso Wave, Inc.

Thanks and Acknowledgements

  • Kazuhiko Arase: For his reference implementation!
  • Paul Varry: for opening the first few issues on the repo and helping to make the library even better for everyone! :grin:
  • Renan Lukas: For his friendship, patience and help with Android, Gradle and a bunch of other stuff during the development of v2.0.0 and v3.0.0!
  • Doomsdayrs: For pointing out how the library could be improved using Kotlin Multiplatform, and helping out implementing it into the project.
  • An awesome, furry friend for all the support through all these years :)
  • ruicanas: For not only pointing out some issues with the iOS implementation, but also fixing them! Thank you so much ^^

Support and Links

If you enjoyed the library and want to get me some coffee, use the buttons below :love_you_gesture: