Barcode generator: unpredictable whitespace padding around it depending on requested Width
Nobody has claimed this yet.
Assessment
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Newbie friendliness
- 35/100
Research direction
Start with the ZXing.ImageSharp.BarcodeWriter call in the example, using CODE_39, Width = 400, Height = 400 and Margin = 0, and compare its output with the Width = 1 workaround. Find where the requested width is mapped onto the encoder's minimum module width, which the payload does not show, and make the extra space predictable. Done when a non-multiple width gives output whose bars fill the requested width with no unexplained horizontal padding.
Written by the indexing model from the issue text.
Description
If you ask the barcode writer for an arbitrary width that isn't a multiple of the "default minimum" barcode width for that specific code, then you end up with unpredictable horizontal padding around the barcode.
an example:
public FileContentResult GithubExample()
{
var code = "123456789";
var barcodeWriter = new ZXing.ImageSharp.BarcodeWriter<Rgba32>
{
Format = BarcodeFormat.CODE_39,
Options = new EncodingOptions
{
Height = 400,
Width = 400,
Margin = 0
}
};
using var image = barcodeWriter.Write(code);;
using var stream = new MemoryStream();
var imageEncoder = new PngEncoder();
var mime = "image/png";
image.Save(stream, imageEncoder);
var bytes = stream.ToArray();
return File(bytes, mime);
}
result:
The workaround we currently have is to generate with Width = 1, then resize using ImageSharp after the fact. But it seems like something that ought to be handled by the generator anyway.
- Dominant language
- C#
- Stars
- 3.1k
- Forks
- 704
- Avg merge
- 13d 17h
- Merged PRs (30d)
- 2
Getting set up
This project ships no dev container, Dockerfile or contributing guide, so setting up is up to you: start from its README, and see our first-contribution guide for the general steps.
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from micjahn/ZXing.Net
-
crop() overrides document "0 <= top <= Height"; should be top < Height like left < WidthPossibly taken @hidingmyname claimed this today. Open
Difficulty 1/5 Under an hour Newbie friendliness 92/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 62/100
-
Difficulty 3/5 Half a day Newbie friendliness 22/100
-
Difficulty 3/5 1-2 days Newbie friendliness 42/100
-
Difficulty 4/5 3-5 days Newbie friendliness 12/100
All issues in micjahn/ZXing.Net
Similar issues
-
bug effort:S P3
Difficulty 2/5 1-3 hours Newbie friendliness 85/100
nightscout/nocturne#3093 ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 67/100
Maintainers usually reply within 3 days
-
Difficulty 1/5 Under an hour Newbie friendliness 85/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 76/100