Re: dynamic canvas text manipulation



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
.



Relevant Pages

  • Re: Help with old Meade LX3
    ... Is a mirror out of alignment ... > This doesn't sound much like tarnish to me (though it's hard to tell ... The telescope I have been using most recently is ... during the day the images seem decent. ...
    (sci.astro.amateur)
  • Re: Group/ungroup in word 2007 is greyed out
    ... it as a .docx/.doc I was then able to manipluate the images. ... The browser you're using shouldn't directly influence whether or not you can group graphic items in Word 2007. ... what are the steps you're taking after the canvas is in place? ... MS Office System Products MVP ...
    (microsoft.public.word.drawing.graphics)
  • Virtual Images in front of Concave Mirror
    ... Reposted from " 3-D image in a concave bowl mirror " in this NG. ... Magnified erect virtual images are formed behind concave mirrors ...
    (sci.optics)
  • Re: Canvas keeps scrolling down after mouse button released
    ... and creates it with a single canvas. ... >then populates the canvas with any number of images. ... >can scroll up/down. ... AND limit the number of Photo objects which you need. ...
    (comp.lang.perl.tk)
  • RE: Mirror Image and keep text normal
    ... I already tried printing it in mirror but all the text is mirrowed too. ... Dim oshp As Shape ... For Each osld In ActivePresentation.Slides ... There's a lot of images and you want an automatic way to do it quickly. ...
    (microsoft.public.powerpoint)

Loading