Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix JpGraph memory leak issue with multiple graphs. #105

Merged
merged 1 commit into from
Apr 26, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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