I am using gd-text to add a text from Database to an Image.
Both (image/text) are generated by an external class.
Heres the code:
<?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');
Following lines are for direct download and commented out as I try to figure out, why no text is added.
// header("Content-Disposition: attachment; filename=\"motivation_" . $date . ".jpg\";");
// header('Content-Type: image/jpeg');
The image is created with no text added. $slogan_txt['en'] is filled with the correct value. Also, x/y-coordinates are calculated as they should.
There is no error in PHP or apache log on the server.
Did I miss something? I took the code from a script I did a few months ago and it worked well as I remember.
Any help/hint is appreciated! thanks!