{"id":37019591,"url":"https://github.com/aytchell/qrgen","last_synced_at":"2026-01-14T02:10:56.880Z","repository":{"id":144589262,"uuid":"490765536","full_name":"aytchell/qrgen","owner":"aytchell","description":"A small java lib to generate QR codes","archived":false,"fork":false,"pushed_at":"2025-04-09T14:58:12.000Z","size":351,"stargazers_count":15,"open_issues_count":0,"forks_count":4,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-07-18T13:31:17.786Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Java","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/aytchell.png","metadata":{"files":{"readme":"README.md","changelog":"Changelog.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2022-05-10T15:52:59.000Z","updated_at":"2025-06-15T19:57:48.000Z","dependencies_parsed_at":null,"dependency_job_id":"ca1730bb-bc68-44c0-92f6-be8b28a14d52","html_url":"https://github.com/aytchell/qrgen","commit_stats":null,"previous_names":[],"tags_count":7,"template":false,"template_full_name":null,"purl":"pkg:github/aytchell/qrgen","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/aytchell%2Fqrgen","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/aytchell%2Fqrgen/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/aytchell%2Fqrgen/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/aytchell%2Fqrgen/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/aytchell","download_url":"https://codeload.github.com/aytchell/qrgen/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/aytchell%2Fqrgen/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28408711,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-14T01:52:23.358Z","status":"online","status_checked_at":"2026-01-14T02:00:06.678Z","response_time":107,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2026-01-14T02:10:56.305Z","updated_at":"2026-01-14T02:10:56.870Z","avatar_url":"https://github.com/aytchell.png","language":"Java","funding_links":[],"categories":[],"sub_categories":[],"readme":"# QR code generator\n\nThis library provides a class which is capable of generating QR codes. It is \na layer on top of the [ZXing](https://github.com/zxing/zxing) generator\nwhich does the heavily lifting of actually computing the dot matrix. This\nlib then adds the functionality to make image files.\n\nThis lib is inspired by [QRGen](http://kenglxn.github.io/QRGen/).\nBut since I'd like to have some structural changes plus more variations when\nrendering the QR code, I wrote this new lib instead. The main\ndifferences to QRGen are:\n  - you can configure a QrGenerator and then generate multiple QR codes from\n    it instead of repeating the configuration for each QR code\n  - this lib can overlay a logo over the QR code\n  - the 'pixels' of the code can be drawn with different styles\n  - you can select from a set of different styles for the three markers (the\n    big rectangles in the corners)\n  - no leaking of ZXing provided types\n  - no support for Android thus only one lib (instead of \"core + javase + android\")\n\n## Table of contents\n\n* [Introduction](#introduction)\n* [Maven](#maven)\n* [Configuration](#configuration)\n    * [Output file type](#conf_filetype)\n    * [Size and margin of the code](#conf_size)\n    * [Used colors](#conf_colors)\n    * [Error correction level](#conf_error)\n    * [Logo overlay](#conf_logo)\n    * [Styling](#conf_styling)\n      * [... the pixels](#conf_styling_pixels)\n      * [... the markers](#conf_styling_markers)\n    * [Character set of the encoded message](#conf_charset)\n* [Actually writing the QR code](#write)\n* [License](#license)\n\n\u003ca name=\"introduction\"\u003e\u003c/a\u003e\n## Introduction\n\nWhen starting with class `QrGenerator` usage of this lib is quite\nself-explanatory (there's also javadoc available):\n\n```java\n    final QrGenerator generator = new QrGenerator()\n            .withSize(300, 300)\n            .withMargin(3)\n            .as(ImageType.PNG)\n            .withErrorCorrection(ErrorCorrectionLevel.Q);\n\n    final Path img = generator\n            .writeToTmpFile(\"Hello, World!\");\n```\n\nThis library has a `modules-info.java` so it can be used as a Java 9 (Jigsaw)\nmodule.\n\n\u003ca name=\"maven\"\u003e\u003c/a\u003e\n## Maven\n\n```xml\n    \u003cdependency\u003e\n        \u003cgroupId\u003ecom.github.aytchell\u003c/groupId\u003e\n        \u003cartifactId\u003eqrgen\u003c/artifactId\u003e\n        \u003cversion\u003e3.0.0\u003c/version\u003e\n    \u003c/dependency\u003e\n```\n\n## Gradle\n\nGroovy syntax:\n```groovy\n    implementation 'com.github.aytchell:qrgen:3.0.0'\n```\n\nKotlin syntax\n```kotlin\n    implementation(\"com.github.aytchell:qrgen:3.0.0\")\n```\n\n\u003ca name=\"configuration\"\u003e\u003c/a\u003e\n## Configuration\n\nThis section lists the possible configurations for the created QR codes. The\nmethod calls to configure the generator can be chained and the resulting\nconfiguration is collected by the instance. So to make things easier all\nexamples build on the same instance of `QrGenerator`.\n\n```java\n    final QrGenerator generator = new QrGenerator();\n```\n\n\u003ca name=\"conf_filetype\"\u003e\u003c/a\u003e\n### Output file type\n\nThe file format of the resulting QR code image can be selected to be\n`png`, `gif`, `bmp` or `jpeg`:\n\n```java\n    generator.as(ImageType.PNG);\n```\n\n\u003ca name=\"conf_size\"\u003e\u003c/a\u003e\n### Size and margin of the code\n\nThe size of the resulting image (in pixels) can be configured as well\nas a \"quiet zone\" around the code. This margin is an aid for QR code\nscanners to easier distinguished the code from the surrounding environment.\n\nThe unit of the parameter for the margin's size is \"number of dots used in\nthe QR code\" so the actual size of the margin in pixels depends on the size\nof the complete image as well as on the complexity of the QR code.\n\n```java\n    generator\n            .withSize(300, 300)\n            .withMargin(3);\n```\n\n\u003ca name=\"conf_colors\"\u003e\u003c/a\u003e\n### Used colors\n\nUsually QR codes are displayed in black and white as this gives the best\ncontrast and thus help a scanner in reading it. But there might be times,\nwhen you want to have different colors.\n\nThe trivial variant is to set no colors at all. Then the lib will fall back to\nthe usual black/white pattern. The next level is to choose a color for\n'the background' and another color for 'the pixels':\n\n```java\n    final RgbValue daffodil = new RgbValue(0xff, 0xff, 0x31);\n    final RgbValue oxfordBlue = new RgbValue(0x00, 0x21, 0x47);\n\n    generator.withColors(daffodil, oxfordBlue);\n```\n\nFinally, it is possible to use up to four different colors:\n\u003ctable style=\"border: none; border-collapse: collapse\"\u003e\n\u003ctr style=\"border: none\"\u003e\n\u003ctd style=\"border: none; vertical-align: top; padding: 0\"\u003e\n\u003cul\u003e\n\u003cli\u003ethe background color (which is usually white)\u003c/li\u003e\n\u003cli\u003ethe \"active parts\" of the code (which form 'the pixels' in the mid of the code)\u003c/li\u003e\n\u003cli\u003ethe outer part of the three markers and\u003c/li\u003e\n\u003cli\u003ethe inner part of the three markers\u003c/li\u003e\n\u003c/ul\u003e\n\u003c/td\u003e\n\u003ctd style=\"border: none; vertical-align: center\"\u003e\n\u003cimg src=\"examples/colors.png\" alt=\"QR code with four colors\"/\u003e\n\u003c/td\u003e\u003c/tr\u003e\n\u003c/table\u003e\n\nHowever, you should choose such colors which provide a sufficient contrast.\nOtherwise, it might get difficult for QR code scanners to read the code.\n  \n```java\n    final RgbValue white = new RgbValue(0xffffff);\n    final RgbValue alloyOrange = new RgbValue(196, 98, 16);\n    final RgbValue alabamaCrimson = new RgbValue(0xaf, 0x00, 0x2a);\n    final RgbValue black = new RgbValue(0x0);\n\n    generator.withColors(\n            black,              // 'pixel' color\n            white,              // background color\n            alloyOrange,        // outer marker color\n            alabamaCrimson);    // inner marker color\n```\n\nThere's also a version with three parameters where the third color is used\nfor the complete markers' structure.\n\nAs the examples show, an RGB color value can be constructed with the three\nparts separated as well as with one single raw integer value. Along with\nthe `RgbValue` there are some more possible color representations:\n  - `ArgbValue` \u0026mdash; an RGB value with a leading alpha channel\n  - `RgbaValue` \u0026mdash; same with the alpha channel given at the end\n  - `HslValue` \u0026mdash; a color given via hue, saturation and lightness\n  - `HslaValue` \u0026mdash; an HSL color value with an extra alpha channel\n\n(Note that only `PNG` and `GIF` output image formats support alpha values.)\n\n\u003ca name=\"conf_error\"\u003e\u003c/a\u003e\n### Error correction level\n\nIf you plan to put a logo onto your generated QR code or you're printing it\nand the code gets dirty or damaged then information is lost and scanners\nmight not be able to correctly scan the code.\n\nTo circumvent this kind of problem the information encoded into the QR code\ncan be stored with different degrees of redundancy. The higher the level of\nredundancy the better a scanner will be able to read a damaged or covered QR\ncode but this also means that the QR code becomes more dense (\"more pixels\").\n\nIn the end there is no simple algorithm which level to take but it depends on\nthe scenario how you want to use the QR code.\n\nThe specified levels are\n  - L - error correction rate of approximately 7%\n  - M - error correction rate of approximately 15%\n  - Q - error correction rate of approximately 25%\n  - H - error correction rate of approximately 30%\n\n```java\n        generator.withErrorCorrection(ErrorCorrectionLevel.Q)\n```\n\n\u003ca name=\"conf_logo\"\u003e\u003c/a\u003e\n### Logo overlay\n\nThe generator is able to overlay the QR code with a centered logo. The file\nformat of the logo can be any of `gif`, `png`, `bmp` or `jpeg`. Alpha channel\nis respected if the file format supports it.\n\nNote however that the lib does not scale the logo to \"fit\" (whatever that\nmeans); the logo will cover information from the QR code and increasing the\nerror correction level should be considered.\n\nIt's up to the caller to ensure that the QR code can be read with the\nlogo above it.\n\n```java\n        try (final InputStream logo =\n                QrCodeExample.class.getResourceAsStream(\"github_logo.png\")) {\n            // in real code check for null ...\n            generator.withLogo(logo);\n        }\n\n        final Path img = generator\n                .writeToTmpFile(\"Hello, Github!\");\n```\n\n![QR code with github logo](examples/github_logo.png \"github logo overlay\")\n![QR code with mvn central logo](examples/mvn_logo.png \"mvn central logo overlay\")\n\n\u003ca name=\"conf_styling\"\u003e\u003c/a\u003e\n### Styling\n\nIt is possible to change the appearance of 'the pixels' used to render the QR\ncode as well as the appearance of the three markers. Most QR code scanners\nshould be able to handle these shapes but keep in mind that you're diverging\nfrom 'specified appearance'.\n\n\u003ca name=\"conf_styling_pixels\"\u003e\u003c/a\u003e\n#### ... the pixels\n\nIt is possible to change the style of the individual pixels used to render\nthe QR code. Currently, there are eight different styles available:\n\n  - `RECTANGLES` \u0026mdash; The \"standard\" styling with rectangular pixels \"touching\" each other\n  - `SMALL_RECTANGLES` \u0026mdash; A styling with smaller pixels so that a white grid between them appears\n  - `DOTS` \u0026mdash; Dots instead of rectangles\n  - `ROUND_CORNERS` \u0026mdash; rectangular pixels but with rounded corners\n  - `ROWS` \u0026mdash; a style that makes the pixels appear like rows with Morse-code-like lines\n  - `COLUMNS` \u0026mdash; a similar style but with columns instead of rows\n  - `SNAKES` \u0026mdash; connected pixels with 'snakes-like' heads when there's no neighbor\n  - `WATER` \u0026mdash; connected pixels which behave like adhesion of water surfaces\n\n```java\n        final Path img = generator\n                .withPixelStyle(PixelStyle.DOTS)\n                .writeToTmpFile(\"Hello, Github!\");\n```\n\n\u003ctable\u003e\n\u003ctr\u003e\n\u003ctd\u003e\u003ccode\u003eRECTANGLES\u003c/code\u003e\u003c/td\u003e\n\u003ctd\u003e\u003ccode\u003eSMALL_RECTANGLES\u003c/code\u003e\u003c/td\u003e\n\u003ctd\u003e\u003ccode\u003eDOTS\u003c/code\u003e\u003c/td\u003e\n\u003ctd\u003e\u003ccode\u003eROUND_CORNERS\u003c/code\u003e\u003c/td\u003e\n\u003c/tr\u003e\u003ctr\u003e\n\u003ctd\u003e\n\u003cimg alt=\"QR code with RECTANGLES styled pixels\" src=\"examples/pix_rectangles.png\"/\u003e\n\u003c/td\u003e\u003ctd\u003e\n\u003cimg alt=\"QR code with SMALL_RECTANGLES styled pixels\" src=\"examples/pix_small_rectangles.png\"/\u003e\n\u003c/td\u003e\u003ctd\u003e\n\u003cimg alt=\"QR code with DOTS styled pixels\" src=\"examples/pix_dots.png\"/\u003e\n\u003c/td\u003e\u003ctd\u003e\n\u003cimg alt=\"QR code with ROUND_CORNERS styled pixels\" src=\"examples/pix_round.png\"/\u003e\n\u003c/td\u003e\u003c/tr\u003e\u003c/table\u003e\n\n\u003ctable\u003e\n\u003ctr\u003e\n\u003ctd\u003e\u003ccode\u003eROWS\u003c/code\u003e\u003c/td\u003e\n\u003ctd\u003e\u003ccode\u003eCOLUMNS\u003c/code\u003e\u003c/td\u003e\n\u003ctd\u003e\u003ccode\u003eSNAKES\u003c/code\u003e\u003c/td\u003e\n\u003ctd\u003e\u003ccode\u003eWATER\u003c/code\u003e\u003c/td\u003e\n\u003c/tr\u003e\u003ctr\u003e\n\u003ctd\u003e\n\u003cimg alt=\"QR code with ROWS styled pixels\" src=\"examples/pix_rows.png\"/\u003e\n\u003c/td\u003e\u003ctd\u003e\n\u003cimg alt=\"QR code with COLUMNS styled pixels\" src=\"examples/pix_columns.png\"/\u003e\n\u003c/td\u003e\u003ctd\u003e\n\u003cimg alt=\"QR code with SNAKES styled pixels\" src=\"examples/pix_snakes.png\"/\u003e\n\u003c/td\u003e\u003ctd\u003e\n\u003cimg alt=\"QR code with WATER styled pixels\" src=\"examples/pix_water.png\"/\u003e\n\u003c/td\u003e\u003c/tr\u003e\u003c/table\u003e\n\n\u003ca name=\"conf_styling_markers\"\u003e\u003c/a\u003e\n#### ... the markers\n\nIt's also possible to change the styling of the three big markers.\nCurrently, there are nine different styles to chose from:\n\n  - `RECTANGLES` \u0026mdash; the 'normal' rectangular markers\n  - `ROUND_CORNERS` \u0026mdash; like `RECTANGLES` but with rounded corners\n  - `CIRCLES` \u0026mdash; circles instead of rectangles\n  - `DROP_IN` \u0026mdash; raindrops appearing to fall toward the inside of the code\n  - `DROP_OUT` \u0026mdash; raindrops appearing to fall toward the outside of the code\n  - `ROUND_IN` \u0026mdash; rectangular marker with the inner edge being rounded\n  - `ROUND_OUT` \u0026mdash; rectangular marker with the outer edge being rounded\n  - `EDGE_IN` \u0026mdash; like `ROUND_CORNERS` but the inner edge is a sharp one\n  - `EDGE_OUT` \u0026mdash; as above but the outer edge is sharp\n\n\u003ctable\u003e\n\u003ctr\u003e\n\u003ctd\u003e\u003ccode\u003eRECTANGLES\u003c/code\u003e\u003c/td\u003e\n\u003ctd\u003e\u003ccode\u003eROUND_CORNERS\u003c/code\u003e\u003c/td\u003e\n\u003ctd\u003e\u003ccode\u003eCIRCLES\u003c/code\u003e\u003c/td\u003e\n\u003ctd\u003e\u003ccode\u003eDROP_IN\u003c/code\u003e\u003c/td\u003e\n\u003ctd\u003e\u003ccode\u003eDROP_OUT\u003c/code\u003e\u003c/td\u003e\n\u003c/tr\u003e\u003ctr\u003e\n\u003ctd\u003e\n\u003cimg alt=\"QR code with RECTANGLES styled markers\" src=\"examples/mark_rectangles.png\"/\u003e\n\u003c/td\u003e\u003ctd\u003e\n\u003cimg alt=\"QR code with ROUND_CORNERS styled markers\" src=\"examples/mark_round.png\"/\u003e\n\u003c/td\u003e\u003ctd\u003e\n\u003cimg alt=\"QR code with CIRCLES styled markers\" src=\"examples/mark_circles.png\"/\u003e\n\u003c/td\u003e\u003ctd\u003e\n\u003cimg alt=\"QR code with DROP_IN styled markers\" src=\"examples/mark_drop_in.png\"/\u003e\n\u003c/td\u003e\u003ctd\u003e\n\u003cimg alt=\"QR code with DROP_OUT styled markers\" src=\"examples/mark_drop_out.png\"/\u003e\n\u003c/td\u003e\u003c/tr\u003e\u003c/table\u003e\n\n\u003ctable\u003e\n\u003ctr\u003e\n\u003ctd\u003e\u003ccode\u003eROUND_IN\u003c/code\u003e\u003c/td\u003e\n\u003ctd\u003e\u003ccode\u003eROUND_OUT\u003c/code\u003e\u003c/td\u003e\n\u003ctd\u003e\u003ccode\u003eEDGE_IN\u003c/code\u003e\u003c/td\u003e\n\u003ctd\u003e\u003ccode\u003eEDGE_OUT\u003c/code\u003e\u003c/td\u003e\n\u003c/tr\u003e\u003ctr\u003e\n\u003ctd\u003e\n\u003cimg alt=\"QR code with ROUND_IN styled markers\" src=\"examples/mark_round_in.png\"/\u003e\n\u003c/td\u003e\u003ctd\u003e\n\u003cimg alt=\"QR code with ROUND_OUT styled markers\" src=\"examples/mark_round_out.png\"/\u003e\n\u003c/td\u003e\u003ctd\u003e\n\u003cimg alt=\"QR code with EDGE_IN styled markers\" src=\"examples/mark_edge_in.png\"/\u003e\n\u003c/td\u003e\u003ctd\u003e\n\u003cimg alt=\"QR code with EDGE_OUT styled markers\" src=\"examples/mark_edge_out.png\"/\u003e\n\u003c/td\u003e\u003c/tr\u003e\u003c/table\u003e\n\n\u003ca name=\"conf_charset\"\u003e\u003c/a\u003e\n### Character set of the encoded message\n\nA QR code encode strings and to be more precise: a series of bytes. And at\nthis point we're entering the wide area of character encodings. You can\nconfigure the character encoding which should be used when converting the\ngiven payload to bytes.\n\nIn most cases UTF-8 (which is the default when not setting any character set)\nwill be perfectly OK.\n\n```java\n        generator.withCharset(StandardCharsets.UTF_8);\n```\n\n\u003ca name=\"write\"\u003e\u003c/a\u003e\n## Actually writing the QR code\n\nOnce you've configured the QR code generator you can use it to write QR\ncodes. The method to write a payload to a QR code image file does not change\nthe state of the generator instance. So you can reuse the same generator\ninstance to write as many QR Code as you like (with different payloads).\n\n```java\n        final Path img_1 = generator\n                .writeToTmpFile(\"Hello, World!\");\n\n        final Path img_2 = generator\n                .writeToTmpFile(\"Hello again\");\n\n        final Path img_3 = generator\n                .writeToTmpFile(\"Anybody out there?\");\n```\n\nNote that the returned file will be created in the system's tmp folder with\nthe \"delete on exit\" flag set. The method does not change access permissions\nof the created file so most probably (depending on the JRE and the OS) it will\nbe readable to anyone with access to the system.\n\n\u003ca name=\"license\"\u003e\u003c/a\u003e\n## License\n\nApache 2.0 License\n\nCreated and maintained by [Hannes Lerchl](mailto:hannes.lerchl@googlemail.com)\n\nFeel free to send in pull requests. Please also add unit tests and adapt the\nREADME if appropriate.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Faytchell%2Fqrgen","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Faytchell%2Fqrgen","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Faytchell%2Fqrgen/lists"}