Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

backgroundcolor with # doesn't work or throw an error #329

Open
jaisal1024 opened this issue Mar 14, 2024 · 1 comment
Open

backgroundcolor with # doesn't work or throw an error #329

jaisal1024 opened this issue Mar 14, 2024 · 1 comment

Comments

@jaisal1024
Copy link

When i call the toBuffer API like so:

  const buffer = await bwipjs.toBuffer({
    bcid: 'code128',
    text: '5555563151499218',
    includetext: true,
    textxalign: 'center',
    backgroundcolor: '#ffffff',

The generated PNG is transparent, not white.

To fix it i have to call the API like so:

  const buffer = await bwipjs.toBuffer({
    bcid: 'code128',
    text: '5555563151499218',
    includetext: true,
    textxalign: 'center',
    backgroundcolor: 'ffffff',

and it adds a white background. The backgroundcolor: '#ffffff', should either throw an error or work as its really confusing to figure out what is going on!

@metafloor
Copy link
Owner

This works for me:

const bwipjs = require('bwip-js');
console.log(bwipjs.BWIPJS_VERSION);   // 4.3.0 (2024-03-12)
(async function() {
    let buf = await bwipjs.toBuffer({
            bcid:'code128',
            text: '5555563151499218',
            includetext: true,
            textxalign: 'center',
            backgroundcolor: '#abcdef',
            padding: 5,
        });

    require('fs').writeFileSync('bg.png', buf);
})();

image

I suspect you are using an out of date version.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants