(none) imager-devel
/ help / lists / applications / search /
 

Re: Transparency and Text Rendering

From: Mike Depot (
01267@xyz.molar.is)
Date: Wed 02 May 2001 - 20:15:55 UTC

  • Next message: Arnar Mar Hrafnkelsson: "CVS access..."

    opps, that
    gif_tran_color=>$white,
    wasn't supposed to be there, I was trying it to see if that would help. It
    didn't seem to have any effect.

    > #!/usr/bin/perl -w
    >
    > # tested on Imager version 0.38pre8
    > use strict;
    > use Imager qw(:handy);
    > use POSIX qw(strftime);
    >
    > my ($mday, $mon, $year, $wday) = (localtime)[3,4,5,6];
    > my $datestr = strftime("%A, %d-%b-%Y",0,0,0,$mday,$mon,$year,$wday);
    >
    > my $black = NC(0,0,0);
    > my $orange = NC(255,102,0);
    > my $white = NC(255,255,255);
    >
    > my $fontname = "/usr/share/fonts/times.ttf";
    > my $font=NF(file=>$fontname,size=>30,aa=>1)
    > or die "Couldn't create font: $Imager::ERRSTR\n";
    >
    > my $datestr1 = $datestr.' [';
    > my $datestr2 = 'an orange day';
    > my $datestr3 = ']';
    > $datestr = $datestr1.$datestr2.$datestr3;
    >
    > my @bbox=$font->bounding_box(string=>$datestr);
    > my @bbox1=$font->bounding_box(string=>$datestr1);
    > my @bbox2=$font->bounding_box(string=>$datestr2);
    > my @bbox3=$font->bounding_box(string=>$datestr3);
    >
    > my $xs1=$bbox1[2]-$bbox1[0]+2;
    > my $xs2=$bbox2[2]-$bbox2[0]+2;
    > my $xs3=$bbox3[2]-$bbox3[0]+2;
    > my $xs = $xs1+$xs2+$xs3;
    > my $ys=$bbox[3]-$bbox[1]+4;
    >
    > my $i1=Imager->new(xsize=>$xs,ysize=>$ys,channels=>4);
    > $i1->box(color=>$white,filled=>1);
    > $i1->string(font=>$font,string=>$datestr1,color=>$black,
    > x=>-$bbox[0]+2,y=>$bbox[3]);
    > $i1->string(font=>$font,string=>$datestr2,color=>$orange,
    > x=>-$bbox[0]+2+$xs1,y=>$bbox[3]);
    > $i1->string(font=>$font,string=>$datestr3, color=>$black,
    > x=>-$bbox[0]+2+$xs1+$xs2,y=>$bbox[3]);
    > $i1->write(file=>"date1.gif",gifquant=>'gen', transp=>'threshold',
    > gif_tran_color=>$white,
    > max_colors=>255);
    >
    > my $i2=Imager->new(xsize=>$xs,ysize=>$ys,channels=>4);
    > $i2->string(font=>$font,string=>$datestr1,color=>$black,
    > x=>-$bbox[0]+2,y=>$bbox[3]);
    > $i2->string(font=>$font,string=>$datestr2,color=>$orange,
    > x=>-$bbox[0]+2+$xs1,y=>$bbox[3]);
    > $i2->string(font=>$font,string=>$datestr3, color=>$black,
    > x=>-$bbox[0]+2+$xs1+$xs2,y=>$bbox[3]);
    > $i2->write(file=>"date3.gif",gifquant=>'gen', transp=>'threshold',
    > max_colors=>255);
    > $i2->write(file=>"date2.png");



  •