dousuize3082 2017-04-27 07:50
浏览 6

将HTML添加到图像并使用php下载

I am trying to add following HTML table to an image and then download it as an .jpg file but instead it giving me white image which is given in $dir. Please have a look and guide what i am missing or what is wrong with this code

$dir = "../images/white.jpg";

$text = "tableHTML";
imagettftext($dir, 20, 0, 10, 20, $text);

imagepng($dir);
//$name = './img/ok.png';
header('Pragma: public');
header('Cache-Control: public, no-cache');
header('Content-Type: application/octet-stream');
header('Content-Length: ' . filesize($dir));
header('Content-Disposition: attachment; filename="' . basename($dir) . '"');
header('Content-Transfer-Encoding: binary');

readfile($dir);

the output image.jpg would be like this

Sr # | ID    | Bar Code  | Notes
1    | 1261  | ||||||||  | Test
2    | 6781  | ||||||||  | test 
3    | 8895  | ||||||||  | test 
4    | 5578  | ||||||||  | test 
5    | 1123  | ||||||||  | test 

*test data

  • 写回答

2条回答 默认 最新

  • 普通网友 2017-04-27 07:56
    关注

    You're missing one parameter. Following the documentation -> http://php.net/manual/en/function.imagettftext.php

    imagettftext ( resource $image , float $size , float $angle , int $x , int $y , int $color , string $fontfile , string $text )

    you're using

    imagettftext((image)$dir, (size)20, (angle)0, (x)10, (t)20, (color)$text);

    maybe you're missing the color before the text ;)

    评论

报告相同问题?

悬赏问题

  • ¥15 微信公众平台自制会员卡可以通过收款码收款码收款进行自动积分吗
  • ¥15 随身WiFi网络灯亮但是没有网络,如何解决?
  • ¥15 gdf格式的脑电数据如何处理matlab
  • ¥20 重新写的代码替换了之后运行hbuliderx就这样了
  • ¥100 监控抖音用户作品更新可以微信公众号提醒
  • ¥15 UE5 如何可以不渲染HDRIBackdrop背景
  • ¥70 2048小游戏毕设项目
  • ¥20 mysql架构,按照姓名分表
  • ¥15 MATLAB实现区间[a,b]上的Gauss-Legendre积分
  • ¥15 delphi webbrowser组件网页下拉菜单自动选择问题