gd-text:没有添加文本
gd-text: no text is added
我正在使用 gd-text 将文本从数据库添加到图像。
两者 (image/text) 都是由外部生成的 class。
代码如下:
<?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-coordinates 是按应有的方式计算的。
PHP 或服务器上的 apache 日志没有错误。
我错过了什么吗?我从几个月前编写的脚本中获取了代码,它在我记忆中运行良好。
任何 help/hint 不胜感激!谢谢!
我不太清楚为什么,但是将 "font.ttf" 从 775 设置为 777 对我有用...
我正在使用 gd-text 将文本从数据库添加到图像。
两者 (image/text) 都是由外部生成的 class。
代码如下:
<?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-coordinates 是按应有的方式计算的。
PHP 或服务器上的 apache 日志没有错误。
我错过了什么吗?我从几个月前编写的脚本中获取了代码,它在我记忆中运行良好。
任何 help/hint 不胜感激!谢谢!
我不太清楚为什么,但是将 "font.ttf" 从 775 设置为 777 对我有用...