Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 5931075
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T14:38:35+00:00 2026-05-22T14:38:35+00:00

I am using GD::Barcode to generate barcodes of course, but did not find a

  • 0

I am using GD::Barcode to generate barcodes of course, but did not find a way to set the image width.
How do I do that?
Here is what I am doing in my (Mojolicious) application:

  #action that generates an image/png barcode which is embedded in the html
  use GD::Barcode::EAN8;
  use Time::Seconds
  sub barcode {
        my ($c) = @_;
        my $barcode_id = $c->stash('barcode_id');
        $c->app->log->debug('Generating barcode:' . $barcode_id);
        my $img_data = GD::Barcode::EAN8->new($barcode_id)->plot->png;

        $c->res->headers->content_type('image/png');
        $c->res->headers->header(
            'Cache-Control' => 'max-age=' . ONE_MONTH . ', must-revalidate, private');
        $c->render_data($img_data);

  }

Thanks.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-22T14:38:36+00:00Added an answer on May 22, 2026 at 2:38 pm

    Solved!!!

    I just needed to realize that

    GD::Barcode::EAN8->new($barcode_id)->plot;
    

    returns a GD::Image instance.

    Thanks to Sherzod B. Ruzmetov who wrote Image::Resize.

    and here is the new solution:


    use Time::Seconds
    #...
    #generate an image/png barcode which is embedded in the html
    require Image::Resize ;
    GD::Image->trueColor( 0 );#turn it off since Image::Resize turned it on
    require GD::Barcode::EAN8;
    
    sub barcode {
        my ($c) = @_;
        my $barcode_id = $c->stash('barcode_id');
        $c->app->log->debug('Generating barcode:' . $barcode_id);
        my $img = GD::Barcode::EAN8->new($barcode_id)->plot();
        my $img_data = Image::Resize->new($img)->resize(100, 80,1)->png;
        $c->res->headers->content_type('image/png');
        $c->res->headers->header(
            'Cache-Control' => 'max-age=' . ONE_MONTH . ', must-revalidate, private');
        $c->render_data($img_data);
    
    }
    

    Hope this helps someone else.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have zxing libray using that libray I wan to generate barcode of given
I have a piece of code that generates the barcode image (using the Free
I am trying to generate PDF417 barcode images, but I am noticing that the
I need to generate a barcode png/image using Barby , and then show the
i made a barcode generator using code128 but when my barcode generate then it
Im using http://www.ashberg.de/php-barcode/ scripts to generate a barcode. I now need to import the
It was easy to generate a 3 of 9 barcode using Font() Font f
How do we do programmatic reading of a barcode that is captured using a
I'm able to save the captured image from a barcode scanner using this code:
I am using Zxing client for developing BarCode Scanner for android. But I guess

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.