Home > Archive > PerlTk > August 2004 > Tk::Photo
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
|
|
| Torsten Mohr 2004-08-29, 3:57 pm |
| 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]);
}
| |
| Jack D 2004-08-29, 3:57 pm |
|
"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
| |
| Slaven Rezic 2004-08-29, 8:56 pm |
| "Jack D" <goodcall1@hotmail.dot.com> writes:
> "Torsten Mohr" <tmohr@s.netic.de> wrote in message
> news:cgt7e7$aio$1@schleim.qwe.de...
[...][color=darkred]
>
> $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
| |
| Torsten Mohr 2004-08-29, 8:56 pm |
| 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.
[color=darkred]
[color=darkred]
> 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).
| |
| Jack D 2004-08-30, 3:57 am |
|
"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
| |
| Martin Herrmann 2004-08-30, 8:58 am |
| 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?
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
| |
| Torsten Mohr 2004-08-30, 8:56 pm |
| 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.
|
|
|
|
|