我可以检测是否从多页PDF文件转换了PNG文件,并使用ImageMagick将图像拆分为单独的文件吗? [英] Can I detect if a PNG file was converted from a multiple page PDF file and split the image into separate files using ImageMagick?

查看:128
本文介绍了我可以检测是否从多页PDF文件转换了PNG文件,并使用ImageMagick将图像拆分为单独的文件吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我遇到的问题是,在OS X的预览中使用PDF导出功能创建的PNG文件在某些​​浏览器(Safari,Firefox)中显示为动画GIF,或仅显示第一页(Chrome)如果转换的PDF文件有多个页面(通过动画GIF,我的意思是它在不同的页面之间闪烁)。有没有办法使用PHP来检测上传的PNG文件是否以这种方式转换,然后将其拆分为单独的图像并使用ImageMagick将它们拼接在一起?

解决方案

这是一个动画PNG或Mozilla APNG 格式文件。您可以通过运行 pngcheck 来检测它:

  pngcheck -v npma33-png-convert-test.png 

输出

 文件:npma33-png-convert-test.png(981954字节)
chunk IHDR偏移量0x0000c,长度13
1275 x 1650图像,32位RGB + alpha,非隔行扫描
chunk acTL偏移量0x00025,长度8< --- APNG
未知私有,辅助,不安全复制块
块iCCP在偏移量0x00039,长度281
配置文件名称= ICC配置文件,压缩方法= 0(deflate)
压缩配置文件= 268字节
chunk pHYs在偏移量0x0015e,长度9: 5906x5906像素/米(150 dpi)
chunk fcTL偏移量0x00173,长度26< --- APNG
未知私有,辅助,不安全到拷贝块
块IDAT偏移量0x00199 ,长度16384
zlib:放气,32K窗口,超快压缩
块IDAT位于偏移量0x041a5,长度16384
块IDAT偏移量0x081b1,长度16384
块IDAT偏移量0x0c1bd,长度16384
块IDAT偏移量0x101c9,长度16384
块IDAT at偏移量0x141d5,长度16384
块IDAT偏移量0x181e1,长度16384
块IDAT偏移量0x1c1ed,长度16384
块IDAT偏移量0x201f9,长度16384
块IDAT偏移量0x24205 ,长度16384
块IDAT偏移量0x28211,长度16384
块IDAT偏移量0x2c21d,长度16384
块IDAT偏移量0x30229,长度16384
块IDAT偏移量0x34235,长度16384
块IDAT偏移量0x38241,长度16384
块IDAT偏移量0x3c24d,长度16384
块IDAT偏移量0x40259,长度16384
块IDAT偏移量0x44265,长度16384
块IDAT偏移量0x48271,长度16384
块IDAT偏移量0x4c27d,长度16384
块IDAT偏移量0x50289,长度16384
块IDAT位于偏移量0x54295,长度16384
块IDAT偏移量0x582a1,长度16384
块IDAT偏移量0x5c2ad,长度16384
块IDAT偏移量0x602b9,长度16384
块IDAT at偏移0x642c5,长度15969
块fcTL偏移量0x68132,长度26< --- APNG
未知私有,辅助,不安全到拷贝块
块fdAT偏移量0x68158,长度16388
未知私有,辅助,不安全复制块
块fdAT偏移量为0x6c168,长度为16388
未知私有,辅助,不安全复制块
chunk fdAT偏移量0x70178,长度16388
未知私有,辅助,不安全复制块
块fdAT偏移量0x74188,长度16388
未知私有,辅助,不安全复制块
块fdAT偏移0x78198,长度16388
未知私有,辅助,不安全复制块
块fdAT偏移量0x7c1a8,长度16388
未知私有,辅助,u nsafe-to-copy chunk
chunk fdAT偏移量0x801b8,长度16388
未知私有,辅助,不安全到拷贝块
块fdAT偏移量0x841c8,长度16388
未知私有,辅助,不安全复制块
块fdAT偏移量0x881d8,长度16388
未知私有,辅助,不安全复制块
块fdAT偏移量0x8c1e8,长度16388
未知私有,辅助,不安全复制块
块fdAT偏移量0x901f8,长度16388
未知私有,辅助,不安全复制块
块fdAT偏移量0x94208 ,长度16388
未知私人,辅助,不安全复制块
块fdAT偏移量0x98218,长度16388
未知私有,辅助,不安全复制块
块fdAT偏移量为0x9c228,长度为16388
未知私有,辅助,不安全到拷贝块
块fdAT偏移量为0xa0238,长度为16388
未知私有,辅助,不安全到拷贝块
C hunk fdAT偏移量为0xa4248,长度为16388
未知私有,辅助,不安全到拷贝块
块fdAT偏移量为0xa8258,长度为16388
未知私有,辅助,不安全到拷贝块
chunk fdAT偏移0xac268,长度16388
未知私有,辅助,不安全复制块
块fdAT偏移量0xb0278,长度16388
未知私有,辅助,不安全 - 复制块
块fdAT偏移0xb4288,长度16388
未知私有,辅助,不安全复制块
块fdAT偏移量0xb8298,长度16388
未知私有,辅助,不安全复制块
块fdAT偏移0xbc2a8,长度16388
未知私有,辅助,不安全复制块
块fdAT偏移量0xc02b8,长度16388
未知私有,辅助,不安全复制块
块fdAT偏移量为0xc42c8,长度为16388
未知私有,辅助,不安全复制块
块fdAT偏移量为0xc82d8,长度16388
未知私人,辅助,不安全复制块
块fdAT偏移量0xcc2e8,长度16388
未知私有,辅助,不安全复制块
块fdAT偏移量0xd02f8,长度16388
未知私有,辅助,不安全复制块
块fdAT偏移量0xd4308,长度16388
未知私有,辅助,不安全到拷贝块
chunk fdAT偏移量为0xd8318,长度为16388
未知私有,辅助,不安全到拷贝块
块fdAT偏移量为0xdc328,长度为16388
未知私有,辅助,不安全到 - 复制块
块fdAT偏移0xe0338,长度16388
未知私有,辅助,不安全复制块
块fdAT偏移量0xe4348,长度16388
未知私有,辅助,不安全复制块
块fdAT偏移量为0xe8358,长度为16388
未知私有,辅助,不安全复制块
块fdAT偏移量为0xec368,长度为14406
unkno私人,辅助,不安全复制块
块IEND位于偏移量0xefbba,长度为0

赠送 APNG 是否存在 acTL fcTL 动画控件帧控制的块。



您可以抑制这些块的输出(使用以下命令停止闪烁):

 转换npma33-png-convert-test.png -define png: exclude-chunk = acTL result.png 

但我没有做过任何关于是否会影响其他人的测试诸如压缩实现或任何其他元数据受影响的事情 - 所以请自己做检查。



所以,如果你使用 bash 你最终会得到这样的结果:

  file =npma33-png-convert-test .png
如果pngcheck -v$ file| grep -q acTL;然后
转换$ file-define png:exclude-chunk = acTL$ file
fi

并排和重新加入框架的预期方式可能是

 转换npma .... -separate + append result.png 

 转换npma ... -coalesce + append result.png 

但ImageMagick似乎不愿意这样做 - 我只能猜测 APNG 并不支持。



<我还尝试使用 Photoshop风格的图层寻址,但这也不起作用:

 转换npma ... [0] page1.png 
转换npma ... [1] page2.png


I'm having a problem where a PNG file that was created using the PDF export feature in OS X's Preview will display like an animated GIF in some browsers (Safari,Firefox) or display only the first page (Chrome) if the converted PDF file has more than one page (By animated GIF I mean it flickers between the different pages). Is there a way using PHP to detect if an uploaded PNG file was converted this way, and then split it into separate images and stitch them together using ImageMagick?

解决方案

It is an animated PNG, or Mozilla APNG format file. You can detect it by running pngcheck like this:

pngcheck -v npma33-png-convert-test.png

Output

File: npma33-png-convert-test.png (981954 bytes)
  chunk IHDR at offset 0x0000c, length 13
    1275 x 1650 image, 32-bit RGB+alpha, non-interlaced
  chunk acTL at offset 0x00025, length 8                   <--- APNG
    unknown private, ancillary, unsafe-to-copy chunk
  chunk iCCP at offset 0x00039, length 281
    profile name = ICC Profile, compression method = 0 (deflate)
    compressed profile = 268 bytes
  chunk pHYs at offset 0x0015e, length 9: 5906x5906 pixels/meter (150 dpi)
  chunk fcTL at offset 0x00173, length 26                  <--- APNG
    unknown private, ancillary, unsafe-to-copy chunk
  chunk IDAT at offset 0x00199, length 16384
    zlib: deflated, 32K window, superfast compression
  chunk IDAT at offset 0x041a5, length 16384
  chunk IDAT at offset 0x081b1, length 16384
  chunk IDAT at offset 0x0c1bd, length 16384
  chunk IDAT at offset 0x101c9, length 16384
  chunk IDAT at offset 0x141d5, length 16384
  chunk IDAT at offset 0x181e1, length 16384
  chunk IDAT at offset 0x1c1ed, length 16384
  chunk IDAT at offset 0x201f9, length 16384
  chunk IDAT at offset 0x24205, length 16384
  chunk IDAT at offset 0x28211, length 16384
  chunk IDAT at offset 0x2c21d, length 16384
  chunk IDAT at offset 0x30229, length 16384
  chunk IDAT at offset 0x34235, length 16384
  chunk IDAT at offset 0x38241, length 16384
  chunk IDAT at offset 0x3c24d, length 16384
  chunk IDAT at offset 0x40259, length 16384
  chunk IDAT at offset 0x44265, length 16384
  chunk IDAT at offset 0x48271, length 16384
  chunk IDAT at offset 0x4c27d, length 16384
  chunk IDAT at offset 0x50289, length 16384
  chunk IDAT at offset 0x54295, length 16384
  chunk IDAT at offset 0x582a1, length 16384
  chunk IDAT at offset 0x5c2ad, length 16384
  chunk IDAT at offset 0x602b9, length 16384
  chunk IDAT at offset 0x642c5, length 15969
  chunk fcTL at offset 0x68132, length 26                 <--- APNG
    unknown private, ancillary, unsafe-to-copy chunk
  chunk fdAT at offset 0x68158, length 16388
    unknown private, ancillary, unsafe-to-copy chunk
  chunk fdAT at offset 0x6c168, length 16388
    unknown private, ancillary, unsafe-to-copy chunk
  chunk fdAT at offset 0x70178, length 16388
    unknown private, ancillary, unsafe-to-copy chunk
  chunk fdAT at offset 0x74188, length 16388
    unknown private, ancillary, unsafe-to-copy chunk
  chunk fdAT at offset 0x78198, length 16388
    unknown private, ancillary, unsafe-to-copy chunk
  chunk fdAT at offset 0x7c1a8, length 16388
    unknown private, ancillary, unsafe-to-copy chunk
  chunk fdAT at offset 0x801b8, length 16388
    unknown private, ancillary, unsafe-to-copy chunk
  chunk fdAT at offset 0x841c8, length 16388
    unknown private, ancillary, unsafe-to-copy chunk
  chunk fdAT at offset 0x881d8, length 16388
    unknown private, ancillary, unsafe-to-copy chunk
  chunk fdAT at offset 0x8c1e8, length 16388
    unknown private, ancillary, unsafe-to-copy chunk
  chunk fdAT at offset 0x901f8, length 16388
    unknown private, ancillary, unsafe-to-copy chunk
  chunk fdAT at offset 0x94208, length 16388
    unknown private, ancillary, unsafe-to-copy chunk
  chunk fdAT at offset 0x98218, length 16388
    unknown private, ancillary, unsafe-to-copy chunk
  chunk fdAT at offset 0x9c228, length 16388
    unknown private, ancillary, unsafe-to-copy chunk
  chunk fdAT at offset 0xa0238, length 16388
    unknown private, ancillary, unsafe-to-copy chunk
  chunk fdAT at offset 0xa4248, length 16388
    unknown private, ancillary, unsafe-to-copy chunk
  chunk fdAT at offset 0xa8258, length 16388
    unknown private, ancillary, unsafe-to-copy chunk
  chunk fdAT at offset 0xac268, length 16388
    unknown private, ancillary, unsafe-to-copy chunk
  chunk fdAT at offset 0xb0278, length 16388
    unknown private, ancillary, unsafe-to-copy chunk
  chunk fdAT at offset 0xb4288, length 16388
    unknown private, ancillary, unsafe-to-copy chunk
  chunk fdAT at offset 0xb8298, length 16388
    unknown private, ancillary, unsafe-to-copy chunk
  chunk fdAT at offset 0xbc2a8, length 16388
    unknown private, ancillary, unsafe-to-copy chunk
  chunk fdAT at offset 0xc02b8, length 16388
    unknown private, ancillary, unsafe-to-copy chunk
  chunk fdAT at offset 0xc42c8, length 16388
    unknown private, ancillary, unsafe-to-copy chunk
  chunk fdAT at offset 0xc82d8, length 16388
    unknown private, ancillary, unsafe-to-copy chunk
  chunk fdAT at offset 0xcc2e8, length 16388
    unknown private, ancillary, unsafe-to-copy chunk
  chunk fdAT at offset 0xd02f8, length 16388
    unknown private, ancillary, unsafe-to-copy chunk
  chunk fdAT at offset 0xd4308, length 16388
    unknown private, ancillary, unsafe-to-copy chunk
  chunk fdAT at offset 0xd8318, length 16388
    unknown private, ancillary, unsafe-to-copy chunk
  chunk fdAT at offset 0xdc328, length 16388
    unknown private, ancillary, unsafe-to-copy chunk
  chunk fdAT at offset 0xe0338, length 16388
    unknown private, ancillary, unsafe-to-copy chunk
  chunk fdAT at offset 0xe4348, length 16388
    unknown private, ancillary, unsafe-to-copy chunk
  chunk fdAT at offset 0xe8358, length 16388
    unknown private, ancillary, unsafe-to-copy chunk
  chunk fdAT at offset 0xec368, length 14406
    unknown private, ancillary, unsafe-to-copy chunk
  chunk IEND at offset 0xefbba, length 0

The giveaway that it is APNG is the presence of the acTL and fcTL chunks which are animation control and frame control.

You can suppress output of those chunks (which will stop the flickering) using the following command:

convert npma33-png-convert-test.png -define png:exclude-chunk=acTL result.png

but I have not done any testing on whether that will affect other things such as the compression achieved or how any other meta-data is affected - so please do your own checks.

So, if you use bash you will end up with something like this:

file="npma33-png-convert-test.png"
if pngcheck -v "$file" | grep -q acTL; then 
   convert "$file" -define png:exclude-chunk=acTL "$file"
fi

The expected way to separate and rejoin the frames side-by-side would probably be

convert npma.... -separate +append result.png

or

convert npma... -coalesce +append result.png

but ImageMagick seems reluctant to do either - I can only guess APNG is not really supported.

I also tried using Photoshop-style layer addressing, but that doesn't work either:

convert npma...[0] page1.png
convert npma...[1] page2.png

这篇关于我可以检测是否从多页PDF文件转换了PNG文件,并使用ImageMagick将图像拆分为单独的文件吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆