📄 jpgraph.php
字号:
<?php//=======================================================================// File: JPGRAPH.PHP// Description: PHP Graph Plotting library. Base module.// Created: 2001-01-08// Author: Johan Persson (johanp@aditus.nu)// Ver: $Id: jpgraph.php,v 1.9.10.2 2006/03/18 15:09:32 gregorerhardt Exp $//// Copyright (c) Aditus Consulting. All rights reserved.//========================================================================require_once('jpg-config.inc');// Version infoDEFINE('JPG_VERSION','1.20.3');// For internal use onlyDEFINE("_JPG_DEBUG",false);DEFINE("_FORCE_IMGTOFILE",false);DEFINE("_FORCE_IMGDIR",'/tmp/jpgimg/');//------------------------------------------------------------------------// Automatic settings of path for cache and font directory// if they have not been previously specified//------------------------------------------------------------------------if(USE_CACHE) { if (!defined('CACHE_DIR')) { if ( strstr( PHP_OS, 'WIN') ) { if( empty($_SERVER['TEMP']) ) { $t = new ErrMsgText(); $msg = $t->Get(11,$file,$lineno); die($msg); } else { DEFINE('CACHE_DIR', $_SERVER['TEMP'] . '/'); } } else { DEFINE('CACHE_DIR','/tmp/jpgraph_cache/'); } }}elseif( !defined('CACHE_DIR') ) { DEFINE('CACHE_DIR', '');}if (!defined('TTF_DIR')) { if (strstr( PHP_OS, 'WIN') ) { $sroot = getenv('SystemRoot'); if( empty($sroot) ) { $t = new ErrMsgText(); $msg = $t->Get(12,$file,$lineno); die($msg); } else { DEFINE('TTF_DIR', $sroot.'/fonts/'); } } else { DEFINE('TTF_DIR','/usr/X11R6/lib/X11/fonts/truetype/'); }}//------------------------------------------------------------------// Constants which are used as parameters for the method calls//------------------------------------------------------------------// TTF Font familiesDEFINE("FF_COURIER",10);DEFINE("FF_VERDANA",11);DEFINE("FF_TIMES",12);DEFINE("FF_COMIC",14);DEFINE("FF_ARIAL",15);DEFINE("FF_GEORGIA",16);DEFINE("FF_TREBUCHE",17);// Gnome Vera font// Available from http://www.gnome.org/fonts/DEFINE("FF_VERA",19);DEFINE("FF_VERAMONO",20);DEFINE("FF_VERASERIF",21);// Chinese fontDEFINE("FF_SIMSUN",30);DEFINE("FF_CHINESE",31);DEFINE("FF_BIG5",31);// Japanese fontDEFINE("FF_MINCHO",40);DEFINE("FF_PMINCHO",41);DEFINE("FF_GOTHIC",42);DEFINE("FF_PGOTHIC",43);// Limits for TTF fontsDEFINE('_FF_FIRST',10);DEFINE('_FF_LAST',43);// Older deprecated fonts DEFINE("FF_BOOK",91); // Deprecated fonts from 1.9DEFINE("FF_HANDWRT",92); // Deprecated fonts from 1.9// TTF Font stylesDEFINE("FS_NORMAL",9001);DEFINE("FS_BOLD",9002);DEFINE("FS_ITALIC",9003);DEFINE("FS_BOLDIT",9004);DEFINE("FS_BOLDITALIC",9004);//Definitions for internal font, new styleDEFINE("FF_FONT0",1);DEFINE("FF_FONT1",2);DEFINE("FF_FONT2",4);// Tick densityDEFINE("TICKD_DENSE",1);DEFINE("TICKD_NORMAL",2);DEFINE("TICKD_SPARSE",3);DEFINE("TICKD_VERYSPARSE",4);// Side for ticks and labels. DEFINE("SIDE_LEFT",-1);DEFINE("SIDE_RIGHT",1);DEFINE("SIDE_DOWN",-1);DEFINE("SIDE_BOTTOM",-1);DEFINE("SIDE_UP",1);DEFINE("SIDE_TOP",1);// Legend type stacked vertical or horizontalDEFINE("LEGEND_VERT",0);DEFINE("LEGEND_HOR",1);// Mark types for plot marksDEFINE("MARK_SQUARE",1);DEFINE("MARK_UTRIANGLE",2);DEFINE("MARK_DTRIANGLE",3);DEFINE("MARK_DIAMOND",4);DEFINE("MARK_CIRCLE",5);DEFINE("MARK_FILLEDCIRCLE",6);DEFINE("MARK_CROSS",7);DEFINE("MARK_STAR",8);DEFINE("MARK_X",9);DEFINE("MARK_LEFTTRIANGLE",10);DEFINE("MARK_RIGHTTRIANGLE",11);DEFINE("MARK_FLASH",12);DEFINE("MARK_IMG",13);DEFINE("MARK_FLAG1",14);DEFINE("MARK_FLAG2",15);DEFINE("MARK_FLAG3",16);DEFINE("MARK_FLAG4",17);// Builtin imagesDEFINE("MARK_IMG_PUSHPIN",50);DEFINE("MARK_IMG_SPUSHPIN",50);DEFINE("MARK_IMG_LPUSHPIN",51);DEFINE("MARK_IMG_DIAMOND",52);DEFINE("MARK_IMG_SQUARE",53);DEFINE("MARK_IMG_STAR",54);DEFINE("MARK_IMG_BALL",55);DEFINE("MARK_IMG_SBALL",55);DEFINE("MARK_IMG_MBALL",56);DEFINE("MARK_IMG_LBALL",57);DEFINE("MARK_IMG_BEVEL",58);// Inline definesDEFINE("INLINE_YES",1);DEFINE("INLINE_NO",0);// Format for background imagesDEFINE("BGIMG_FILLPLOT",1);DEFINE("BGIMG_FILLFRAME",2);DEFINE("BGIMG_COPY",3);DEFINE("BGIMG_CENTER",4);// Depth of objectsDEFINE("DEPTH_BACK",0);DEFINE("DEPTH_FRONT",1);// DirectionDEFINE("VERTICAL",1);DEFINE("HORIZONTAL",0);// Axis styles for scientific style axisDEFINE('AXSTYLE_SIMPLE',1);DEFINE('AXSTYLE_BOXIN',2);DEFINE('AXSTYLE_BOXOUT',3);DEFINE('AXSTYLE_YBOXIN',4);DEFINE('AXSTYLE_YBOXOUT',5);// Style for title backgroundsDEFINE('TITLEBKG_STYLE1',1);DEFINE('TITLEBKG_STYLE2',2);DEFINE('TITLEBKG_STYLE3',3);DEFINE('TITLEBKG_FRAME_NONE',0);DEFINE('TITLEBKG_FRAME_FULL',1);DEFINE('TITLEBKG_FRAME_BOTTOM',2);DEFINE('TITLEBKG_FRAME_BEVEL',3);DEFINE('TITLEBKG_FILLSTYLE_HSTRIPED',1);DEFINE('TITLEBKG_FILLSTYLE_VSTRIPED',2);DEFINE('TITLEBKG_FILLSTYLE_SOLID',3);// Style for background gradient fillsDEFINE('BGRAD_FRAME',1);DEFINE('BGRAD_MARGIN',2);DEFINE('BGRAD_PLOT',3);// Width of tab titlesDEFINE('TABTITLE_WIDTHFIT',0);DEFINE('TABTITLE_WIDTHFULL',-1);// Defines for 3D skew directionsDEFINE('SKEW3D_UP',0);DEFINE('SKEW3D_DOWN',1);DEFINE('SKEW3D_LEFT',2);DEFINE('SKEW3D_RIGHT',3);//// Get hold of gradient class (In Version 2.x)// A client of the library has to manually include this//require_once 'jpgraph_gradient.php';class ErrMsgText { var $lt=NULL; var $supportedLocales = array('en'); function ErrMsgText() { GLOBAL $__jpg_err_locale; if( !in_array($__jpg_err_locale,$this->supportedLocales) ) $aLoc = 'en'; require_once('lang/'.$__jpg_err_locale.'.inc.php'); $this->lt = $_jpg_messages; } function Get($errnbr,$a1=null,$a2=null,$a3=null,$a4=null,$a5=null) { if( !isset($this->lt[$errnbr]) ) { return 'Internal error: The specified error message does not exist in the chosen locale. (Please blame the translator...))'; } $ea = $this->lt[$errnbr]; $j=0; if( $a1 !== null ) { $argv[$j++] = $a1; if( $a2 !== null ) { $argv[$j++] = $a2; if( $a3 !== null ) { $argv[$j++] = $a3; if( $a4 !== null ) { $argv[$j++] = $a4; if( $a5 !== null ) { $argv[$j++] = $a5; } } } } } $numargs = $j; if( $ea[1] != $numargs ) { // Error message argument count do not match. // Just return the error message without arguments. return $ea[0]; } switch( $numargs ) { case 1: $msg = sprintf($ea[0],$argv[0]); break; case 2: $msg = sprintf($ea[0],$argv[0],$argv[1]); break; case 3: $msg = sprintf($ea[0],$argv[0],$argv[1],$argv[2]); break; case 4: $msg = sprintf($ea[0],$argv[0],$argv[1],$argv[2],$argv[3]); break; case 5: $msg = sprintf($ea[0],$argv[0],$argv[1],$argv[2],$argv[3],$argv[4]); break; case 0: default: $msg = sprintf($ea[0]); break; } return $msg; }}//// A wrapper class that is used to access the specified error object// (to hide the global error parameter and avoid having a GLOBAL directive// in all methods.//GLOBAL $__jpg_err;GLOBAL $__jpg_err_locale ;$__jpg_err_locale = 'en';class JpGraphError { function Install($aErrObject) { GLOBAL $__jpg_err; $__jpg_err = $aErrObject; } function Raise($aMsg,$aHalt=true){ GLOBAL $__jpg_err; $tmp = new $__jpg_err; $tmp->Raise($aMsg,$aHalt); } function RaiseL($errnbr,$a1=null,$a2=null,$a3=null,$a4=null,$a5=null) { GLOBAL $__jpg_err; $t = new ErrMsgText(); $msg = $t->Get($errnbr,$a1,$a2,$a3,$a4,$a5); $tmp = new $__jpg_err; $tmp->Raise($msg); }} //// ... and install the default error handler//if( USE_IMAGE_ERROR_HANDLER ) { $__jpg_err = "JpGraphErrObjectImg";}else { $__jpg_err = "JpGraphErrObject"; }//// Make GD sanity check//if( !function_exists("imagetypes") || !function_exists('imagecreatefromstring') ) { JpGraphError::RaiseL(25001);//("This PHP installation is not configured with the GD library. Please recompile PHP with GD support to run JpGraph. (Neither function imagetypes() nor imagecreatefromstring() does exist)");}//// Routine to determine if GD1 or GD2 is installed//function CheckGDVersion() { $GDfuncList = get_extension_funcs('gd'); if( !$GDfuncList ) return 0 ; else { if( in_array('imagegd2',$GDfuncList) && in_array('imagecreatetruecolor',$GDfuncList)) return 2; else return 1; } }//// Check what version of the GD library is installed.//$GLOBALS['gd2'] = false;if( USE_LIBRARY_GD2 === 'auto' ) { $gdversion = CheckGDVersion(); if( $gdversion == 2 ) { $GLOBALS['gd2'] = true; $GLOBALS['copyfunc'] = 'imagecopyresampled'; } elseif( $gdversion == 1 ) { $GLOBALS['gd2'] = false; $GLOBALS['copyfunc'] = 'imagecopyresized'; } else { JpGraphError::RaiseL(25002);//(" Your PHP installation does not seem to have the required GD library. Please see the PHP documentation on how to install and enable the GD library."); }}else { $GLOBALS['gd2'] = USE_LIBRARY_GD2; $GLOBALS['copyfunc'] = USE_LIBRARY_GD2 ? 'imagecopyresampled' : 'imagecopyresized';}//// First of all set up a default error handler////=============================================================// The default trivial text error handler.//=============================================================class JpGraphErrObject { var $iTitle = "JpGraph Error"; var $iDest = false; function JpGraphErrObject() { // Empty. Reserved for future use } function SetTitle($aTitle) { $this->iTitle = $aTitle; } function SetStrokeDest($aDest) { $this->iDest = $aDest; } // If aHalt is true then execution can't continue. Typical used for fatal errors. function Raise($aMsg,$aHalt=true) { $aMsg = $this->iTitle.' '.$aMsg; if ($this->iDest) { $f = @fopen($this->iDest,'a'); if( $f ) { @fwrite($f,$aMsg); @fclose($f); } } else { echo $aMsg; } if( $aHalt ) die(); }}//==============================================================// An image based error handler//==============================================================class JpGraphErrObjectImg extends JpGraphErrObject { function Raise($aMsg,$aHalt=true) { $img_iconerror = 'iVBORw0KGgoAAAANSUhEUgAAACgAAAAoCAMAAAC7IEhfAAAAaV'. 'BMVEX//////2Xy8mLl5V/Z2VvMzFi/v1WyslKlpU+ZmUyMjEh/'. 'f0VyckJlZT9YWDxMTDjAwMDy8sLl5bnY2K/MzKW/v5yyspKlpY'. 'iYmH+MjHY/PzV/f2xycmJlZVlZWU9MTEXY2Ms/PzwyMjLFTjea'.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -