Re: dynamic canvas text manipulation
- From: zentara <zentara@xxxxxxxxxxxxxx>
- Date: Tue, 26 Jul 2005 08:55:08 -0400
On Mon, 25 Jul 2005 10:57:00 -0400, Matt Fienberg
<mfienberg@xxxxxxxxxxx> wrote:
>I have an application in Perl Tk that requires mirrored text.
>Ideas???
Well in case you haven't worked out some trick yet, (like a
custom mirrored font),
here is a script to take text, and create 2 png files, 1 regular
and 1 a mirror.
I have a static text in this example, but you could make a sub
to take any text you want.
Now there is ALOT of grunt work to make this work on a canvas
so that it could take any user input as text.
See script at end.
######################################################
Some pointers.
1. Read "perldoc Imager::Font" and look at the section on "bounding
boxes". You can get the size required for whatever text you want to
type in. This can be valuable in setting up the positions on the canvas
for the images.
2. You do not have to create temporary graphics files on disk. Imager
lets you save images to scalars with the "data" option
$img->write( data => \$temp, type => 'jpeg' )
or warn $img->errstr;
will save the image in the scalar $temp
Now Tk can read images from scalars, but you must first base64encode
$temp, then it can be read into a Photo object and placed directly on
the canvas.
#######################################################
So it would take some time to work it out, but you can do it with Imager
in conjunction with Canvas or Zinc.
I would go with Zinc myself, because you can then rotate (and translate)
the entire "mirror_group" with a few simple lines of code.
#!/usr/bin/perl
use warnings;
use strict;
use Imager;
my $img = Imager->new(xsize=>400,ysize=>50,channels=>4);
my $blue = Imager::Color->new("#0000FF");
my $font = Imager::Font->new(
file => 'Generic.ttf',
color => $blue,
size => 30);
$img->string(font => $font,
text => "Model-XYZ",
x => 15,
y => 40,
size => 40,
color => $blue,
aa => 1);
$img->write(file=>$0.'.png', type=>'png')
or die "Cannot write: ",$img->errstr;
my $img_mirror = $img->copy();
$img_mirror->flip( dir => "h" );
$img_mirror->write(file=>$0.'-mirror.png', type=>'png')
or die "Cannot write: ",$img_mirror->errstr;
__END__
--
I'm not really a human, but I play one on earth.
http://zentara.net/japh.html
.
- Follow-Ups:
- Re: dynamic canvas text manipulation
- From: zentara
- Re: dynamic canvas text manipulation
- References:
- dynamic canvas text manipulation
- From: Matt Fienberg
- dynamic canvas text manipulation
- Prev by Date: Re: dynamic canvas text manipulation
- Next by Date: Re: dynamic canvas text manipulation
- Previous by thread: Re: dynamic canvas text manipulation
- Next by thread: Re: dynamic canvas text manipulation
- Index(es):
Relevant Pages
|
Loading