您的当前位置:首页>全部文章>文章详情

imagecreatefrompng(): '/path/img.png' is not a valid PNG file

发表于:2024-05-16 09:46:55浏览:172次TAG: #PHP #图片

引言

有时候我们的图片后缀明明是.png,调用imagecreatefrompng()方法时候却提示:is not a valid PNG file,比如我们使用微信自带的截图工具保存图片就会报这个错,如何解决这个问题呢?

解决

使用imagecreatefromstring()代替

原本调用

$img = imagecreatefrompng($filename);

替换成
$img = imagecreatefromstring(file_get_contents($filename))