当然,我正在使用GD::Barcode来生成条形码,但没有找到设置图像宽度的方法。我该怎么做?下面是我在我的(Mojolicious)应用程序中做的事情:
#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);
}谢谢。
发布于 2011-05-21 01:30:34
解决了!
我只需要意识到
GD::Barcode::EAN8->new($barcode_id)->plot;返回GD::Image实例。
感谢写了Image::Resize的Sherzod B. Ruzmetov。
这是新的解决方案:
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);
}希望这对其他人有帮助。
https://stackoverflow.com/questions/4547517
复制相似问题