douba6365 2013-04-26 02:57 采纳率: 100%
浏览 76
已采纳

将PNG-8转换为PNG-24(或其他)

I have a PHP application where...

  1. User uploads a scanned image (png or jpg)
  2. I create annotations that are saved as a transparent png.
  3. Those annotations are "embedded" into the scans and the output is a png file.

All works well except if the images are PNG-8's. So, I don't know if this is possible, but could I convert a PNG-8 to a PNG-24 (or some other kind of PNG)?

I don't know much about PNG types, but according to http://www.fileformat.info, the metadata of a working image looks like this...

<javax_imageio_png_1.0>
<IHDR width="600" height="764" bitDepth="8" colorType="RGB" compressionMethod="deflate" filterMethod="adaptive" interlaceMethod="none"/>
<pHYs pixelsPerUnitXAxis="7874" pixelsPerUnitYAxis="7874" unitSpecifier="meter"/>
<tIME year="2013" month="4" day="25" hour="14" minute="9" second="17"/>
</javax_imageio_png_1.0>

And metadata from a failing image looks like this...

<javax_imageio_png_1.0>
<IHDR width="600" height="755" bitDepth="8" colorType="Grayscale" compressionMethod="deflate" filterMethod="adaptive" interlaceMethod="none"/>
<pHYs pixelsPerUnitXAxis="7874" pixelsPerUnitYAxis="7874" unitSpecifier="meter"/>
<tIME year="2013" month="4" day="23" hour="21" minute="10" second="33"/>
</javax_imageio_png_1.0>
  • 写回答

1条回答 默认 最新

  • doumaqing6652 2013-04-26 03:00
    关注

    PNG-8 refers to a PNG image with an indexed palette. It is almost always a smaller filesize, but is limited to 256 colours. PNG-24 is full-colour.

    The easiest way to convert a palette image to a full-colour one in PHP is like so:

    $src = imagecreatefrompng("my-indexed-image.png");
    $dst = imagecreatetruecolor($w=imagesx($src),$h=imagesy($src));
    imagecopy($dst,$src,0,0,0,0,$w,$h);
    imagedestroy($src);
    // now do stuff with $dst
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥60 求一个简单的网页(标签-安全|关键词-上传)
  • ¥35 lstm时间序列共享单车预测,loss值优化,参数优化算法
  • ¥15 基于卷积神经网络的声纹识别
  • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
  • ¥100 为什么这个恒流源电路不能恒流?
  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图