一张图片加些文字后生成新的图片 imagepng输出展示的时候不正确?

// 基本参数
$font = './Upload/fonts/hanyishengongtijian.ttf';//字体
$img = imagecreatefromstring(file_get_contents($img_path));
$black = imagecolorallocate($img, 224, 193, 68);//字体颜色 RGB
$fontSize = 20;   //字体大小
$left = 140;      //左边距
$top = 177;       //顶边距

$string = '不成功 很难过 求帮助';
imagefttext ($img, $fontSize, 0, $left, $top, $black, $font, $string);

$string = 'NO:88888';
imagefttext ($img, $fontSize, 0, $num_left, $num_top, $black, $font, $string);

$create_img_path = './Upload/cart/user_cart'.222.'.png';

Header("Content-type: image/png");
imagepng($img,$create_img_path);
imagedestroy($img);

clipboard.png
最后的结果是这样的 但是我保存到本地的图片是正常的 我拿本地的图片上传到第三方 打开也是不行的 是不是字体的原因啊?有木有知道的大神求教

阅读 5.4k
2 个回答

你可以这样子测试,加水印都注释掉,就载入图片,设置背景色,输出图片,就这几个执行看看。我猜测,应该图片载入的时候失败了

把Header("Content-type: image/png");这行注释掉看看,看看有咩有报错

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题