I'm learning png IDAT chunks now. I tried writing my own code to read them, and it works fine if there is only 1 IDAT chunk, but fails when there are more "IDAT 78 DA" chunks. My question is that: What should I modify in my code and how? Thanks for all the replies. :)
<?php
$in_filename = "stego15.png";
$raw_data = file_get_contents($in_filename);
$idat_chunks = explode('IDAT', substr($raw_data, 0, -4));
foreach ($idat_chunks as $idat_number=>$idat_chunk) {
if ($idat_number==0) {
continue;
}
$chunk = substr($idat_chunk, 2, -4);
$decompressed = gzinflate($chunk);
list($width, $height) = getimagesize($in_filename);
$data = str_split(bin2hex($decompressed), $width*6+2);
$grouped_data = array();
foreach ($data as $row=>$d) {
$grouped_data[$row] = str_split(substr($d, 2), 6);
}
echo '<h1>'.$idat_number.'. chunk</h1>';
var_dump($grouped_data);
}
?>
What do you mean more "IDAT 78 DA" chunks? It is unlikely that you would see those particular bytes, a zlib header, in the 2nd or later IDAT chunks. All of the image data is compressed once, and then broken up into chunks. So you need to put all the IDAT data together and then inflate it all at once.