2010-12-28 16 views
2

私はGD :: Barcodeを使ってバーコードを生成していますが、画像の幅を設定する方法はありませんでした。 どうすればいいですか?GD :: Barcodeを使って画像サイズを設定するには

#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); 

    } 

ありがとう:ここに は、私は私の(Mojoliciousの)アプリケーションでやっているものです。

+0

注:はい、ちょうどタグ が、これはChromeがアンチエイリアス傾向にある主な理由は、私が欲しいWathのない 『ズーム』画像を画像サイズを変更するのは簡単です。 –

+0

解答セクションに解決策を投稿して、未回答リストから解消することができますか?ありがとう! –

+0

完了、Bill the Lizard –

答えて

0

解決済み!

私はちょうど

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); 

} 

これは他の誰かの役に立てば幸い:ここ

とは、新しいソリューションです。

関連する問題