{"id":22409463,"url":"https://github.com/iodevs/qr_code","last_synced_at":"2025-05-16T05:03:33.271Z","repository":{"id":34960872,"uuid":"159926753","full_name":"iodevs/qr_code","owner":"iodevs","description":"A library for generating QR code. https://hexdocs.pm/qr_code","archived":false,"fork":false,"pushed_at":"2025-02-21T19:53:44.000Z","size":274,"stargazers_count":81,"open_issues_count":6,"forks_count":21,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-05-16T05:02:04.784Z","etag":null,"topics":["elixir","elixir-lang","generator","hacktoberfest","qr","qr-code","qrcode","qrcode-generator"],"latest_commit_sha":null,"homepage":"","language":"Elixir","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"bsd-4-clause","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/iodevs.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.md","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":"2018-12-01T09:00:16.000Z","updated_at":"2025-04-19T11:07:57.000Z","dependencies_parsed_at":"2025-02-28T22:14:50.858Z","dependency_job_id":"ea0adc97-08d3-4074-b2ef-66fca9e30146","html_url":"https://github.com/iodevs/qr_code","commit_stats":{"total_commits":216,"total_committers":5,"mean_commits":43.2,"dds":0.5046296296296297,"last_synced_commit":"3943da0e3fdc147f7304b971e5e947e26270aa04"},"previous_names":[],"tags_count":15,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/iodevs%2Fqr_code","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/iodevs%2Fqr_code/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/iodevs%2Fqr_code/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/iodevs%2Fqr_code/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/iodevs","download_url":"https://codeload.github.com/iodevs/qr_code/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254471061,"owners_count":22076584,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","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":["elixir","elixir-lang","generator","hacktoberfest","qr","qr-code","qrcode","qrcode-generator"],"created_at":"2024-12-05T12:07:48.055Z","updated_at":"2025-05-16T05:03:33.196Z","avatar_url":"https://github.com/iodevs.png","language":"Elixir","readme":"# QRCode\n\n[![Continuous Integration](https://github.com/iodevs/qr_code/workflows/Continuous%20Integration/badge.svg)](https://github.com/iodevs/qr_code/actions)\n[![Coverage Status](https://coveralls.io/repos/github/iodevs/qr_code/badge.svg?branch=master)](https://coveralls.io/github/iodevs/qr_code?branch=master)\n![GitHub top language](https://img.shields.io/github/languages/top/iodevs/qr_code)\n![Hex.pm](https://img.shields.io/hexpm/v/qr_code)\n![Hex.pm](https://img.shields.io/hexpm/dt/qr_code)\n\nThis library is useful for generating QR code to your projects.\n\n![QR code](docs/qrcode.svg)\n\n## Installation\n\n```elixir\ndef deps do\n  [\n    {:qr_code, \"~\u003e 3.2.0\"}\n  ]\nend\n```\n\n## Usage\n\nIf you want to create QR code, just use the function `QRCode.create(your_string, level)`:\n\n```elixir\n  iex\u003e QRCode.create(\"Hello World\")\n  {:ok, %QRCode.QR{...}}\n```\n\nYou can also change the error correction level according to your needs. There are four level of error corrections:\n\n```elixir\n  | Error Correction Level    | Error Correction Capability    |\n  |---------------------------|--------------------------------|\n  | :low (default value)      | recovers 7% of data            |\n  | :medium                   | recovers 15% of data           |\n  | :quartile                 | recovers 25% of data           |\n  | :high                     | recovers 30% of data           |\n```\n\n\u003e Be aware higher levels of error correction require more bytes, so the higher the error correction level,\n\u003e the larger the QR code will have to be.\n\nWe've just generated QR code and now we want to save it to some image file format with high quality. This library supports two image types: `svg` and `png`. So basic using is following:\n\n```elixir\n  iex\u003e \"Hello World\"\n        |\u003e QRCode.create(:high)\n        |\u003e QRCode.render()\n        |\u003e QRCode.save(\"/path/to/hello.svg\")\n  {:ok, \"/path/to/hello.svg\"}\n```\n\nwhere we used an error correction level `:high`. Note the function `QRCode.render()` has default render set up to `:svg` with default `SvgSettings`. Similarly, if you want to export to png just use `QRCode.render(:png)` with/without `PngSettings`. Calling by `QRCode.save` function you save QR code to file `/path/to/file.type`. Also instead of saving QR code to file, you can use a function `QRCode.to_base64()` to encode QR to base 64.\n\nThere are several options to change the appearance of svg or png:\n\n### Svg settings\n\n```elixir\n| Option             | Type                   | Default value | Description                         |\n|--------------------|------------------------|---------------|-------------------------------------|\n| scale              | positive integer       | 10            | changes size of rendered QR code    |\n| background_opacity | nil or 0.0 \u003c= x \u003c= 1.0 | nil           | sets background opacity of svg      |\n| background_color   | string or {r, g, b}    | \"#ffffff\"     | sets background color of svg        |\n| qrcode_color       | string or {r, g, b}    | \"#000000\"     | sets color of QR                    |\n| flatten            | boolean                | false         | renders path data instead of rects  |                                     |\n| image              | {string, size} or nil  | nil           | puts the image to the center of svg |\n| structure          | :minify or :readable   | :minify       | minifies or makes readable svg file |\n```\n\nNotes:\n\n- `:image` inserts image `/path/to/image.type` with `size`, this number must be positive integer.\n  There are a few limitations:\n\n  - The only image formats SVG software must support are JPEG, PNG, and other SVG files, see [MDN](https://developer.mozilla.org/en-US/docs/Web/SVG/Element/image).\n  - Pay attention to the `size` of the embedded image, if you put it too large, it may not be readable by the QR reader.\n\n- By `:structure` you can minify a final size of svg file or make it readable if you need. In the readable case, the file size can be slightly larger and the svg code is structured and thus more clearer.\n\nLet's see an example with embedded image below:\n\n```elixir\n  iex\u003e alias QRCode.Render.SvgSettings\n  iex\u003e image = {\"/docs/elixir.svg\", 100}\n  iex\u003e qr_color = {17, 170, 136}\n  iex\u003e svg_settings = %SvgSettings{qrcode_color: qr_color, image: image, structure: :readable}\n  %QRCode.Render.SvgSettings{\n    background_color: \"#ffffff\",\n    background_opacity: nil,\n    image: {\"/docs/elixir.svg\", 100},\n    qrcode_color: {17, 170, 136},\n    scale: 10,\n    structure: :readable\n  }\n  iex\u003e \"your_string\"\n        |\u003e QRCode.create()\n        |\u003e QRCode.render(:svg, svg_settings)\n        |\u003e QRCode.save(\"/tmp/qr-with-image.svg\")\n  {:ok, \"/tmp/qr-with-image.svg\"}\n```\n\n![QR code color](docs/qrcode_color_with_image.svg)\n\nSimilarly, you can use `png` with/without `PngSettings`.\n\n### Png settings\n\n```elixir\n| Option            | Type                   | Default value | Description                  |\n|--------------------|------------------------|---------------|------------------------------|\n| scale              | positive integer       | 10            | changes size of rendered QR  |\n| background_color   | string or {r, g, b}    | \"#ffffff\"     | sets background color of png |\n| qrcode_color       | string or {r, g, b}    | \"#000000\"     | sets color of QR             |\n```\n\n## Limitations\n\nThe QR code is limited by characters that can contain. In our case this library was developed only for `Byte` and `Alphanumeric` mode. For example, the limits for **40 version** are:\n\n```elixir\n|                   |      Maximum number of characters      |\n| Level             |   low   |  medium  | quartile |  high  |\n|-------------------|---------|----------|----------|--------|\n| Byte mode         |   2953  |   2331   |   1663   |  1273  |\n| Alphanumeric mode |   4296  |   3391   |   2420   |  1852  |\n```\n\nFor other versions and modes see [Character Capacities](https://www.thonky.com/qr-code-tutorial/character-capacities) in documentation.\n\nIf you get an `{:error, \"Input string can't be encoded\"}` it means that you overcame the limit for the given `version` and `level` (i.e. your string is too big).\n\nIf anyone needs the rest of encoding modes,\nplease open new issue or push your code in this repository.\n\n## Notes\n\n- You can also save the QR matrix to csv using by [csvlixir](https://github.com/jimm/csvlixir):\n\n  ```elixir\n  {:ok, qr} = QRCode.create(\"Hello World\")\n  save_csv(qr.matrix, \"qr_matrix.csv\")\n\n  def save_csv(matrix, name_file) do\n    name_file\n    |\u003e File.open([:write], fn file -\u003e\n      matrix\n      |\u003e CSVLixir.write()\n      |\u003e Enum.each(\u0026IO.write(file, \u00261))\n    end)\n  end\n  ```\n\n## References\n\n- [http://www.thonky.com/qr-code-tutorial/](http://www.thonky.com/qr-code-tutorial/)\n\n## License\n\nQRCode source code is licensed under the _BSD-4-Clause._\n\n---\n\nCreated: 2018-11-24Z\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fiodevs%2Fqr_code","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fiodevs%2Fqr_code","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fiodevs%2Fqr_code/lists"}