Hacktoberfest 2026: the issues maintainers tagged for October, open and beginner-friendly. Browse Hacktoberfest issues

Barcode generator: unpredictable whitespace padding around it depending on requested Width

Open
#570 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
3/5
Estimated time
1-2 days
Newbie friendliness
35/100
Issue type
Bug
Clarity
Mostly clear
Activity status
Stale
Tech stack
csharp
Domain
backend

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:
image

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

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from micjahn/ZXing.Net

All issues in micjahn/ZXing.Net

Similar issues

More C# issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.