PHP GD issues with ImageCreateTrueColor and PNGs

后端 未结 1 943
Happy的楠姐
Happy的楠姐 2021-01-24 03:53

I am resizing PNG images using the GD image library function ImageCopyResampled(). It all works fine, I can even keep alpha blending transparency with the use of ImageCreateTrue

1条回答
  •  执笔经年
    2021-01-24 04:15

    With imagecreate() you're creating an indexed-color PNG file and with imagecreatetruecolor() you're creating a 24-bit color PNG file. Of course the resampling quality is going to appear much better with the true color image, since it has a much larger range of colors to use when resampling. With imagecreate(), the system can only use the much smaller palette.

    You can try this out using Photoshop or Gimp, scaling images in the different color modes (indexed and RGB). Unfortunately it's the nature of the game-- the file size will be larger when there are more colors to store.

    I'm not sure if it would make a difference, but you could try using imagecopyresampled() to copy to a true-color resource (from imagecreatetruecolor()), then copy (but not resample) that to a palette image resource. This way the palette is determined based on the resampled result. I'm not sure that you'd be able to retain the alpha channel, though.

    0 讨论(0)
提交回复
热议问题