Code Comments
Programming Forum and web based access to our favorite programming groups.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]);
}
Post Follow-up to this message
"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
Post Follow-up to this message"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
Post Follow-up to this messageHi, 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).
Post Follow-up to this message"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
Post Follow-up to this messageTorsten 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
Post Follow-up to this messageHi, 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.
Post Follow-up to this messagePowered by vBulletin
Copyright 2000-2006 Jelsoft Enterprises Limited.