How to check a PNG for grayscale/alpha color type?

前端 未结 3 1317
旧时难觅i
旧时难觅i 2021-01-12 09:07

PHP and GD seem to have trouble creating images from PNGs of type greyscale with alpha when using imagecreatefrompng(). The results are incredibly distorted.

3条回答
  •  挽巷
    挽巷 (楼主)
    2021-01-12 09:47

    see this answer :

    Another usefull note for those using ImageCreateFromPng: PHP and GD do not recognize grayscale/alpha images.

    So if you use grayscale images with transparency between 0% and 100%, then save the image as RGB.

    At least this is true for PHP Version 4.4.2-1 and in 5.1.2-1 with pictures made with GIMP 2.2.8.

    url : http://php.net/manual/en/function.imagecreatefrompng.php

提交回复
热议问题