解决FPDF报错:FPDF error: Not a JPEG file / FPDF error: Not a PNG file

最近有个项目需要用到FPDF,但是输出的时候报错:

FPDF error: Not a JPEG file: http://***/data/attachment/forum/201603/19/105428nzhz6z9eh6qyyiw8.jpg

 找到报错的代码:

 

用到了getimagesize函数来做判断,那就简单试下:

<?php
/**
 * User: Administrator
 * Date: 2016/3/22 11:54
 */
header("Content-type: text/html; charset=utf-8");

$a = getimagesize('105428nzhz6z9eh6qyyiw8.jpg');
var_dump($a);

结果如下:

array (size=6)
  0 => int 282
  1 => int 500
  2 => int 3
  3 => string 'width="282" height="500"' (length=24)
  'bits' => int 8
  'mime' => string 'image/png' (length=9)

 

发现了比较奇怪的现象:后缀为jpg,但是mime的结果却是image/png!!!!

 

发现问题就比较好解决了,由于我的图片是其他地方用到的,那就是复制个105428nzhz6z9eh6qyyiw8.jpg到105428nzhz6z9eh6qyyiw8.png即可,试了下,完美解决!

附上代码:

$imgurl=$imgtemp['attachment'];
$imgtype = substr($imgurl,strrpos($imgurl,'.')+1);
$a = getimagesize('../data/attachment/forum/'.$imgurl);
$mime =str_replace('jpeg','jpg', str_replace('image/','',$a['mime']));
if($imgtype != $mime){
  $imgurl_new = '/data/attachment/forum/'.str_replace($imgtype,$mime,$imgurl);
  if(!is_dir($imgurl_new)){
    $jpg = '/data/attachment/forum/'.$imgurl;
    $topng = copy('..'.$jpg,'..'.$imgurl_new);
    $imgurl = str_replace('/data/attachment/forum/','',$imgurl_new);
  }
}
$mypath="http://$baseurl/data/attachment/forum/".$imgurl;

$pdf->Image(''.$mypath.'');

 

转载于:https://www.cnblogs.com/pthlp/p/5305790.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值