Code Comments

Programming Forum and web based access to our favorite programming groups.
For Programmers: Free Programming Magazines | New: Database administration forum
Registration is free! Edit your profileCalendarFind other membersFrequently Asked QuestionsSearch -> 
Post New Thread











Thread
Author

Tk::Photo
Hi everybody,

i try to write a small script that lets me display JPEG
files in a directory.

So i started with this little script that i've aded below.

Basically, load_pic complains that it can't load the image.
The image exists and has the correct file name.

couldn't recognize data in image file "@"
at /usr/lib/perl5/vendor_perl/5.8.3/i586-linux-thread-multi/Tk/Image.pm\
line 21.

Can anybody show me a working example of loading a JPEG file and
displaying it?


Best regards,
Torsten.


#! /usr/bin/perl -w

use Tk;
use Tk::Photo;

$pattern = '.*?\.jpg';

opendir(DIR, ".");
@F = readdir(DIR);
@F = grep (/$pattern/, @F);
$p = 0;

$mw = MainWindow->new();
$fr = $mw->Frame();
$quit = $fr->Button('-text' => "Exit", '-command' => \&ex);
$nxt = $fr->Button('-text' => "Next", '-command' => \&nextp);

$quit->pack(side => "left");
$nxt->pack(side => "left");
load_pic($p);

$actual->pack(side => "top");

$fr->pack(side => "top");


MainLoop;


sub ex {
exit;
}

sub nextp {
if($p < $#{@F}) {
$p++;
load_pic($p);
}
}

sub load_pic {
my ($i) = @_;

print "loading $F[$p]\n";
$actual = $fr->Photo('-file' => $F[$p]);
}


Report this thread to moderator Post Follow-up to this message
Old Post
Torsten Mohr
08-29-04 08:57 PM


Re: Tk::Photo
"Torsten Mohr" <tmohr@s.netic.de> wrote in message
news:cgt7e7$aio$1@schleim.qwe.de...
> Hi everybody,
>
> i try to write a small script that lets me display JPEG
> files in a directory.
>
> So i started with this little script that i've aded below.
>
> Basically, load_pic complains that it can't load the image.
> The image exists and has the correct file name.
>
> couldn't recognize data in image file "@"
> at /usr/lib/perl5/vendor_perl/5.8.3/i586-linux-thread-multi/Tk/Image.pm\
> line 21.
>
> Can anybody show me a working example of loading a JPEG file and
> displaying it?
>
>
> Best regards,
> Torsten.
>
>
> #! /usr/bin/perl -w
>
> use Tk;
> use Tk::Photo;

use Tk::JPEG;

>
> $pattern = '.*?\.jpg';
>
> opendir(DIR, ".");
> @F = readdir(DIR);
> @F = grep (/$pattern/, @F);
> $p = 0;
>
> $mw = MainWindow->new();
> $fr = $mw->Frame();
> $quit = $fr->Button('-text' => "Exit", '-command' => \&ex);
> $nxt = $fr->Button('-text' => "Next", '-command' => \&nextp);
>
> $quit->pack(side => "left");
> $nxt->pack(side => "left");
> load_pic($p);
>
> $actual->pack(side => "top");
>
> $fr->pack(side => "top");
>
>
> MainLoop;
>
>
> sub ex {
>         exit;
> }
>
> sub nextp {
>         if($p < $#{@F}) {
>                 $p++;
>                 load_pic($p);
>         }
> }
>
> sub load_pic {
>         my ($i) = @_;
>
>         print "loading $F[$p]\n";
>         $actual = $fr->Photo('-file' => $F[$p]);

$actual = $fr->Photo(-format=>'jpeg', '-file' => $F[$p]);


> }
>

Jack



Report this thread to moderator Post Follow-up to this message
Old Post
Jack D
08-29-04 08:57 PM


Re: Tk::Photo
"Jack D" <goodcall1@hotmail.dot.com> writes:

> "Torsten Mohr" <tmohr@s.netic.de> wrote in message
> news:cgt7e7$aio$1@schleim.qwe.de... 
[...] 
>
> $actual = $fr->Photo(-format=>'jpeg', '-file' => $F[$p]);
>

The -format option is not necessary for loading --- Tk decides by file
magic which image format to use. The "use Tk::JPEG" line is only
necessary for Tk800 (I think).

Regards,
Slaven

--
Slaven Rezic - slaven <at> rezic <dot> de

Dump a Tk canvas as an xfig file:
http://search.cpan.org/search?mode=...y=Tk::CanvasFig

Report this thread to moderator Post Follow-up to this message
Old Post
Slaven Rezic
08-30-04 01:56 AM


Re: Tk::Photo
Hi,

thanks for your hints.

Sadly, it still does not work.  Loading a GIF with an example i
found works fine, but JPEG fails.

Does anybody know what LIB Tk::Photo relies on to load a Jpeg?
Or is it internal code that should work anyway?

I work on Linux, Kernel 2.6.7, SuSE 9.1 based system (with changes).


Best regards,
Torsten.
 
 

> The -format option is not necessary for loading --- Tk decides by file
> magic which image format to use. The "use Tk::JPEG" line is only
> necessary for Tk800 (I think).



Report this thread to moderator Post Follow-up to this message
Old Post
Torsten Mohr
08-30-04 01:56 AM


Re: Tk::Photo
"Torsten Mohr" <tmohr@s.netic.de> wrote in message
news:cgthr0$d2u$1@schleim.qwe.de...
> Hi,
>
> thanks for your hints.
>
> Sadly, it still does not work.  Loading a GIF with an example i
> found works fine, but JPEG fails.

Did you try putting:

use Tk::JPEG;

in your script?

Jack



Report this thread to moderator Post Follow-up to this message
Old Post
Jack D
08-30-04 08:57 AM


Re: Tk::Photo
Torsten Mohr <tmohr@s.netic.de> wrote in message news:<cgt7e7$aio$1@schleim.qwe.de>...[colo
r=darkred]
> Hi everybody,
>
> i try to write a small script that lets me display JPEG
> files in a directory.
>
> So i started with this little script that i've aded below.
>
> Basically, load_pic complains that it can't load the image.
> The image exists and has the correct file name.
>
> couldn't recognize data in image file "@"
> at /usr/lib/perl5/vendor_perl/5.8.3/i586-linux-thread-multi/Tk/Image.pm\
> line 21.
>
> Can anybody show me a working example of loading a JPEG file and
> displaying it?[/color]

Here is a working script with zoom functionality:
http://herrmanns-stern.de/software/etc/etc.shtml#zoom  (description)
http://herrmanns-stern.de/software/etc/tkjpegZoom      (the code)

Bye,
Martin

Report this thread to moderator Post Follow-up to this message
Old Post
Martin Herrmann
08-30-04 01:58 PM


Re: Tk::Photo
Hi,

i did not find Tk::JPEG, so i installed Tk::JPEG::Lite and now
it works.

> Did you try putting:
>
> use Tk::JPEG;
>
> in your script?


Thanks for your hints,
Torsten.


Report this thread to moderator Post Follow-up to this message
Old Post
Torsten Mohr
08-31-04 01:56 AM


Sponsored Links




Last Thread Next Thread Next
Search this forum -> 
Post New Thread

PerlTk archive

Show a Printable Version Send to friend Email This Page to Someone! subscribe to this thread Receive updates to this thread
Computer Consultants
Programming Jobs
Visual Basic Controls
SQL Server Programming
Webservices
Java Security
Visual Studio
C# Programming
Visual J++
Software engineering
Open source Software
Perl Programming
PHP Programming
ASP Programming
ASP .NET Programming
Visual Basic Programming
Windows Scripting Host
Java Programming
Java Help
Java Beans
VBScript
Cobol
MAC Applications
Unix Programming
Forum Jump:
All times are GMT. The time now is 04:54 PM.

 
Free MCSE Braindumps | Real Estate Topics

Programming forum archive

Copyrights CodeComments.com 2004 - 2006

Powered by vBulletin Copyright 2000-2006 Jelsoft Enterprises Limited.