Jpgraph image brokeing

577 views
Skip to first unread message

Dileep c

unread,
Apr 23, 2020, 5:27:54 AM4/23/20
to JpGraph
There is either a configuration problem with TrueType or a problem reading font file "/var/www/xxxxx/public_html/vendor/amenadiel/jpgraph/src/fonts/DejaVuSans-Bold.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.

John Crisp

unread,
Apr 28, 2020, 12:06:41 PM4/28/20
to JpGraph
I have had the same issue since updating recently from 3.x to 4.3.1 and have been trying to debug it. 

Graphs I have used for years seemed to have broken overnight.

It ISN'T because the font file is missing. That error is totally misleading. My font files are in a subdirectory of the jpgraph directory. I can see the code checks for the existence of the font file and that is all OK.

If there was an open basedir error my server would tell me. So it isn't that.

For some reason it seems to fall over trying to stroke a non existent text value.

I have seen it happen over and over but can't get my head round why.

Running a test with example0.php

Here's where it fails when I step debug it



        // 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

        $bbox = @imagettfbbox($size, 0, $fontfile, $text);

        if( $bbox === false ) {

            JpGraphError::RaiseL(25092,$this->font_file);


You can see in the screen shot that the value of $text is not set.

Any help gratefully received - I have wasted hours trying to figure this out and still don't understand.


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


Screenshot_2020-04-28_17-53-37.png


Gavin D

unread,
Apr 29, 2020, 6:21:19 AM4/29/20
to JpGraph
gdImageStringFT() fails for empty strings as of libgd 2.3.0.

All you need to do is add blank string checks around ImageTTFText like as I've done in my fork of the codebase.


Surely this will be patched really soon.

John Crisp

unread,
Apr 29, 2020, 7:33:26 AM4/29/20
to JpGraph
Blimey - that fixed thanks.

This has been driving me insane.

There should be better error checking anyway - see my main post where I identified an issue with the php error handling.

The error handling should have identified the empty string - that would at least have helped.

Also, it doesn't explain why it is trying to stroke a non existent value ? Surely that should be picked up, but i can't see where?

John Crisp

unread,
Apr 29, 2020, 7:58:34 AM4/29/20
to JpGraph
Ahhh - got it.

I have empty/unset SubTitle and SubSubTitle and TabTitle

So these probably all need a 

if ne "" 


        // ... and subtitle
        $y += $this->title->GetTextHeight($this->img) + $margin + $this->subtitle->margin;
        if( $this->subtitle->halign == 'center' ) {
            $this->subtitle->Center(0,$this->img->width,$y);
        }
        elseif( $this->subtitle->halign == 'left' ) {
            $this->subtitle->SetPos($this->subtitle->margin+2,$y);
        }
        elseif( $this->subtitle->halign == 'right' ) {
            $indent = 0;
            if( $this->doshadow )
            $indent = $this->shadow_width+2;
            $this->subtitle->SetPos($this->img->width-$this->subtitle->margin-$indent,$y,'right');
        }
        $this->subtitle->Stroke($this->img);

        // ... and subsubtitle
        $y += $this->subtitle->GetTextHeight($this->img) + $margin + $this->subsubtitle->margin;
        if( $this->subsubtitle->halign == 'center' ) {
            $this->subsubtitle->Center(0,$this->img->width,$y);
        }
        elseif( $this->subsubtitle->halign == 'left' ) {
            $this->subsubtitle->SetPos($this->subsubtitle->margin+2,$y);
        }
        elseif( $this->subsubtitle->halign == 'right' ) {
            $indent = 0;
            if( $this->doshadow )
            $indent = $this->shadow_width+2;
            $this->subsubtitle->SetPos($this->img->width-$this->subsubtitle->margin-$indent,$y,'right');
        }
        $this->subsubtitle->Stroke($this->img);

        // ... and fancy title
        $this->tabtitle->Stroke($this->img);


Ralph Höglund

unread,
May 3, 2020, 9:12:32 AM5/3/20
to JpGraph
Thank you for the fix, saved many hours for me!

Ralph Höglund

unread,
May 3, 2020, 9:13:38 AM5/3/20
to JpGraph

MBL

unread,
Jun 1, 2020, 1:01:01 AM6/1/20
to JpGraph
This patch worked for me as well. Many Thanks for sharing..

Alejandro Márquez

unread,
Jun 17, 2020, 3:39:38 PM6/17/20
to JpGraph
Works for me too, the error ocurred when migrate to Centos 7 with PHP 7.4.6, thanks
Reply all
Reply to author
Forward
0 new messages