<small id='PWDVp'></small><noframes id='PWDVp'>

<i id='PWDVp'><tr id='PWDVp'><dt id='PWDVp'><q id='PWDVp'><span id='PWDVp'><b id='PWDVp'><form id='PWDVp'><ins id='PWDVp'></ins><ul id='PWDVp'></ul><sub id='PWDVp'></sub></form><legend id='PWDVp'></legend><bdo id='PWDVp'><pre id='PWDVp'><center id='PWDVp'></center></pre></bdo></b><th id='PWDVp'></th></span></q></dt></tr></i><div id='PWDVp'><tfoot id='PWDVp'></tfoot><dl id='PWDVp'><fieldset id='PWDVp'></fieldset></dl></div>

  • <legend id='PWDVp'><style id='PWDVp'><dir id='PWDVp'><q id='PWDVp'></q></dir></style></legend>
    <tfoot id='PWDVp'></tfoot>

          <bdo id='PWDVp'></bdo><ul id='PWDVp'></ul>
      1. 在 php 中附加一个 png pHYs 块

        Appending a png pHYs chunk in php(在 php 中附加一个 png pHYs 块)

            <tbody id='IWUMk'></tbody>
          <tfoot id='IWUMk'></tfoot>

            <i id='IWUMk'><tr id='IWUMk'><dt id='IWUMk'><q id='IWUMk'><span id='IWUMk'><b id='IWUMk'><form id='IWUMk'><ins id='IWUMk'></ins><ul id='IWUMk'></ul><sub id='IWUMk'></sub></form><legend id='IWUMk'></legend><bdo id='IWUMk'><pre id='IWUMk'><center id='IWUMk'></center></pre></bdo></b><th id='IWUMk'></th></span></q></dt></tr></i><div id='IWUMk'><tfoot id='IWUMk'></tfoot><dl id='IWUMk'><fieldset id='IWUMk'></fieldset></dl></div>
            <legend id='IWUMk'><style id='IWUMk'><dir id='IWUMk'><q id='IWUMk'></q></dir></style></legend>
                <bdo id='IWUMk'></bdo><ul id='IWUMk'></ul>

                <small id='IWUMk'></small><noframes id='IWUMk'>

                • 本文介绍了在 php 中附加一个 png pHYs 块的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我正在尝试添加一些有关物理尺寸的信息,以便在生成 PNG 之前打印它们.

                  I'm trying to tack on some information about the physical size for printing my PNGs just before they are generated.

                  阅读 libpng doc 和 pHYs 块规范很有帮助但我似乎无法破解它.

                  Reading the libpng doc and the pHYs chunk specifications has been helpful but I just can't seem to crack it.

                  我已尝试以最手动和最简单的方式添加此块,但是 .png 文件最终损坏.我错过了编码技巧吗?

                  I have tried adding this chunk in the most manual and simplest way possible, however, the .png file ends up corrupted. Am I missing an encoding trick?

                  对于 CRC 计算,我使用了 this site,已插入下面代码给我的块的 ASCII 值.

                  For the CRC computation I have used the 32-bit result of this site, having plugged in the ASCII values for the chunk that the code below gives me.

                  $encoded = $_POST['imgdata'];
                  $encoded = str_replace(' ', '+', $encoded);
                  $decoded=  base64_decode($encoded);
                  
                  $test = explode('IDAT',$decoded);
                  $ppu='00000000000000000010111000100011';  //32-bit integer for the pixels per unit
                  $dppu=bindec($ppu);
                  $test[0].=sprintf("%c",bindec('00000000000000000000000000001001')) //length, also 32-bit
                      .'pHYs'                                                      //type
                      .  sprintf("%c",$dppu)                             //Pixels per unit, x axis
                      . sprintf("%c",$dppu)                             //Pixels per unit, y axis
                      .'1'                                                 //Units in metres (1 byte)
                      .  sprintf("%c",  bindec(base_convert('0x0BFAAA7E', 16, 2))) //CRC (32-bit)
                      .'IDAT';
                  $fintest=implode($test);
                  
                  echo $fintest;
                  

                  请让我知道像这样入侵它是否可行.我也不确定我的 32 位整数:当我正在做正确的方法使它们成为 32 位时,是否对它们进行了零填充?

                  Please let me know whether hacking it in like this is likely to work. I am also unsure about my 32-bit integers: is zero-padding them as I am doing the correct way to make them 32-bit?

                  推荐答案

                  花了一天的时间,我发现这样做的方法是逐字节翻译所有内容.按照文档,pHYs 块需要:

                  After having spent the day on this, I found that the way to do this was to translate everything byte by byte. Following the docs, the pHYs chunk takes:

                  • 块(仅数据)长度为 4 个字节
                  • 4 个字节用于块类型(字符pHYs")
                  • 9 字节用于块数据:x 和 y 密度各 4 字节,单位选择 1 字节
                  • 4 个字节用于 CRC

                  我将所有这些都写成二进制字符串,必要时用 0 填充字节.然后事实证明, chr() 函数正确编码了它以在 PNG 文件中使用,这与我使用的 sprintf("%c",$string) 方法不同在问题中.这是代码

                  I wrote all this as a binary string, padding the bytes with 0 as necessary. It then turns out that the chr() function correctly encodes this to be used in the PNG file, unlike the sprintf("%c",$string) method I use in the question. Here is the code

                  $encoded = $_POST['imgdata'];
                  $encoded = str_replace(' ', '+', $encoded);
                  $decoded=  base64_decode($encoded);
                  
                  $binstring='00000000000000000000000000001001' //4-byte length
                          . '01110000010010000101100101110011' //4-byte type or 'pHYs'
                          . '000000000000000000101110001000110000000000000000001011100010001100000001' //9-byte data
                          . base_convert('0x0BFAAA7E', 16, 2); //4-byte CRC
                  foreach (str_split($binstring,8) as $b) {
                      $on.=chr(bindec($b));
                  }
                  

                  然后将 $on 变量附加到 IDAT 块长度的 4 个字节之前的位置.

                  The $on variable is then appended to the position just before the 4 bytes of the IDAT chunk length.

                  这篇关于在 php 中附加一个 png pHYs 块的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  PHP Upload File Validation(PHP 上传文件验证)
                  PHP Error - Uploading a file(PHP 错误 - 上传文件)
                  How can I write tests for file upload in PHP?(如何在 PHP 中编写文件上传测试?)
                  php resizing image on upload rotates the image when i don#39;t want it to(php在上传时调整图像大小会在我不想要它时旋转图像)
                  How to send additional data using PLupload?(如何使用 PLupload 发送附加数据?)
                  change button text in js/ajax after mp4 =gt;mp3 conversion in php(在 php 中的 mp4 =gt;mp3 转换后更改 js/ajax 中的按钮文本)
                  <tfoot id='lhfJc'></tfoot>
                • <legend id='lhfJc'><style id='lhfJc'><dir id='lhfJc'><q id='lhfJc'></q></dir></style></legend>
                      <tbody id='lhfJc'></tbody>
                    <i id='lhfJc'><tr id='lhfJc'><dt id='lhfJc'><q id='lhfJc'><span id='lhfJc'><b id='lhfJc'><form id='lhfJc'><ins id='lhfJc'></ins><ul id='lhfJc'></ul><sub id='lhfJc'></sub></form><legend id='lhfJc'></legend><bdo id='lhfJc'><pre id='lhfJc'><center id='lhfJc'></center></pre></bdo></b><th id='lhfJc'></th></span></q></dt></tr></i><div id='lhfJc'><tfoot id='lhfJc'></tfoot><dl id='lhfJc'><fieldset id='lhfJc'></fieldset></dl></div>

                  • <small id='lhfJc'></small><noframes id='lhfJc'>

                          <bdo id='lhfJc'></bdo><ul id='lhfJc'></ul>