Ignore:
Timestamp:
Apr 13, 2019, 8:05:15 PM (6 years ago)
Author:
roby
Message:
 
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/client/modules/Elezioni/grafici/jpgraph_mgraph.php

    r2 r265  
    11<?php
    22/*=======================================================================
    3 // File:        JPGRAPH_MGRAPH.PHP
    4 // Description: Class to handle multiple graphs in the same image
    5 // Created:     2006-01-15
    6 // Ver:         $Id: jpgraph_mgraph.php 1012 2008-06-23 15:02:15Z ljp $
    7 //
    8 // Copyright (c) Aditus Consulting. All rights reserved.
    9 //========================================================================
    10 */
     3 // File:        JPGRAPH_MGRAPH.PHP
     4 // Description: Class to handle multiple graphs in the same image
     5 // Created:     2006-01-15
     6 // Ver:         $Id: jpgraph_mgraph.php 1770 2009-08-17 06:10:22Z ljp $
     7 //
     8 // Copyright (c) Asial Corporation. All rights reserved.
     9 //========================================================================
     10 */
    1111
    1212//=============================================================================
    1313// CLASS MGraph
    14 // Description: Create a container image that can hold several graph 
     14// Description: Create a container image that can hold several graph
    1515//=============================================================================
    1616class MGraph {
     17
     18    public $title = null, $subtitle = null, $subsubtitle = null;
    1719
    1820    protected $img=NULL;
    1921    protected $iCnt=0,$iGraphs = array(); // image_handle, x, y, fx, fy, sizex, sizey
    2022    protected $iFillColor='white', $iCurrentColor=0;
    21     protected $lm=0,$rm=0,$tm=0,$bm=0;
     23    protected $lm=4,$rm=4,$tm=4,$bm=4;
    2224    protected $iDoFrame = FALSE, $iFrameColor = 'black', $iFrameWeight = 1;
    2325    protected $iLineWeight = 1;
    2426    protected $expired=false;
    25     protected $img_format='png',$image_quality=75;
     27    protected $cache=null,$cache_name = '',$inline=true;
     28    protected $image_format='png',$image_quality=75;
    2629    protected $iWidth=NULL,$iHeight=NULL;
    2730    protected $background_image='',$background_image_center=true,
    28         $backround_image_format='',$background_image_mix=100,
    29         $background_image_y=NULL, $background_image_x=NULL;
     31    $backround_image_format='',$background_image_mix=100,
     32    $background_image_y=NULL, $background_image_x=NULL;
     33    private $doshadow=false, $shadow_width=4, $shadow_color='gray@0.5';
     34    public $footer;
     35
    3036
    3137    // Create a new instane of the combined graph
    32     function MGraph($aWidth=NULL,$aHeight=NULL) {
    33         $this->iWidth = $aWidth;
    34         $this->iHeight = $aHeight;
     38    function __construct($aWidth=NULL,$aHeight=NULL,$aCachedName='',$aTimeOut=0,$aInline=true) {
     39        $this->iWidth = $aWidth;
     40        $this->iHeight = $aHeight;
     41
     42        // If the cached version exist just read it directly from the
     43        // cache, stream it back to browser and exit
     44        if( $aCachedName!='' && READ_CACHE && $aInline ) {
     45            $this->cache = new ImgStreamCache();
     46            $this->cache->SetTimeOut($aTimeOut);
     47            $image = new Image();
     48            if( $this->cache->GetAndStream($image,$aCachedName) ) {
     49                exit();
     50            }
     51        }
     52        $this->inline = $aInline;
     53        $this->cache_name = $aCachedName;
     54
     55        $this->title = new Text();
     56        $this->title->ParagraphAlign('center');
     57        $this->title->SetFont(FF_FONT2,FS_BOLD);
     58        $this->title->SetMargin(3);
     59        $this->title->SetAlign('center');
     60
     61        $this->subtitle = new Text();
     62        $this->subtitle->ParagraphAlign('center');
     63        $this->subtitle->SetFont(FF_FONT1,FS_BOLD);
     64        $this->subtitle->SetMargin(3);
     65        $this->subtitle->SetAlign('center');
     66
     67        $this->subsubtitle = new Text();
     68        $this->subsubtitle->ParagraphAlign('center');
     69        $this->subsubtitle->SetFont(FF_FONT1,FS_NORMAL);
     70        $this->subsubtitle->SetMargin(3);
     71        $this->subsubtitle->SetAlign('center');
     72
     73        $this->footer = new Footer();
     74
    3575    }
    3676
    3777    // Specify background fill color for the combined graph
    3878    function SetFillColor($aColor) {
    39         $this->iFillColor = $aColor;
     79        $this->iFillColor = $aColor;
    4080    }
    4181
    4282    // Add a frame around the combined graph
    4383    function SetFrame($aFlg,$aColor='black',$aWeight=1) {
    44         $this->iDoFrame = $aFlg;
    45         $this->iFrameColor = $aColor;
    46         $this->iFrameWeight = $aWeight;
    47     }
    48 
    49     // Specify a background image blend   
     84        $this->iDoFrame = $aFlg;
     85        $this->iFrameColor = $aColor;
     86        $this->iFrameWeight = $aWeight;
     87    }
     88
     89    // Specify a background image blend
    5090    function SetBackgroundImageMix($aMix) {
    51         $this->background_image_mix = $aMix ;
     91        $this->background_image_mix = $aMix ;
    5292    }
    5393
    5494    // Specify a background image
    5595    function SetBackgroundImage($aFileName,$aCenter_aX=NULL,$aY=NULL) {
    56         // Second argument can be either a boolean value or
    57         // a numeric
    58         $aCenter=TRUE;
    59         $aX=NULL;
    60 
    61         if( $GLOBALS['gd2'] && !USE_TRUECOLOR ) {
    62             JpGraphError::RaiseL(12001);
    63 //("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 <b>must</b> 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.");
    64         }
    65         if( is_numeric($aCenter_aX) ) {
    66             $aX=$aCenter_aX;
    67         }
    68 
    69         // Get extension to determine image type
    70         $e = explode('.',$aFileName);
    71         if( !$e ) {
    72             JpGraphError::RaiseL(12002,$aFileName);
    73 //('Incorrect file name for MGraph::SetBackgroundImage() : '.$aFileName.' Must have a valid image extension (jpg,gif,png) when using autodetection of image type');
    74         }
    75        
    76         $valid_formats = array('png', 'jpg', 'gif');
    77         $aImgFormat = strtolower($e[count($e)-1]);
    78         if ($aImgFormat == 'jpeg')  {
    79             $aImgFormat = 'jpg';
    80         }
    81         elseif (!in_array($aImgFormat, $valid_formats) )  {
    82             JpGraphError::RaiseL(12003,$aImgFormat,$aFileName);
    83 //('Unknown file extension ($aImgFormat) in MGraph::SetBackgroundImage() for filename: '.$aFileName);
    84         }   
    85 
    86         $this->background_image = $aFileName;
    87         $this->background_image_center=$aCenter;
    88         $this->background_image_format=$aImgFormat;
    89         $this->background_image_x = $aX;
    90         $this->background_image_y = $aY;
    91     }
    92 
    93 
    94     // Private helper function for backgound image
    95     function _loadBkgImage($aFile='') {
    96         if( $aFile == '' )
    97             $aFile = $this->background_image;
    98 
    99         // Remove case sensitivity and setup appropriate function to create image
    100         // Get file extension. This should be the LAST '.' separated part of the filename
    101         $e = explode('.',$aFile);
    102         $ext = strtolower($e[count($e)-1]);
    103         if ($ext == "jpeg")  {
    104             $ext = "jpg";
    105         }
    106        
    107         if( trim($ext) == '' )
    108             $ext = 'png';  // Assume PNG if no extension specified
    109 
    110         $supported = imagetypes();
    111         if( ( $ext == 'jpg' && !($supported & IMG_JPG) ) ||
    112             ( $ext == 'gif' && !($supported & IMG_GIF) ) ||
    113             ( $ext == 'png' && !($supported & IMG_PNG) ) ) {
    114             JpGraphError::RaiseL(12004,$aFile);//('The image format of your background image ('.$aFile.') is not supported in your system configuration. ');
    115         }
    116 
    117         if( $ext == "jpg" || $ext == "jpeg") {
    118             $f = "imagecreatefromjpeg";
    119             $ext = "jpg";
    120         }
    121         else {
    122             $f = "imagecreatefrom".$ext;
    123         }
    124 
    125         $img = @$f($aFile);
    126         if( !$img ) {
    127             JpGraphError::RaiseL(12005,$aFile);
    128 //(" Can't read background image: '".$aFile."'");   
    129         }
    130         return $img;
    131     }   
     96        // Second argument can be either a boolean value or
     97        // a numeric
     98        $aCenter=TRUE;
     99        $aX=NULL;
     100
     101        if( is_numeric($aCenter_aX) ) {
     102            $aX=$aCenter_aX;
     103        }
     104
     105        // Get extension to determine image type
     106        $e = explode('.',$aFileName);
     107        if( !$e ) {
     108            JpGraphError::RaiseL(12002,$aFileName);
     109            //('Incorrect file name for MGraph::SetBackgroundImage() : '.$aFileName.' Must have a valid image extension (jpg,gif,png) when using autodetection of image type');
     110        }
     111
     112        $valid_formats = array('png', 'jpg', 'gif');
     113        $aImgFormat = strtolower($e[count($e)-1]);
     114        if ($aImgFormat == 'jpeg')  {
     115            $aImgFormat = 'jpg';
     116        }
     117        elseif (!in_array($aImgFormat, $valid_formats) )  {
     118            JpGraphError::RaiseL(12003,$aImgFormat,$aFileName);
     119            //('Unknown file extension ($aImgFormat) in MGraph::SetBackgroundImage() for filename: '.$aFileName);
     120        }
     121
     122        $this->background_image = $aFileName;
     123        $this->background_image_center=$aCenter;
     124        $this->background_image_format=$aImgFormat;
     125        $this->background_image_x = $aX;
     126        $this->background_image_y = $aY;
     127    }
    132128
    133129    function _strokeBackgroundImage() {
    134         if( $this->background_image == '' )
    135             return;
    136 
    137         $bkgimg = $this->_loadBkgImage();
    138         // Background width & Heoght
    139         $bw = imagesx($bkgimg);
    140         $bh = imagesy($bkgimg);
    141         // Canvas width and height
    142         $cw = imagesx($this->img);
    143         $ch = imagesy($this->img);
    144 
    145         if( $this->background_image_x === NULL || $this->background_image_y === NULL ) {
    146             if( $this->background_image_center ) {
    147                 // Center original image in the plot area
    148                 $x = round($cw/2-$bw/2); $y = round($ch/2-$bh/2);
    149             }
    150             else {
    151                 // Just copy the image from left corner, no resizing
    152                 $x=0; $y=0;
    153             }                   
    154         }
    155         else {
    156             $x = $this->background_image_x;
    157             $y = $this->background_image_y;
    158         }
    159         $this->_imageCp($bkgimg,$x,$y,0,0,$bw,$bh,$this->background_image_mix);
    160     }
    161 
    162     function _imageCp($aSrcImg,$x,$y,$fx,$fy,$w,$h,$mix=100) {
    163         imagecopymerge($this->img,$aSrcImg,$x,$y,$fx,$fy,$w,$h,$mix);
    164     }
    165 
    166     function _imageCreate($aWidth,$aHeight) {
    167         if( $aWidth <= 1 || $aHeight <= 1 ) {
    168             JpGraphError::RaiseL(12006,$aWidth,$aHeight);
    169 //("Illegal sizes specified for width or height when creating an image, (width=$aWidth, height=$aHeight)");
    170         }
    171         if( @$GLOBALS['gd2']==true && USE_TRUECOLOR ) {
    172             $this->img = @imagecreatetruecolor($aWidth, $aHeight);
    173             if( $this->img < 1 ) {
    174                 JpGraphError::RaiseL(12011);
    175 // die("<b>JpGraph Error:</b> Can't create truecolor image. Check that you really have GD2 library installed.");
    176             }
    177             ImageAlphaBlending($this->img,true);
    178         } else {
    179             $this->img = @imagecreate($aWidth, $aHeight);       
    180             if( $this->img < 1 ) {
    181                 JpGraphError::RaiseL(12012);
    182 // die("<b>JpGraph Error:</b> Can't create image. Check that you really have the GD library installed.");
    183             }
    184         }
    185     }
    186 
    187     function _polygon($p,$closed=FALSE) {
    188         if( $this->iLineWeight==0 ) return;
    189         $n=count($p);
    190         $oldx = $p[0];
    191         $oldy = $p[1];
    192         for( $i=2; $i < $n; $i+=2 ) {
    193             imageline($this->img,$oldx,$oldy,$p[$i],$p[$i+1],$this->iCurrentColor);
    194             $oldx = $p[$i];
    195             $oldy = $p[$i+1];
    196         }
    197         if( $closed ) {
    198             imageline($this->img,$p[$n*2-2],$p[$n*2-1],$p[0],$p[1],$this->iCurrentColor);
    199         }
    200     }
    201 
    202     function _filledPolygon($pts) {
    203         $n=count($pts);
    204         for($i=0; $i < $n; ++$i)
    205             $pts[$i] = round($pts[$i]);
    206         imagefilledpolygon($this->img,$pts,count($pts)/2,$this->iCurrentColor);
    207     }
    208        
    209     function _rectangle($xl,$yu,$xr,$yl) {
    210         for($i=0; $i < $this->iLineWeight; ++$i )
    211             $this->_polygon(array($xl+$i,$yu+$i,$xr-$i,$yu+$i,
    212                                   $xr-$i,$yl-$i,$xl+$i,$yl-$i,
    213                                   $xl+$i,$yu+$i));
    214     }
    215        
    216     function _filledRectangle($xl,$yu,$xr,$yl) {
    217         $this->_filledPolygon(array($xl,$yu,$xr,$yu,$xr,$yl,$xl,$yl));
    218     }
    219 
    220     function _setColor($aColor) {
    221         $this->iCurrentColor = $this->iRGB->Allocate($aColor);
     130        if( $this->background_image == '' ) return;
     131
     132        $bkgimg = Graph::LoadBkgImage('',$this->background_image);
     133
     134        // Background width & Heoght
     135        $bw = imagesx($bkgimg);
     136        $bh = imagesy($bkgimg);
     137
     138        // Canvas width and height
     139        $cw = imagesx($this->img);
     140        $ch = imagesy($this->img);
     141
     142        if( $this->doshadow ) {
     143            $cw -= $this->shadow_width;
     144            $ch -= $this->shadow_width;
     145        }
     146
     147        if( $this->background_image_x === NULL || $this->background_image_y === NULL ) {
     148            if( $this->background_image_center ) {
     149                // Center original image in the plot area
     150                $x = round($cw/2-$bw/2); $y = round($ch/2-$bh/2);
     151            }
     152            else {
     153                // Just copy the image from left corner, no resizing
     154                $x=0; $y=0;
     155            }
     156        }
     157        else {
     158            $x = $this->background_image_x;
     159            $y = $this->background_image_y;
     160        }
     161        imagecopymerge($this->img,$bkgimg,$x,$y,0,0,$bw,$bh,$this->background_image_mix);
    222162    }
    223163
    224164    function AddMix($aGraph,$x=0,$y=0,$mix=100,$fx=0,$fy=0,$w=0,$h=0) {
    225         $this->_gdImgHandle($aGraph->Stroke( _IMG_HANDLER),$x,$y,$fx=0,$fy=0,$w,$h,$mix);
    226     }
    227    
     165        $this->_gdImgHandle($aGraph->Stroke( _IMG_HANDLER),$x,$y,$fx=0,$fy=0,$w,$h,$mix);
     166    }
     167
    228168    function Add($aGraph,$x=0,$y=0,$fx=0,$fy=0,$w=0,$h=0) {
    229         $this->_gdImgHandle($aGraph->Stroke( _IMG_HANDLER),$x,$y,$fx=0,$fy=0,$w,$h);
     169        $this->_gdImgHandle($aGraph->Stroke( _IMG_HANDLER),$x,$y,$fx=0,$fy=0,$w,$h);
    230170    }
    231171
    232172    function _gdImgHandle($agdCanvas,$x,$y,$fx=0,$fy=0,$w=0,$h=0,$mix=100) {
    233         if( $w == 0 )  $w = @imagesx($agdCanvas);
    234         if( $w === NULL ) {
    235             JpGraphError::RaiseL(12007);
    236 //('Argument to MGraph::Add() is not a valid GD image handle.');
    237             return;
    238         }
    239         if( $h == 0 )  $h = @imagesy($agdCanvas);
    240         $this->iGraphs[$this->iCnt++] = array($agdCanvas,$x,$y,$fx,$fy,$w,$h,$mix);
     173        if( $w == 0 ) {
     174            $w = @imagesx($agdCanvas);
     175        }
     176        if( $w === NULL ) {
     177            JpGraphError::RaiseL(12007);
     178            //('Argument to MGraph::Add() is not a valid GD image handle.');
     179            return;
     180        }
     181        if( $h == 0 ) {
     182            $h = @imagesy($agdCanvas);
     183        }
     184        $this->iGraphs[$this->iCnt++] = array($agdCanvas,$x,$y,$fx,$fy,$w,$h,$mix);
    241185    }
    242186
    243187    function SetMargin($lm,$rm,$tm,$bm) {
    244         $this->lm = $lm;
    245         $this->rm = $rm;
    246         $this->tm = $tm;
    247         $this->bm = $bm;
     188        $this->lm = $lm;
     189        $this->rm = $rm;
     190        $this->tm = $tm;
     191        $this->bm = $bm;
    248192    }
    249193
    250194    function SetExpired($aFlg=true) {
    251         $this->expired = $aFlg;
    252     }
    253 
    254     // Generate image header
    255     function Headers() {
    256        
    257         // In case we are running from the command line with the client version of
    258         // PHP we can't send any headers.
    259         $sapi = php_sapi_name();
    260         if( $sapi == 'cli' )
    261             return;
    262        
    263         if( headers_sent() ) {
    264            
    265             echo "<table border=1><tr><td><font color=darkred size=4><b>JpGraph Error:</b>
    266 HTTP headers have already been sent.</font></td></tr><tr><td><b>Explanation:</b><br>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).<p>Most likely you have some text in your script before the call to <i>Graph::Stroke()</i>. 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. <p>For example it is a common mistake to leave a blank line before the opening \"<b>&lt;?php</b>\".</td></tr></table>";
    267 
    268         die();
    269 
    270         }       
    271        
    272         if ($this->expired) {
    273             header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
    274             header("Last-Modified: " . gmdate("D, d M Y H:i:s") . "GMT");
    275             header("Cache-Control: no-cache, must-revalidate");
    276             header("Pragma: no-cache");
    277         }
    278         header("Content-type: image/$this->img_format");
     195        $this->expired = $aFlg;
    279196    }
    280197
    281198    function SetImgFormat($aFormat,$aQuality=75) {
    282         $this->image_quality = $aQuality;
    283         $aFormat = strtolower($aFormat);
    284         $tst = true;
    285         $supported = imagetypes();
    286         if( $aFormat=="auto" ) {
    287             if( $supported & IMG_PNG )
    288                 $this->img_format="png";
    289             elseif( $supported & IMG_JPG )
    290                 $this->img_format="jpeg";
    291             elseif( $supported & IMG_GIF )
    292                 $this->img_format="gif";
    293             else
    294                 JpGraphError::RaiseL(12008);
    295 //(" Your PHP (and GD-lib) installation does not appear to support any known graphic formats.".
    296             return true;
    297         }
    298         else {
    299             if( $aFormat=="jpeg" || $aFormat=="png" || $aFormat=="gif" ) {
    300                 if( $aFormat=="jpeg" && !($supported & IMG_JPG) )
    301                     $tst=false;
    302                 elseif( $aFormat=="png" && !($supported & IMG_PNG) )
    303                     $tst=false;
    304                 elseif( $aFormat=="gif" && !($supported & IMG_GIF) )   
    305                     $tst=false;
    306                 else {
    307                     $this->img_format=$aFormat;
    308                     return true;
    309                 }
    310             }
    311             else
    312                 $tst=false;
    313             if( !$tst )
    314                 JpGraphError::RaiseL(12009,$aFormat);
    315 //(" Your PHP installation does not support the chosen graphic format: $aFormat");
    316         }
    317     }
    318 
    319     // Stream image to browser or to file
    320     function Stream($aFile="") {
    321         $func="image".$this->img_format;
    322         if( $this->img_format=="jpeg" && $this->image_quality != null ) {
    323             $res = @$func($this->img,$aFile,$this->image_quality);
    324         }
    325         else {
    326             if( $aFile != "" ) {
    327                 $res = @$func($this->img,$aFile);
    328             }
    329             else
    330                 $res = @$func($this->img);
    331         }
    332         if( !$res )
    333             JpGraphError::RaiseL(12010,$aFile);
    334 //("Can't create or stream image to file $aFile Check that PHP has enough permission to write a file to the current directory.");
     199        $this->image_format = $aFormat;
     200        $this->image_quality = $aQuality;
     201    }
     202
     203    // Set the shadow around the whole image
     204    function SetShadow($aShowShadow=true,$aShadowWidth=4,$aShadowColor='gray@0.3') {
     205        $this->doshadow = $aShowShadow;
     206        $this->shadow_color = $aShadowColor;
     207        $this->shadow_width = $aShadowWidth;
     208        $this->footer->iBottomMargin += $aShadowWidth;
     209        $this->footer->iRightMargin += $aShadowWidth;
     210    }
     211
     212    function StrokeTitle($image,$w,$h) {
     213        // Stroke title
     214        if( $this->title->t !== '' ) {
     215
     216            $margin = 3;
     217
     218            $y = $this->title->margin;
     219            if( $this->title->halign == 'center' ) {
     220                $this->title->Center(0,$w,$y);
     221            }
     222            elseif( $this->title->halign == 'left' ) {
     223                $this->title->SetPos($this->title->margin+2,$y);
     224            }
     225            elseif( $this->title->halign == 'right' ) {
     226                $indent = 0;
     227                if( $this->doshadow ) {
     228                    $indent = $this->shadow_width+2;
     229                }
     230                $this->title->SetPos($w-$this->title->margin-$indent,$y,'right');
     231            }
     232            $this->title->Stroke($image);
     233
     234            // ... and subtitle
     235            $y += $this->title->GetTextHeight($image) + $margin + $this->subtitle->margin;
     236            if( $this->subtitle->halign == 'center' ) {
     237                $this->subtitle->Center(0,$w,$y);
     238            }
     239            elseif( $this->subtitle->halign == 'left' ) {
     240                $this->subtitle->SetPos($this->subtitle->margin+2,$y);
     241            }
     242            elseif( $this->subtitle->halign == 'right' ) {
     243                $indent = 0;
     244                if( $this->doshadow ) {
     245                    $indent = $this->shadow_width+2;
     246                }
     247                $this->subtitle->SetPos($this->img->width-$this->subtitle->margin-$indent,$y,'right');
     248            }
     249            $this->subtitle->Stroke($image);
     250
     251            // ... and subsubtitle
     252            $y += $this->subtitle->GetTextHeight($image) + $margin + $this->subsubtitle->margin;
     253            if( $this->subsubtitle->halign == 'center' ) {
     254                $this->subsubtitle->Center(0,$w,$y);
     255            }
     256            elseif( $this->subsubtitle->halign == 'left' ) {
     257                $this->subsubtitle->SetPos($this->subsubtitle->margin+2,$y);
     258            }
     259            elseif( $this->subsubtitle->halign == 'right' ) {
     260                $indent = 0;
     261                if( $this->doshadow ) {
     262                    $indent = $this->shadow_width+2;
     263                }
     264                $this->subsubtitle->SetPos($w-$this->subsubtitle->margin-$indent,$y,'right');
     265            }
     266            $this->subsubtitle->Stroke($image);
     267
     268        }
    335269    }
    336270
    337271    function Stroke($aFileName='') {
    338         // Find out the necessary size for the container image
    339         $w=0; $h=0;
    340         for($i=0; $i < $this->iCnt; ++$i ) {
    341             $maxw = $this->iGraphs[$i][1]+$this->iGraphs[$i][5];
    342             $maxh = $this->iGraphs[$i][2]+$this->iGraphs[$i][6];
    343             $w = max( $w, $maxw );
    344             $h = max( $h, $maxh );
    345         }
    346         $w += $this->lm+$this->rm;
    347         $h += $this->tm+$this->bm;
    348 
    349         // User specified width,height overrides
    350         if( $this->iWidth !== NULL ) $w = $this->iWidth;
    351         if( $this->iHeight!== NULL ) $h = $this->iHeight;
    352 
    353         $this->_imageCreate($w,$h);
    354         $this->iRGB = new RGB($this->img);
    355 
    356         $this->_setcolor($this->iFillColor);
    357         $this->_filledRectangle(0,0,$w-1,$h-1);
    358 
    359         $this->_strokeBackgroundImage();
    360 
    361         if( $this->iDoFrame ) {
    362             $this->_setColor($this->iFrameColor);
    363             $this->iLineWeight=$this->iFrameWeight;
    364             $this->_rectangle(0,0,$w-1,$h-1);
    365         }
    366 
    367         // Copy all sub graphs to the container
    368         for($i=0; $i < $this->iCnt; ++$i ) {
    369             $this->_imageCp($this->iGraphs[$i][0],
    370                             $this->iGraphs[$i][1]+$this->lm,$this->iGraphs[$i][2]+$this->tm,
    371                             $this->iGraphs[$i][3],$this->iGraphs[$i][4],
    372                             $this->iGraphs[$i][5],$this->iGraphs[$i][6],
    373                             $this->iGraphs[$i][7]);
    374         }
    375 
    376         // Output image
    377         if( $aFileName == _IMG_HANDLER ) {
    378             return $this->img;
    379         }
    380         else {
    381             if( $aFileName != '' ) {
    382                 $this->Stream($aFileName);
    383             }
    384             else {
    385                 $this->Headers();
    386                 $this->Stream();
    387             }
    388         }
     272        // Find out the necessary size for the container image
     273        $w=0; $h=0;
     274        for($i=0; $i < $this->iCnt; ++$i ) {
     275            $maxw = $this->iGraphs[$i][1]+$this->iGraphs[$i][5];
     276            $maxh = $this->iGraphs[$i][2]+$this->iGraphs[$i][6];
     277            $w = max( $w, $maxw );
     278            $h = max( $h, $maxh );
     279        }
     280        $w += $this->lm+$this->rm;
     281        $h += $this->tm+$this->bm;
     282
     283        // User specified width,height overrides
     284        if( $this->iWidth !== NULL && $this->iWidth !== 0 ) $w = $this->iWidth;
     285        if( $this->iHeight!== NULL && $this->iHeight !== 0) $h = $this->iHeight;
     286
     287        if( $this->doshadow ) {
     288            $w += $this->shadow_width;
     289            $h += $this->shadow_width;
     290        }
     291
     292        $image = new Image($w,$h);
     293        $image->SetImgFormat( $this->image_format,$this->image_quality);
     294
     295        if( $this->doshadow ) {
     296            $image->SetColor($this->iFrameColor);
     297            $image->ShadowRectangle(0,0,$w-1,$h-1,$this->iFillColor,$this->shadow_width,$this->shadow_color);
     298            $w -= $this->shadow_width;
     299            $h -= $this->shadow_width;
     300        }
     301        else {
     302            $image->SetColor($this->iFillColor);
     303            $image->FilledRectangle(0,0,$w-1,$h-1);
     304        }
     305        $image->SetExpired($this->expired);
     306
     307        $this->img = $image->img;
     308        $this->_strokeBackgroundImage();
     309
     310        if( $this->iDoFrame && ! $this->doshadow ) {
     311           $image->SetColor($this->iFrameColor);
     312           $image->SetLineWeight($this->iFrameWeight);
     313           $image->Rectangle(0,0,$w-1,$h-1);
     314        }
     315
     316        // Copy all sub graphs to the container
     317        for($i=0; $i < $this->iCnt; ++$i ) {
     318            $image->CopyMerge($this->iGraphs[$i][0],
     319                            $this->iGraphs[$i][1]+$this->lm,$this->iGraphs[$i][2]+$this->tm,
     320                            $this->iGraphs[$i][3],$this->iGraphs[$i][4],
     321                            $this->iGraphs[$i][5],$this->iGraphs[$i][6],
     322                            -1,-1, /* Full from width and height */
     323                            $this->iGraphs[$i][7]);
     324
     325
     326        }
     327
     328        $this->StrokeTitle($image,$w,$h);
     329        $this->footer->Stroke($image);
     330
     331        // Output image
     332        if( $aFileName == _IMG_HANDLER ) {
     333            return $image->img;
     334        }
     335        else {
     336            //Finally stream the generated picture
     337            $this->cache = new ImgStreamCache();
     338            $this->cache->PutAndStream($image,$this->cache_name,$this->inline,$aFileName);
     339        }
    389340    }
    390341}
    391342
     343// EOF
     344
    392345?>
Note: See TracChangeset for help on using the changeset viewer.