Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
Hi, here is a start for you, I modified a little scribble program I had, ztk-mapper, to accept an image, so you can freehand draw on the image with a left-mouse-drag, and a right click allows you to insert text. You can use it with ImageMagick, GD, or Imager to size, scale, cropt, etc. I prefer Imager myself.
#!/usr/bin/perl use warnings; use strict; use Tk; require Tk::DialogBox; use Tk::PNG; #by zentara on Sept 30, 2005 # Usage: # Press and drag Mouse Button 1 to draw lines # Right click to add text at click point # Middle Click(or both mouse buttons ) to delete item under mouse # Save will write the canvas to postscript my $file = shift or die "Need image $!\n"; my @s; #line drawing buffer my $count_l = 0; #count for lines tags my $count_t = 0; #count for text tags my $mw = tkinit; $mw->fontCreate('big', -family=>'arial', -weight=>'bold', -size=> 18 ); my $topframe = $mw->Frame(-bg=>'black')->pack(-fill =>'x'); $topframe->Button(-text=>'Exit',-command=>sub{ exit }) ->pack(-side => 'right', -padx => 5); my $canvas = $mw->Canvas( -width => 640, -height => 480, -bg => 'white', )->pack(-fill=>'both', -expand => 1); $canvas->Tk::bind('<1>', [ \&Start, Ev('x'), Ev('y') ] ); $canvas->Tk::bind("<B1-Motion>", [ \&Move, Ev('x'), Ev('y') ]); $canvas->Tk::bind('<ButtonRelease>', sub { @s =() }); #text insert with right button click $canvas->Tk::bind('<3>', [ \&Text_insert, Ev('x'), Ev('y') ] ); #undo with a middle mouse click $canvas->Tk::bind('<2>', sub{ $canvas->delete( ($canvas->gettags("current"))[0] ); }); my $image = $mw->Photo(-file => $file); my $png = $canvas->createImage(0,0, -anchor => 'nw', -image=> $image, ); $topframe->Button( -text => "Save", -command => [sub { $canvas->update; my @capture=(); my ($x0,$y0,$x1,$y1)=$canvas->bbox('all'); @capture=('-x'=>$x0,'-y'=>$y0,-height=>$y1-$y0,-width=>$x1- +$x0); $canvas -> postscript(-colormode=>'color', -file=>$0.'.ps', -rotate=>0, -width=>800, -height=>500, @capture); } ])->pack(-side=>'left', -padx =>5); $topframe->Button( -text => "Restart", -command => sub{ $canvas->delete('line','text'); })->pack(-side=>'left', -padx =>5); MainLoop; ############################################################# sub Start { my ($canv, $x, $y) = @_; $count_l++; @s =(); my @coords = ($canv->canvasx($x) , $canv->canvasx($y) ); push @s, @coords; } ############################################################# sub Move { my ($canv, $x, $y) = @_; my @coords = ($canv->canvasx($x) , $canv->canvasx($y) ); push @s, @coords; $canvas->createLine( @s, -width => 5, -smooth => 1, -tags => [ 'l'.$count_l , 'line'], -fill => 'black'); #shift off previous points to avoid overlapping shift @s; shift @s; } ############################################################## sub Text_insert { my ($canv, $x, $y) = @_; $count_t++; my @coords = ($canv->canvasx($x) , $canv->canvasx($y) ); my $dialog = $mw->DialogBox( -buttons => ['Ok'], -title => 'Text Insert', -bg => 'lightsteelblue', ); my $dentry = $dialog->add('Entry', -bg=>'yellow', -font => 'big', )->pack(); $dialog->configure(-focus => $dentry); my $button = $dialog->Show(); if ( $button eq "Ok" ) { my $text = $dialog->Subwidget('entry')->get(); $canvas->createText( @coords, -text => $text, -anchor => 'w', -justify => 'left', -font => 'big', -tags => [ 't'.$count_t, 'text' ], -fill => 'red'); } } ################################################################ __END__

I'm not really a human, but I play one on earth. Cogito ergo sum a bum

In reply to Re: Suggestion - Image processing.. by zentara
in thread Suggestion - Image processing.. by balayya

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others about the Monastery: (8)
As of 2024-04-16 09:50 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found