Parsing a .PNG file really isn't hard, especially if you don't really care about the content. Here's something to get you started:

use strict; use warnings; my $file = '...'; open my $pngIn, '<:raw', $file or die "Can't open '$file': $!\n"; read $pngIn, my $header, 8; my ($prefix, $png, $crlf, $ctrlZ, $lf) = unpack "aa3a2aa", $header; die "Bad header prefix\n" if ord $prefix != 0x89; die "Bad header type\n" if $png ne 'PNG'; die "Bad header crlf\n" if $crlf ne "\r\n"; die "Bad header Ctrl-Z\n" if ord $ctrlZ != 0x1a; die "Bad header newline\n" if $lf ne "\n"; while (!eof $pngIn) { read $pngIn, my $chunkHeader, 8 or last; my ($length, $type) = unpack "Na4", $chunkHeader; read $pngIn, my $body, $length + 4 or die "Truncated chunk\n"; my ($payload, $crc) = unpack "a$length N", $body; last if $type eq 'IEND'; }

Tested on Windows. Probably OK on a big endien machine but those are harder to come by now that Apple have gone Intel. It doesn't do anything with the chunk data other than skipping through the chunk headers. It also doesn't try to be smart about excessively large chunks.

Premature optimization is the root of all job security

In reply to Re^3: File extraction 2nd try by GrandFather
in thread File extraction 2nd try by knight.of.ni

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



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.