douqiao8032 2017-04-22 21:13
浏览 220

PNG多个IDAT块(PHP)

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);
}

?>
  • 写回答

1条回答 默认 最新

  • dongyishen5796 2017-04-23 00:04
    关注

    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.

    评论

报告相同问题?

悬赏问题

  • ¥15 高价求中通快递查询接口
  • ¥15 解决一个加好友限制问题 或者有好的方案
  • ¥15 关于#java#的问题,请各位专家解答!
  • ¥15 急matlab编程仿真二阶震荡系统
  • ¥20 TEC-9的数据通路实验
  • ¥15 ue5 .3之前好好的现在只要是激活关卡就会崩溃
  • ¥50 MATLAB实现圆柱体容器内球形颗粒堆积
  • ¥15 python如何将动态的多个子列表,拼接后进行集合的交集
  • ¥20 vitis-ai量化基于pytorch框架下的yolov5模型
  • ¥15 如何实现H5在QQ平台上的二次分享卡片效果?