我目前遇到了一个关于fpdf的非常奇怪的问题。我在stackoverflow上找到了一个相似的问题,但没有答案:not a PNG file in FPDF。我将一张图片通过浏览器上传到我的文件服务器,然后将其引入fpdf报表中。当这张图片是png格式时,我会收到错误信息:"FPDF error: Not a PNG file"。而当上传的图片是jpg格式时,就不会出现任何错误。这个问题似乎是几周前突然出现的。
更奇怪的是,这只会出现在新上传的png图片上。有一张png图片在报表中生成得很好。当我从系统中下载这张png并重新上传时,错误就再次出现了。
以下是我尝试解决这个问题时采取的一些步骤:
- I've made sure the image is actually a png (through its properties).
Nothing has changed with the way I've been saving the images, but here's the code:
$original = $time."_".$name."_o.".$extension; $thumbnail = $time."_".$name."_t.".$extension; include('SimpleImage.php'); $image = new SimpleImage(); $image->load($_FILES['file']['tmp_name']); $image->save($A_path."images/".$original); $image->resizeToHeight(200); $image->save($A_path."images/thumbs/".$thumbnail); $photo = "images/".$original; $thumb = "images/thumbs/".$thumbnail;
- I've checked to see if their were any changes to the PNG format or FPDF updates, with no luck.
- I've converted a jpg that works into a png through gimp.
- Converting a png to a jpg through gimp and then uploading the jpg to the system does not generate any errors.
解决方式- 我已经在保存时将PNG转换为JPG,而不是重新编码图像。感谢您的帮助。