I posted this as a reply yesterday, but looking further I believe this is actually a couple of bugs at least, but I just can't figure out why.
jpgraph 4.3.1
The error manifests itself like this:
JpGraph Error: 25092 There is either a configuration problem with TrueType or a problem reading font file "/home/e-smith/files/ibays/testbay/html/graphs-test/jpgraph/fonts/DejaVuSans.ttf" Make sure file exists and is in a readable place for the HTTP process. (If 'basedir' restriction is enabled in PHP then the font file must be located in the document root.). It might also be a wrongly installed FreeType library. Try upgrading to at least FreeType 2.1.13 and recompile GD with the correct setup so it can find the new FT library.
However, this is completely wrong and NOT the real reason for failure, at least in this case.
I added some test code and it appears the font file is found, but the $text value that it tries to stroke is empty so this returns a 0
$bbox = @imagettfbbox($size, 0, $fontfile, $text);
We can test his by just adding a simple test to jd_image.inc.php
All it does is check if there is a $text value and if there isn't, make the font is actually readable
diff -ruN gd_image.inc.orig gd_image.inc.php
--- gd_image.inc.orig 2020-04-24 05:51:05.000000000 +0200
+++ gd_image.inc.php 2020-04-29 11:55:48.084999064 +0200
@@ -733,6 +733,13 @@
// The built in imagettfbbox is buggy for angles != 0 so
// we calculate this manually by getting the bounding box at
// angle = 0 and then rotate the bounding box manually
+ if ($text == "") {
+ if( is_readable($this->font_file) ) {
+ echo "Font File found >>>>> " . $this->font_file ."<br />";
+ echo "No text <br />";
+ //die();
+ }
+ }
$bbox = @imagettfbbox($size, 0, $fontfile, $text);
if( $bbox === false ) {
JpGraphError::RaiseL(25092,$this->font_file);
And we get this
Font File found >>>>> /home/e-smith/files/ibays/testbay/html/graphs-test/jpgraph/fonts/DejaVuSans.ttf
No text
JpGraph Error: 25092 There is either a configuration problem with TrueType or a problem reading font file "/home/e-smith/files/ibays/testbay/html/graphs-test/jpgraph/fonts/DejaVuSans.ttf" Make sure file exists and is in a readable place for the HTTP process. (If 'basedir' restriction is enabled in PHP then the font file must be located in the document root.). It might also be a wrongly installed FreeType library. Try upgrading to at least FreeType 2.1.13 and recompile GD with the correct setup so it can find the new FT library.
But that still isn't really correct - we should never get there. It should fail in the phperrroHandler (see further below when I found this)
Here is the simple example0.php file with the addition of Titles to test.
<?php // content="text/plain; charset=utf-8"
require_once ('jpgraph/jpgraph.php');
require_once ('jpgraph/jpgraph_line.php');
// Some data
$ydata = array(11,3,8,12,5,1,9,13,5,7);
// Create the graph. These two calls are always required
$graph = new Graph(350,250);
$graph->SetScale('textlin');
// Create the linear plot
$lineplot=new LinePlot($ydata);
$lineplot->SetColor('blue');
// Add the plot to the graph
$graph->Add($lineplot);
$graph->title->Set('The Title');
$graph->xaxis->title->Set('USERS');
$graph->yaxis->title->Set('CASH');
// Display the graph
$graph->Stroke();
?>
Note that the missing font error is really misleading - there is error code earlier that would catch a font missing error and so the code should never get to this point.
eg at 822 function GetBBoxTTF($aTxt,$aAngle=0) checks for the font file and it should stop execution here is a font file is not found.
if( !is_readable($this->font_file) ) {
JpGraphError::RaiseL(25093,$this->font_file);
I then noticed that when the $bbox line fails it goes to the PHP handler here. But this fails to execute because it doesn't detect error_reporting being set n the example0.php file
function _phpErrorHandler($errno,$errmsg,$filename, $linenum, $vars) {
// Respect current error level
if( $errno & error_reporting() ) {
JpGraphError::RaiseL(25003,basename($filename),$linenum,$errmsg);
}
}
First it should be double && not single :
if( $errno && error_reporting() ) {
But that still doesn't pickup error_reporting being set unless you do it via PHP ini (there should be a debug on/off for this sort of thing)
So if I temporarily add error_reporting(-1) we then get the real error:
function _phpErrorHandler($errno,$errmsg,$filename, $linenum, $vars) {
// Respect current error level
error_reporting (-1)
if( $errno & error_reporting() ) {
JpGraphError::RaiseL(25003,basename($filename),$linenum,$errmsg);
}
}
And voila !! The correct error:
Err 2
imagettfbbox(): Problem doing text layout
I think the phpErrorHandling should NOT have the error_reporting check set so it always throws an error if detected.
The missing font line should ONLY be called if the font file is actually missing, though that should have been picked up earlier.
I still have no idea why it tries to Stroke and empty var, but at least this is the real error.
==================================================
Some general notes on my setup from my post yesterday.
checkttf.php - works
checkgd.php - works
checkgd2.php - works
testsuit.php
Works:
antispamex01.php
ledex*
ledex_cyrillic.php
ledex_cyrillic2.php
I also added a non Cyrillic text version and that works too.
phpinfo
PHP 7.2.29
GD Support enabled
GD headers Version 2.2.5
GD library Version 2.3.0
FreeType Support enabled
FreeType Linkage with freetype
FreeType Version 2.3.11
GIF Read Support enabled
GIF Create Support enabled
JPEG Support enabled
libJPEG Version 6b
PNG Support enabled
libPNG Version 1.2.49
WBMP Support enabled
XPM Support enabled
libXpm Version 30411
XBM Support enabled
WebP Support enabled
Directive Local Value Master Value
gd.jpeg_ignore_warning 1