Home > Archive > PERL Miscellaneous > June 2005 > Photo does not recognize format of Archive::Zip contents
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]
| Author |
Photo does not recognize format of Archive::Zip contents
|
|
| Richard Trahan 2005-06-08, 8:58 am |
| Consider the following sub. On entry, $tl is a Toplevel, $rmn is an
index into an array of Archive::Zip object member names; comments
explain the others.
sub display_image
{
my ($tl,$rmn) = @_; # Toplevel, requested member number
my $mnref = $tl->{'member_names'}; # ref to member names array
my $zip = $tl->{'zip'}; # Archive::Zip object
my $membername = $mnref->[$rmn];
my $member = $zip->memberNamed($membername);
$tl->{'current_member_number'} = $rmn; # reset current member
my $fh;
my $fn = "C:/windows/temp/temp.jpg";
open $fh,">",$fn;
$member->extractToFileHandle($fh); # this works ok
close $fh;
# my $contents = $zip->contents($member); # (binary) jpeg data
# open $fh,">","C:/temp/temp2.jpg";
# binmode $fh;
# print $fh $contents; # this works ok
# close $fh;
my $image = $tl->Photo(
'-format' => 'jpeg',
# -data => $contents, # this doesn't work
-file => $fn, # this works ok
);
my $button = $tl->{'button'}; # button where image is displayed
$button->configure(-image => $image); # set image
$tl->configure(-title => $tl->{'file_name'} .
":" . $tl->{'sequence'} . " - $membername");
}
Commented sections show that I can successfully extract the "contents"
of a Zip::Archive member (all of which are jpeg files), and write it to
a file (it displays perfectly in a browser, PhotoEditor, etc.). I can
also "extract" that member to another file and specify that file name to
the Photo object, whereupon it displays just fine. But when I take the
"contents", which is supposed to be pure jpeg binary data, and feed it
to the Photo object, the system complains that it doesn't recognize the
file format.
Any help, please.
| |
| Anno Siegel 2005-06-08, 8:58 am |
| Richard Trahan <rtrahan@optonline.net> wrote in comp.lang.perl.misc:
> Consider the following sub. On entry, $tl is a Toplevel, $rmn is an
A toplevel what? Please name the modules you are using. Leaving it
up to the reader to guess from one or two function names is impolite.
> index into an array of Archive::Zip object member names; comments
> explain the others.
Is the fact that the images come from a zip archive essential? I
doubt it.
> sub display_image
> {
> my ($tl,$rmn) = @_; # Toplevel, requested member number
> my $mnref = $tl->{'member_names'}; # ref to member names array
> my $zip = $tl->{'zip'}; # Archive::Zip object
>
> my $membername = $mnref->[$rmn];
> my $member = $zip->memberNamed($membername);
> $tl->{'current_member_number'} = $rmn; # reset current member
> my $fh;
> my $fn = "C:/windows/temp/temp.jpg";
> open $fh,">",$fn;
> $member->extractToFileHandle($fh); # this works ok
> close $fh;
> # my $contents = $zip->contents($member); # (binary) jpeg data
That line shouldn't be commented out, you're using $contents later.
Please copy and paste code instead of re-typing it. Trivial errors
like this are distracting.
> # open $fh,">","C:/temp/temp2.jpg";
> # binmode $fh;
> # print $fh $contents; # this works ok
> # close $fh;
> my $image = $tl->Photo(
> '-format' => 'jpeg',
> # -data => $contents, # this doesn't work
> -file => $fn, # this works ok
> );
> my $button = $tl->{'button'}; # button where image is displayed
> $button->configure(-image => $image); # set image
> $tl->configure(-title => $tl->{'file_name'} .
> ":" . $tl->{'sequence'} . " - $membername");
> }
>
> Commented sections show that I can successfully extract the "contents"
> of a Zip::Archive member (all of which are jpeg files), and write it to
> a file (it displays perfectly in a browser, PhotoEditor, etc.). I can
> also "extract" that member to another file and specify that file name to
> the Photo object, whereupon it displays just fine. But when I take the
> "contents", which is supposed to be pure jpeg binary data, and feed it
> to the Photo object, the system complains that it doesn't recognize the
> file format.
Read "perldoc Tk::Photo". Under the heading "IMAGE FORMATS" you'll
find:
The photo image code is structured to allow handlers for
additional image file formats to be added easily. The
photo image code maintains a list of these handlers.
Handlers are added to the list by registering them with a
call to Tk_CreatePhotoImageFormat. The standard Tk
distribution comes with handlers for PPM/PGM and GIF
formats, which are automatically registered on
initialization.
Looks like you may have to find a way to add a jpeg handler. I don't
know why it works with file input, nor why a jpeg handler *is* mentioned
elsewhere in the documentation (except that documentation isn't perfect).
At least this looks like something to explore.
Anno
| |
| Anno Siegel 2005-06-08, 8:58 am |
| Richard Trahan <rtrahan@optonline.net> wrote in comp.lang.perl.misc:
> Consider the following sub. On entry, $tl is a Toplevel, $rmn is an
A toplevel what? Please name the modules you are using. Leaving it
up to the reader to guess from one or two function names is impolite.
> index into an array of Archive::Zip object member names; comments
> explain the others.
Is the fact that the images come from a zip archive essential? I
doubt it.
> sub display_image
> {
> my ($tl,$rmn) = @_; # Toplevel, requested member number
> my $mnref = $tl->{'member_names'}; # ref to member names array
> my $zip = $tl->{'zip'}; # Archive::Zip object
>
> my $membername = $mnref->[$rmn];
> my $member = $zip->memberNamed($membername);
> $tl->{'current_member_number'} = $rmn; # reset current member
> my $fh;
> my $fn = "C:/windows/temp/temp.jpg";
> open $fh,">",$fn;
> $member->extractToFileHandle($fh); # this works ok
> close $fh;
> # my $contents = $zip->contents($member); # (binary) jpeg data
> # open $fh,">","C:/temp/temp2.jpg";
> # binmode $fh;
> # print $fh $contents; # this works ok
> # close $fh;
> my $image = $tl->Photo(
> '-format' => 'jpeg',
> # -data => $contents, # this doesn't work
> -file => $fn, # this works ok
> );
> my $button = $tl->{'button'}; # button where image is displayed
> $button->configure(-image => $image); # set image
> $tl->configure(-title => $tl->{'file_name'} .
> ":" . $tl->{'sequence'} . " - $membername");
> }
>
> Commented sections show that I can successfully extract the "contents"
> of a Zip::Archive member (all of which are jpeg files), and write it to
> a file (it displays perfectly in a browser, PhotoEditor, etc.). I can
> also "extract" that member to another file and specify that file name to
> the Photo object, whereupon it displays just fine. But when I take the
> "contents", which is supposed to be pure jpeg binary data, and feed it
> to the Photo object, the system complains that it doesn't recognize the
> file format.
Read "perldoc Tk::Photo". Under the heading "IMAGE FORMATS" you'll
find:
The photo image code is structured to allow handlers for
additional image file formats to be added easily. The
photo image code maintains a list of these handlers.
Handlers are added to the list by registering them with a
call to Tk_CreatePhotoImageFormat. The standard Tk
distribution comes with handlers for PPM/PGM and GIF
formats, which are automatically registered on
initialization.
Looks like you may have to find a way to add a jpeg handler. I don't
know why it works with file input, nor why a jpeg handler *is* mentioned
elsewhere in the documentation (except that documentation isn't perfect).
At least this looks like something to explore.
Anno
| |
| Richard Trahan 2005-06-08, 3:59 pm |
|
Thank you for your reply.
There are no errors in my sample; $contents is not used later unless all
lines containing $contents are uncommented.
Yes, it is essential that the files come from a zip archive.
Yes, I have read Tk::Photo; JPEG is listed in the Description as a
supported format. The fact that I can read a jpeg file with the "-file"
option illustrates that. It is when "-file" is replaced by "-data =>
contents_from_zip_archive" that it breaks.
A Toplevel would be immediately familiar to anyone conversant with Tk.
Since you opted to point me to Tk::Photo, I assume you are a Tk person,
and you should have known what Toplevel is.
Yes, I do know about comp.lang.perl.tk. I chose to post here, because
the members are more knowledgeable, for the most part.
It is impolite to criticize when you don't know what you're talking about.
| |
| A. Sinan Unur 2005-06-08, 3:59 pm |
| Richard Trahan <rtrahan@optonline.net> wrote in
news:2oCpe.3444$S62.1656@fe11.lga:
> Thank you for your reply.
[ Thank whom for what reply? Please quote some context when you reply. ]
> It is impolite to criticize when you don't know what you're talking
> about.
A verdict more applicable to you than to Anno, for sure.
Sinan
--
A. Sinan Unur <1usa@llenroc.ude.invalid>
(reverse each component and remove .invalid for email address)
comp.lang.perl.misc guidelines on the WWW:
http://mail.augustmail.com/~tadmc/c...guidelines.html
| |
| Anno Siegel 2005-06-08, 3:59 pm |
| Richard Trahan <rtrahan@optonline.net> wrote in comp.lang.perl.misc:
>
> Thank you for your reply.
Whose reply? Please quote some context when you reply.
> There are no errors in my sample; $contents is not used later unless all
> lines containing $contents are uncommented.
Yes. I noticed too late that you chose to give example code that doesn't
demonstrate the error. I corrected that part of my posting, but you seem
to have replied to the uncorrected version. See how quoting *the post that
you saw* can make a difference?
> Yes, it is essential that the files come from a zip archive.
Essential for the error? Are you saying, if you read the string from
a .jpeg file instead of a zip archive you don't have the problem?
That would be an interesting hint, but neither your code nor your
comments indicate that.
> Yes, I have read Tk::Photo; JPEG is listed in the Description as a
> supported format.
It is listed in one place, but not in the section "IMAGE FORMATS"
(in the version I checked). Since you reported a problem with
one of the missing image formats I thought I'd point out the fact.
> The fact that I can read a jpeg file with the "-file"
> option illustrates that. It is when "-file" is replaced by "-data =>
> contents_from_zip_archive" that it breaks.
Yes, I understand that. Does it also break when you read the data from
a file and not a zip archive? I'd expect it does, but your insistence
that Archive::Zip is somehow involved makes me ask.
> A Toplevel would be immediately familiar to anyone conversant with Tk.
Oh. No other module can use the identifier "Toplevel"?
> Since you opted to point me to Tk::Photo, I assume you are a Tk person,
> and you should have known what Toplevel is.
I'm not a "Tk person". I have used the module occasionally and have
it around. I decided to take a look at the relevant documentation,
found a discrepancy and pointed it out.
> Yes, I do know about comp.lang.perl.tk. I chose to post here, because
> the members are more knowledgeable, for the most part.
Don't mix posters up. I didn't point you to c.l.p.tk.
Since you chose to post here it would have been polite to word your
posting for the general audience you can expect here and not for people
who live in a Tk world.
Anno
| |
| Richard Trahan 2005-06-08, 3:59 pm |
| Thank you for your reply.
>
> [ Thank whom for what reply? Please quote some context when you reply. ]
No, I won't. The thanks apply to the parent posting, which you can see
if you group your postings by thread.
| |
| Anno Siegel 2005-06-08, 8:57 pm |
| Richard Trahan <rtrahan@optonline.net> wrote in comp.lang.perl.misc:
> Thank you for your reply.
> No, I won't. The thanks apply to the parent posting, which you can see
> if you group your postings by thread.
So long then, and have a pleasant Usenet experience.
Anno
| |
| David H. Adler 2005-06-08, 8:57 pm |
| On 2005-06-08, Richard Trahan <rtrahan@optonline.net> wrote:
> Thank you for your reply.
> No, I won't. The thanks apply to the parent posting, which you can see
> if you group your postings by thread.
so you feel that everyone should arrange their newsreading the way you
want to and further assume that all posts come in in the same order for
everyone.
I've seen one post indicating that you won't be getting any quality help
from here out, and I think that there will likely be more.
Have the appropriate amount of fun.
dha
--
David H. Adler - <dha@panix.com> - http://www.panix.com/~dha/
_Day of Wrath_ is probably Dreyer's most popular film, which already
indicates something of the problems it poses.
- David Bordwell, The Films of Carl-Theodor Dreyer
| |
| Damian James 2005-06-08, 8:57 pm |
| On Wed, 08 Jun 2005 12:50:50 -0400, Richard Trahan said:
> Thank you for your reply.
> No, I won't. The thanks apply to the parent posting, which you can see
> if you group your postings by thread.
Who said "[ Thank whom for what reply? Please quote some context when you
reply. ]"? I should wait till my news server has a copy of all previous
posts in the thread before reading this?
*sigh*
You're perhaps not aware of the distributed nature of usenet. You might
ponder what the implications are of there not existing a single central
news server from which changes are promulgated and posts served. Instead,
the lag interval between posting and various people seeing the post
is quite undeterminable. Some people will see this reply before the post
of yours that I have replied to. Some news servers might not even carry
the post that someone is referring to (I know my leafnode configuration
drops anything with more than 3 crossposts, because in the groups I read,
I have never seen a non-spam post that matches that).
You may perhaps be using some sort of web-based interface (Not google, I
would not have seen your post at all, nor any replies to it, if that were
the case). Even in that case the vagaries of usenet apply, you may indeed
not see all posts in a thread. And even on google, you won't see all posts
by all people at all times, even if the post made it to the server, since
there exists the X-No-Archive header, and many people use it routinely.
All in all, denizens of groups like this one have established a convention
that says: quote what you are replying to, there's no other reliable way
for others to know what that is. You are either bringing a convention from
another environment, of you are making up your own. Either way, no-one is
saying that YOU MUST follow the conventions of this group while you are
here, but all the same not doing so shows disrespect, even contempt, of
the folks who post here regularly. Do you really want to be doing that?
Hope this helps your understanding of the situation here a little.
--damian
--
@:=grep!(m!$/|#!..$|),split//,<DATA>;@;=0..$#:;while($:=@;){$;=rand
$:-- ,@;[$;,$:]=@;[$:,$;]while$:;push@|,shift
@;if$;[0]==@|;select$,,
$,,$,,1/80;print qq x\bxx((@;+@|)*$|++),@:[@|,@;],!@;&&$/} __END__
Just another Perl Hacker,
| |
| W. Citoan 2005-06-09, 3:57 am |
| Anno Siegel wrote:
>
> Yes. I noticed too late that you chose to give example code that
> doesn't demonstrate the error. I corrected that part of my posting,
> but you seem to have replied to the uncorrected version. See how
> quoting *the post that you saw* can make a difference?
Well, to be fair, I saw both posts as well and assumed it was a double
post (as happens every once in awhile) since the beginning of each post
(the part visible in my display without scrolling) was identical. Only
upon seeing this did I go back and notice the Supersedes header. Since
many newsreaders/servers don't do anything with that header, a note at
the beginning of the second post would have been nice.
Though I do agree that he does need to learn the value of quoting...
- W. Citoan
--
The only thing we have to fear is fear itself.
-- Franklin D. Roosevelt
|
|
|
|
|