iWidth = $aWidth; $this->iHeight = $aHeight; } // Specify background fill color for the combined graph function SetFillColor($aColor) { $this->iFillColor = $aColor; } // Add a frame around the combined graph function SetFrame($aFlg,$aColor='black',$aWeight=1) { $this->iDoFrame = $aFlg; $this->iFrameColor = $aColor; $this->iFrameWeight = $aWeight; } // Specify a background image blend function SetBackgroundImageMix($aMix) { $this->background_image_mix = $aMix ; } // Specify a background image function SetBackgroundImage($aFileName,$aCenter_aX=NULL,$aY=NULL) { // Second argument can be either a boolean value or // a numeric $aCenter=TRUE; $aX=NULL; if( $GLOBALS['gd2'] && !USE_TRUECOLOR ) { JpGraphError::RaiseL(12001); //("You are using GD 2.x and are trying to use a background images on a non truecolor image. To use background images with GD 2.x you must enable truecolor by setting the USE_TRUECOLOR constant to TRUE. Due to a bug in GD 2.0.1 using any truetype fonts with truecolor images will result in very poor quality fonts."); } if( is_numeric($aCenter_aX) ) { $aX=$aCenter_aX; } // Get extension to determine image type $e = explode('.',$aFileName); if( !$e ) { JpGraphError::RaiseL(12002,$aFileName); //('Incorrect file name for MGraph::SetBackgroundImage() : '.$aFileName.' Must have a valid image extension (jpg,gif,png) when using autodetection of image type'); } $valid_formats = array('png', 'jpg', 'gif'); $aImgFormat = strtolower($e[count($e)-1]); if ($aImgFormat == 'jpeg') { $aImgFormat = 'jpg'; } elseif (!in_array($aImgFormat, $valid_formats) ) { JpGraphError::RaiseL(12003,$aImgFormat,$aFileName); //('Unknown file extension ($aImgFormat) in MGraph::SetBackgroundImage() for filename: '.$aFileName); } $this->background_image = $aFileName; $this->background_image_center=$aCenter; $this->background_image_format=$aImgFormat; $this->background_image_x = $aX; $this->background_image_y = $aY; } // Private helper function for backgound image function _loadBkgImage($aFile='') { if( $aFile == '' ) $aFile = $this->background_image; // Remove case sensitivity and setup appropriate function to create image // Get file extension. This should be the LAST '.' separated part of the filename $e = explode('.',$aFile); $ext = strtolower($e[count($e)-1]); if ($ext == "jpeg") { $ext = "jpg"; } if( trim($ext) == '' ) $ext = 'png'; // Assume PNG if no extension specified $supported = imagetypes(); if( ( $ext == 'jpg' && !($supported & IMG_JPG) ) || ( $ext == 'gif' && !($supported & IMG_GIF) ) || ( $ext == 'png' && !($supported & IMG_PNG) ) ) { JpGraphError::RaiseL(12004,$aFile);//('The image format of your background image ('.$aFile.') is not supported in your system configuration. '); } if( $ext == "jpg" || $ext == "jpeg") { $f = "imagecreatefromjpeg"; $ext = "jpg"; } else { $f = "imagecreatefrom".$ext; } $img = @$f($aFile); if( !$img ) { JpGraphError::RaiseL(12005,$aFile); //(" Can't read background image: '".$aFile."'"); } return $img; } function _strokeBackgroundImage() { if( $this->background_image == '' ) return; $bkgimg = $this->_loadBkgImage(); // Background width & Heoght $bw = imagesx($bkgimg); $bh = imagesy($bkgimg); // Canvas width and height $cw = imagesx($this->img); $ch = imagesy($this->img); if( $this->background_image_x === NULL || $this->background_image_y === NULL ) { if( $this->background_image_center ) { // Center original image in the plot area $x = round($cw/2-$bw/2); $y = round($ch/2-$bh/2); } else { // Just copy the image from left corner, no resizing $x=0; $y=0; } } else { $x = $this->background_image_x; $y = $this->background_image_y; } $this->_imageCp($bkgimg,$x,$y,0,0,$bw,$bh,$this->background_image_mix); } function _imageCp($aSrcImg,$x,$y,$fx,$fy,$w,$h,$mix=100) { imagecopymerge($this->img,$aSrcImg,$x,$y,$fx,$fy,$w,$h,$mix); } function _imageCreate($aWidth,$aHeight) { if( $aWidth <= 1 || $aHeight <= 1 ) { JpGraphError::RaiseL(12006,$aWidth,$aHeight); //("Illegal sizes specified for width or height when creating an image, (width=$aWidth, height=$aHeight)"); } if( @$GLOBALS['gd2']==true && USE_TRUECOLOR ) { $this->img = @imagecreatetruecolor($aWidth, $aHeight); if( $this->img < 1 ) { JpGraphError::RaiseL(12011); // die("JpGraph Error: Can't create truecolor image. Check that you really have GD2 library installed."); } ImageAlphaBlending($this->img,true); } else { $this->img = @imagecreate($aWidth, $aHeight); if( $this->img < 1 ) { JpGraphError::RaiseL(12012); // die("JpGraph Error: Can't create image. Check that you really have the GD library installed."); } } } function _polygon($p,$closed=FALSE) { if( $this->iLineWeight==0 ) return; $n=count($p); $oldx = $p[0]; $oldy = $p[1]; for( $i=2; $i < $n; $i+=2 ) { imageline($this->img,$oldx,$oldy,$p[$i],$p[$i+1],$this->iCurrentColor); $oldx = $p[$i]; $oldy = $p[$i+1]; } if( $closed ) { imageline($this->img,$p[$n*2-2],$p[$n*2-1],$p[0],$p[1],$this->iCurrentColor); } } function _filledPolygon($pts) { $n=count($pts); for($i=0; $i < $n; ++$i) $pts[$i] = round($pts[$i]); imagefilledpolygon($this->img,$pts,count($pts)/2,$this->iCurrentColor); } function _rectangle($xl,$yu,$xr,$yl) { for($i=0; $i < $this->iLineWeight; ++$i ) $this->_polygon(array($xl+$i,$yu+$i,$xr-$i,$yu+$i, $xr-$i,$yl-$i,$xl+$i,$yl-$i, $xl+$i,$yu+$i)); } function _filledRectangle($xl,$yu,$xr,$yl) { $this->_filledPolygon(array($xl,$yu,$xr,$yu,$xr,$yl,$xl,$yl)); } function _setColor($aColor) { $this->iCurrentColor = $this->iRGB->Allocate($aColor); } function AddMix($aGraph,$x=0,$y=0,$mix=100,$fx=0,$fy=0,$w=0,$h=0) { $this->_gdImgHandle($aGraph->Stroke( _IMG_HANDLER),$x,$y,$fx=0,$fy=0,$w,$h,$mix); } function Add($aGraph,$x=0,$y=0,$fx=0,$fy=0,$w=0,$h=0) { $this->_gdImgHandle($aGraph->Stroke( _IMG_HANDLER),$x,$y,$fx=0,$fy=0,$w,$h); } function _gdImgHandle($agdCanvas,$x,$y,$fx=0,$fy=0,$w=0,$h=0,$mix=100) { if( $w == 0 ) $w = @imagesx($agdCanvas); if( $w === NULL ) { JpGraphError::RaiseL(12007); //('Argument to MGraph::Add() is not a valid GD image handle.'); return; } if( $h == 0 ) $h = @imagesy($agdCanvas); $this->iGraphs[$this->iCnt++] = array($agdCanvas,$x,$y,$fx,$fy,$w,$h,$mix); } function SetMargin($lm,$rm,$tm,$bm) { $this->lm = $lm; $this->rm = $rm; $this->tm = $tm; $this->bm = $bm; } function SetExpired($aFlg=true) { $this->expired = $aFlg; } // Generate image header function Headers() { // In case we are running from the command line with the client version of // PHP we can't send any headers. $sapi = php_sapi_name(); if( $sapi == 'cli' ) return; if( headers_sent() ) { echo "
JpGraph Error: HTTP headers have already been sent. |
Explanation: HTTP headers have already been sent back to the browser indicating the data as text before the library got a chance to send it's image HTTP header to this browser. This makes it impossible for the library to send back image data to the browser (since that would be interpretated as text by the browser and show up as junk text). Most likely you have some text in your script before the call to Graph::Stroke(). If this texts gets sent back to the browser the browser will assume that all data is plain text. Look for any text, even spaces and newlines, that might have been sent back to the browser. For example it is a common mistake to leave a blank line before the opening \"<?php\". |