Add Human Readable for QR Codes png and svg format, and barcode for png.#9
Add Human Readable for QR Codes png and svg format, and barcode for png.#9Christian-Quesada wants to merge 2 commits into
Conversation
There was a problem hiding this comment.
Pull Request Overview
This PR adds functionality to display human-readable text below barcodes and QR codes, addressing a previous limitation where text rendering wasn't possible. The implementation uses SixLabors.ImageSharp.Drawing for PNG rendering and SVG manipulation for vector output.
- Adds new query parameter "ihr" to enable human-readable text display
- Implements text rendering for both PNG (using ImageSharp Drawing) and SVG formats
- Removes "Known Limitations" section about inability to render text below barcodes
Reviewed Changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 4 comments.
| File | Description |
|---|---|
| README.md | Documents new ImageSharp.Drawing dependency, adds "ihr" query parameter documentation, and removes the limitation about missing text rendering |
| BarcodeImageService.cs | Implements human-readable text rendering with two helper methods for PNG and SVG formats, adds query parameter parsing logic |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| h | The height, in pixels, of the rendered barcode. _Default: 40 pixels_. For QR Code, there are certain jump-points between sizes that will cause a change in the outputted image size. Each Matrix code type has symmetrical representation requirements. It will always jump to an even number that is a multiple of the codeword size. | ||
| w | The width, in pixels, of the rendered barcode. _Default: 0, which means 'unset'_ For 1D barcodes (like Code 128), leave unset to let the rendering engine decide. | ||
| m | Margins, in pixels. _Default: 0_. For 1D barcodes, this modifies the left and right margins. Top and bottom are untouched. | ||
| ihr | Set as 'True' if you want to see the human readable bellow the barcode/qr code. _Default:False |
There was a problem hiding this comment.
Corrected spelling of 'bellow' to 'below'.
| h | The height, in pixels, of the rendered barcode. _Default: 40 pixels_. For QR Code, there are certain jump-points between sizes that will cause a change in the outputted image size. Each Matrix code type has symmetrical representation requirements. It will always jump to an even number that is a multiple of the codeword size. | ||
| w | The width, in pixels, of the rendered barcode. _Default: 0, which means 'unset'_ For 1D barcodes (like Code 128), leave unset to let the rendering engine decide. | ||
| m | Margins, in pixels. _Default: 0_. For 1D barcodes, this modifies the left and right margins. Top and bottom are untouched. | ||
| ihr | Set as 'True' if you want to see the human readable bellow the barcode/qr code. _Default:False |
There was a problem hiding this comment.
The documentation line is incomplete. Missing closing underscore and description text after the default value. Should be: _Default: False_. Additionally, there's a space missing after the colon in _Default:False.
| ihr | Set as 'True' if you want to see the human readable bellow the barcode/qr code. _Default:False | |
| ihr | Set as 'True' if you want to see the human readable below the barcode/QR code. _Default: False_. |
| byte[] bytes; | ||
|
|
||
| // zxing.net already add the human readable for barcodes like Code 128. | ||
| if (includeHumanReadable && string.Compare(symbologyStr, BarcodeFormat.QR_CODE.ToString(), false) == 0) |
There was a problem hiding this comment.
The ignoreCase parameter is set to false, which means the comparison is case-sensitive. However, on line 106, the comparison uses true (case-insensitive). This inconsistency could cause the human readable text feature to fail if the symbology string has different casing. Should use true for case-insensitive comparison to match line 106.
| if (includeHumanReadable && string.Compare(symbologyStr, BarcodeFormat.QR_CODE.ToString(), false) == 0) | |
| if (includeHumanReadable && string.Compare(symbologyStr, BarcodeFormat.QR_CODE.ToString(), true) == 0) |
| return new BadRequestObjectResult($"Margin 'm' must be between 0 and {maxMargin}."); | ||
| } | ||
|
|
||
| var includeHumanReadable = req.Query.ContainsKey("ihr") && string.Compare(req.Query["ihr"].ToString(), bool.TrueString, true) == 0; |
There was a problem hiding this comment.
Inefficient use of 'ContainsKey' and indexer.
| var includeHumanReadable = req.Query.ContainsKey("ihr") && string.Compare(req.Query["ihr"].ToString(), bool.TrueString, true) == 0; | |
| var includeHumanReadable = !StringValues.IsNullOrEmpty(req.Query["ihr"]) && string.Compare(req.Query["ihr"].ToString(), bool.TrueString, true) == 0; |
Uh oh!
There was an error while loading. Please reload this page.