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

Barcode Generated looks weird JPG,PNG #204

Open
Dxsoo96 opened this issue Aug 6, 2024 · 9 comments
Open

Barcode Generated looks weird JPG,PNG #204

Dxsoo96 opened this issue Aug 6, 2024 · 9 comments

Comments

@Dxsoo96
Copy link

Dxsoo96 commented Aug 6, 2024

Hey guys, does anyone ever meet this problem?
the barcode generated looks weird
barcode (2)
this is the code to generate it
$generator = new \Picqer\Barcode\BarcodeGeneratorJPG();
file_put_contents('media/barcode.jpg', $generator->getBarcode($invoice->getIncrementId(), $generator::TYPE_CODE_39, 1, 50, [0, 0, 0]));

It works normal on local but works weird on cloud env.
Please assist

@edvardsr
Copy link

I encountered this issue as well. Just keeping the width factor >=2 works.

@casperbakker
Copy link
Member

What is the value that you put into the barcode? In the example, what is coming out of $invoice->getIncrementId()?

@edvardsr
Copy link

@casperbakker A string of random numbers like "0123456789" should technically work for reproducing this issue. The issue really was that the thinner lines did not render for some reason, only the thicker ones, although on my local environment I have been unable to reproduce that. And as mentioned previously, just using a width factor that is >= 2 worked for me.

The issue was on Magento Cloud in my case.

@casperbakker
Copy link
Member

Weird. I think it can only be something in the way GD or Imagick was build on that machine. Maybe the quality of the JPG rendering was overruled to be lower quality?

This is on my machine. On the top rendered with 1 as width, the bottom one with 2.

Screenshot 2024-09-21 at 09 43 07

If the JPG gives you problems, you can try to use the PNG renderer. As PNG has no way to compress the image and loose small lines to make the file smaller.

@edvardsr
Copy link

edvardsr commented Sep 21, 2024

Surprisingly, this happened both with png and jpg renderers during my testing.

AFAIK it was with the gd renderer there, didn’t test adding imagick. Are there any tests that could help here?

@casperbakker
Copy link
Member

@edvardsr Could you dump the data from the $barcodeData in https://github.com/picqer/php-barcode-generator/blob/v2.4.2/src/BarcodeGeneratorPNG.php#L57 and post it here? var_dump($barcodeData);die(); on line 58 for example. Then I can check if there is something wrong with the barcode data being fed into the renderer.

I also just released version 3 of this library with some optimisations. You could also try to use that and see if the results are different.

@edvardsr
Copy link

I’ll give the new version a try later today, will report back with findings roughly before this time tomorrow.

@edvardsr
Copy link

Hi @casperbakker,

This is what is happening with the new version (3.1.0) on the cloud environment.

image

This is the code I used:

        <div>
            <p>Barcode test</p>
            <p>
                <?php
                    $barcode = (new \Picqer\Barcode\Types\TypeCode39())->getBarcode('0123456789');
                    $renderer = new \Picqer\Barcode\Renderers\PngRenderer();
                    echo '<img src="data:image/png;base64,' . base64_encode($renderer->render($barcode, 1, 50)) . '">';
                    echo '<br>';
                    echo '<img style="margin-top: 10px;" src="data:image/png;base64,' . base64_encode($renderer->render($barcode)) . '">';
                    echo '<br>';
                    echo '<img style="margin-top: 10px;" src="data:image/png;base64,' . base64_encode($renderer->render($barcode, 2, 100)) . '">';
                    echo '<br>';
                    echo '<img style="margin-top: 10px;" src="data:image/png;base64,' . base64_encode($renderer->render($barcode, 3, 150)) . '">';
                ?>
            </p>
        </div>

To compare, this is what I have on my local setup:
image

Here is a var_dump of the $barcode variable on the cloud environment. For the record, it seems almost identical to the one on my local setup except for the # numbers, so the issue has to be somewhere else probably.

https://gist.github.com/edvardsr/eb8a5a1b2745db66eb785f4822d0e9e1

@edvardsr
Copy link

edvardsr commented Sep 26, 2024

The GD version on the cloud instance is "bundled (2.1.0 compatible)", so potentially it might be possible to reproduce the issue with this version of GD. Imagick isn't installed, and the PHP version is 8.3.7.

The version of GD on my local setup is 2.3.3, and the version of imagick is 3.7.0. I have been unable to reproduce the issue with those versions.

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

No branches or pull requests

3 participants