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 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 保护模式-系统加载-段寄存器