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

translucent fonts (fwd)

From:
08271@xyz.molar.is
Date: Wed 23 Apr 2003 - 21:10:12 GMT


Sorry if this is a dupe post, I was sending from the wrong address
before...

----

This hardly seems optimal, but it's the best I've been able to come up with so far for doing translucent fonts. It's fine when I'm only doing it 4 or 5 times, but I'm running batch jobs that often have upwards of 300 labels (after optimizing the labeling).

In my actual solution, I use the 'img_set' method to create an image the size required for the text I'm making translucent. (See 'sub text' http://orange.uc.org/cvsweb/cvsweb.cgi/treemaps/perl/Treemap/Treemap/Output/Imager.pm?rev=1.22&content-type=text/x-cvsweb-markup)

Any suggestions on how to make it faster?

#!/usr/bin/perl -w use Imager qw(:handy);

$fname= $ARGV[0] || "../ImUgly.ttf";

$i=Imager->new(xsize=>200,ysize=>200,channels=>4); # create image with alpha channel $d=Imager->new(xsize=>200,ysize=>200,channels=>3); # destination image

$font=Imager::Font->new(file=>$fname); $colour=Imager::Color->new( 0,0,0,80 ); $i->string(x=>10,y=>150, size=>115,font=>$font,text=>"Img", color=>$colour, aa=>1 ); # write text with an alphaness of 80 (out of 255)

# Draw some stuff to write text overtop of $d->flood_fill(x=>0,y=>0,color=>NC("#FFFFFF")); $d->box(xmin=>50, ymin=>50, xmax=>150, ymax=>150, color=>NC("#FF0000"));

$d->rubthrough(src=>$i); # rub two copies onto the destinastion image to see $d->rubthrough(src=>$i, tx=>10, ty=>10); # the different opacities. $d->write(file=>"test.png");

re, Simon