Skip to content

Commit

Permalink
Merge pull request #105 from PauluzzNL/master
Browse files Browse the repository at this point in the history
Fix JpGraph memory leak issue with multiple graphs.
  • Loading branch information
ffflabs authored Apr 26, 2021
2 parents 85cce2b + d1be170 commit e36dc29
Showing 1 changed file with 12 additions and 5 deletions.
17 changes: 12 additions & 5 deletions src/image/Image.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,13 @@
use Amenadiel\JpGraph\Util;
use Amenadiel\JpGraph\Util\ErrMsgText;

// load fonts only once, and define a constant for them
define("GD_FF_FONT0", imageloadfont(dirname(dirname(__FILE__)) . '/fonts/FF_FONT0.gdf'));
define("GD_FF_FONT1", imageloadfont(dirname(dirname(__FILE__)) . '/fonts/FF_FONT1.gdf'));
define("GD_FF_FONT2", imageloadfont(dirname(dirname(__FILE__)) . '/fonts/FF_FONT2.gdf'));
define("GD_FF_FONT1_BOLD", imageloadfont(dirname(dirname(__FILE__)) . '/fonts/FF_FONT1-Bold.gdf'));
define("GD_FF_FONT2_BOLD", imageloadfont(dirname(dirname(__FILE__)) . '/fonts/FF_FONT2-Bold.gdf'));

/**
* File: GD_IMAGE.INC.PHP
* // Description: PHP Graph Plotting library. Low level image drawing routines
Expand Down Expand Up @@ -101,11 +108,11 @@ public function __construct($aWidth = 0, $aHeight = 0, $aFormat = DEFAULT_GFORMA
$this->ttf = new TTF();
$this->langconv = new LanguageConv();

$this->ff_font0 = imageloadfont(dirname(dirname(__FILE__)) . '/fonts/FF_FONT0.gdf');
$this->ff_font1 = imageloadfont(dirname(dirname(__FILE__)) . '/fonts/FF_FONT1.gdf');
$this->ff_font2 = imageloadfont(dirname(dirname(__FILE__)) . '/fonts/FF_FONT2.gdf');
$this->ff_font1_bold = imageloadfont(dirname(dirname(__FILE__)) . '/fonts/FF_FONT1-Bold.gdf');
$this->ff_font2_bold = imageloadfont(dirname(dirname(__FILE__)) . '/fonts/FF_FONT2-Bold.gdf');
$this->ff_font0 = GD_FF_FONT0;
$this->ff_font1 = GD_FF_FONT1;
$this->ff_font2 = GD_FF_FONT2;
$this->ff_font1_bold = GD_FF_FONT1_BOLD;
$this->ff_font2_bold = GD_FF_FONT2_BOLD;
}

// Enable interlacing in images
Expand Down

0 comments on commit e36dc29

Please sign in to comment.