【问题标题】:gd-text: no text is addedgd-text:不添加文本
【发布时间】:2016-11-07 05:07:56
【问题描述】:

我正在使用 gd-text 将文本从数据库添加到图像。

两者(图像/文本)均由外部类生成。

代码如下:

<?php

//Includes
include 'gdtext/Color.php';
include 'gdtext/Box.php';

include 'class.getSlogan.php';
include 'class.getImage.php';

use GDText\Box;
use GDText\Color;

//Date
$timestamp = time();
$date = date("d.m.Y", $timestamp);


$slogan_txt = dailySlogan();
$img = dailyImage();

//Set Imagepath
$imgPath = '../../images/output/1500_' .$img['imageName'];


//Create Image
$im = imagecreatefromjpeg($imgPath);

//Get X/Y for Box
$image_width = imagesx($im);  
$image_height  = imagesy($im);
$y = ($image_height / 2 );
$max_x = ($image_width / 2 );
$start = ($max_x / 2);


//Generate Text
$box = new Box($im);
$box->setFontFace('font.TTF'); 
$box->setFontSize(60);
$box->setFontColor(new Color(255, 255, 255));
$box->setTextShadow(new Color(0, 0, 0, 50), 0, -2);
$box->setBox($start, $y, $max_x, 0);
$box->setTextAlign('center', 'center');
$box->draw($slogan_txt['en']);

// header("Content-Disposition: attachment; filename=\"motivation_" . $date . ".jpg\";");
// header('Content-Type: image/jpeg');

//Save
imagejpeg($im, 'test.jpg');

以下几行用于直接下载,并在我试图弄清楚为什么没有添加文本时被注释掉。

// header("Content-Disposition: attachment; filename=\"motivation_" . $date . ".jpg\";");
// header('Content-Type: image/jpeg');

创建的图像没有添加任何文字。 $slogan_txt['en'] 填充了正确的值。此外,x/y 坐标也会按应有的方式计算。

服务器上的PHP或apache日志没有错误。

我错过了什么吗?我从几个月前编写的脚本中提取了代码,我记得它运行良好。

感谢任何帮助/提示!谢谢!

【问题讨论】:

  • 编辑:在我的本地机器上它可以工作。在 Ubuntu Server (14.04) 上它没有。相同的脚本。

标签: php gd imagejpeg


【解决方案1】:

我不太清楚为什么,但是将“font.ttf”从 775 设置为 777 对我有用...

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2019-03-23
    • 1970-01-01
    • 2012-10-27
    • 2013-10-16
    • 2022-12-14
    • 1970-01-01
    相关资源
    最近更新 更多