function CopyMerge($fromImg, $toX, $toY, $fromX, $fromY, $toWidth, $toHeight, $fromWidth = -1, $fromHeight = -1, $aMix = 100) { list($toX, $toY) = $this->Rotate($toX, $toY); parent::CopyMerge($fromImg, $toX, $toY, $fromX, $fromY, $toWidth, $toHeight, $fromWidth, $fromHeight, $aMix); }
function Stroke($aFileName = '') { // Find out the necessary size for the container image $w = 0; $h = 0; for ($i = 0; $i < $this->iCnt; ++$i) { $maxw = $this->iGraphs[$i][1] + $this->iGraphs[$i][5]; $maxh = $this->iGraphs[$i][2] + $this->iGraphs[$i][6]; $w = max($w, $maxw); $h = max($h, $maxh); } $w += $this->lm + $this->rm; $h += $this->tm + $this->bm; // User specified width,height overrides if ($this->iWidth !== NULL && $this->iWidth !== 0) { $w = $this->iWidth; } if ($this->iHeight !== NULL && $this->iHeight !== 0) { $h = $this->iHeight; } $image = new Image($w, $h); $image->SetImgFormat($this->image_format, $this->image_quality); $image->SetColor($this->iFillColor); $image->FilledRectangle(0, 0, $w - 1, $h - 1); $image->SetExpired($this->expired); $this->img = $image->img; $this->_strokeBackgroundImage(); if ($this->iDoFrame) { $image->SetColor($this->iFrameColor); $image->SetLineWeight($this->iFrameWeight); $image->Rectangle(0, 0, $w - 1, $h - 1); } // Copy all sub graphs to the container for ($i = 0; $i < $this->iCnt; ++$i) { $image->CopyMerge($this->iGraphs[$i][0], $this->iGraphs[$i][1] + $this->lm, $this->iGraphs[$i][2] + $this->tm, $this->iGraphs[$i][3], $this->iGraphs[$i][4], $this->iGraphs[$i][5], $this->iGraphs[$i][6], -1, -1, $this->iGraphs[$i][7]); } // Stroke title if ($this->title->t !== '') { $margin = 3; $y = $this->title->margin; if ($this->title->halign == 'center') { $this->title->Center(0, $w, $y); } elseif ($this->title->halign == 'left') { $this->title->SetPos($this->title->margin + 2, $y); } elseif ($this->title->halign == 'right') { $indent = 0; if ($this->doshadow) { $indent = $this->shadow_width + 2; } $this->title->SetPos($w - $this->title->margin - $indent, $y, 'right'); } $this->title->Stroke($image); // ... and subtitle $y += $this->title->GetTextHeight($image) + $margin + $this->subtitle->margin; if ($this->subtitle->halign == 'center') { $this->subtitle->Center(0, $w, $y); } elseif ($this->subtitle->halign == 'left') { $this->subtitle->SetPos($this->subtitle->margin + 2, $y); } elseif ($this->subtitle->halign == 'right') { $indent = 0; if ($this->doshadow) { $indent = $this->shadow_width + 2; } $this->subtitle->SetPos($this->img->width - $this->subtitle->margin - $indent, $y, 'right'); } $this->subtitle->Stroke($image); // ... and subsubtitle $y += $this->subtitle->GetTextHeight($image) + $margin + $this->subsubtitle->margin; if ($this->subsubtitle->halign == 'center') { $this->subsubtitle->Center(0, $w, $y); } elseif ($this->subsubtitle->halign == 'left') { $this->subsubtitle->SetPos($this->subsubtitle->margin + 2, $y); } elseif ($this->subsubtitle->halign == 'right') { $indent = 0; if ($this->doshadow) { $indent = $this->shadow_width + 2; } $this->subsubtitle->SetPos($w - $this->subsubtitle->margin - $indent, $y, 'right'); } $this->subsubtitle->Stroke($image); } // Output image if ($aFileName == _IMG_HANDLER) { return $image->img; } else { //Finally stream the generated picture $this->cache = new ImgStreamCache(); $this->cache->PutAndStream($image, $this->cache_name, $this->inline, $aFileName); } }
function Stroke($aFileName = '') { // Find out the necessary size for the container image $w = 0; $h = 0; for ($i = 0; $i < $this->iCnt; ++$i) { $maxw = $this->iGraphs[$i][1] + $this->iGraphs[$i][5]; $maxh = $this->iGraphs[$i][2] + $this->iGraphs[$i][6]; $w = max($w, $maxw); $h = max($h, $maxh); } $w += $this->lm + $this->rm; $h += $this->tm + $this->bm; // User specified width,height overrides if ($this->iWidth !== NULL && $this->iWidth !== 0) { $w = $this->iWidth; } if ($this->iHeight !== NULL && $this->iHeight !== 0) { $h = $this->iHeight; } if ($this->doshadow) { $w += $this->shadow_width; $h += $this->shadow_width; } $image = new Image($w, $h); $image->SetImgFormat($this->image_format, $this->image_quality); if ($this->doshadow) { $image->SetColor($this->iFrameColor); $image->ShadowRectangle(0, 0, $w - 1, $h - 1, $this->iFillColor, $this->shadow_width, $this->shadow_color); $w -= $this->shadow_width; $h -= $this->shadow_width; } else { $image->SetColor($this->iFillColor); $image->FilledRectangle(0, 0, $w - 1, $h - 1); } $image->SetExpired($this->expired); $this->img = $image->img; $this->_strokeBackgroundImage(); if ($this->iDoFrame && !$this->doshadow) { $image->SetColor($this->iFrameColor); $image->SetLineWeight($this->iFrameWeight); $image->Rectangle(0, 0, $w - 1, $h - 1); } // Copy all sub graphs to the container for ($i = 0; $i < $this->iCnt; ++$i) { $image->CopyMerge($this->iGraphs[$i][0], $this->iGraphs[$i][1] + $this->lm, $this->iGraphs[$i][2] + $this->tm, $this->iGraphs[$i][3], $this->iGraphs[$i][4], $this->iGraphs[$i][5], $this->iGraphs[$i][6], -1, -1, $this->iGraphs[$i][7]); } $this->StrokeTitle($image, $w, $h); $this->footer->Stroke($image); // Output image if ($aFileName == _IMG_HANDLER) { return $image->img; } else { //Finally stream the generated picture $this->cache = new ImgStreamCache(); $this->cache->PutAndStream($image, $this->cache_name, $this->inline, $aFileName); } }
function StrokeFrameBackground() { if ($this->background_image != '' && $this->background_cflag != '') { JpGraphError::RaiseL(25040); //('It is not possible to specify both a background image and a background country flag.'); } if ($this->background_image != '') { $bkgimg = $this->LoadBkgImage($this->background_image_format, $this->background_image); } elseif ($this->background_cflag != '') { if (!class_exists('FlagImages', false)) { JpGraphError::RaiseL(25041); //('In order to use Country flags as backgrounds you must include the "jpgraph_flags.php" file.'); } $fobj = new FlagImages(FLAGSIZE4); $dummy = ''; $bkgimg = $fobj->GetImgByName($this->background_cflag, $dummy); $this->background_image_mix = $this->background_cflag_mix; $this->background_image_type = $this->background_cflag_type; } else { return; } $bw = ImageSX($bkgimg); $bh = ImageSY($bkgimg); // No matter what the angle is we always stroke the image and frame // assuming it is 0 degree $aa = $this->img->SetAngle(0); switch ($this->background_image_type) { case BGIMG_FILLPLOT: // Resize to just fill the plotarea $this->FillMarginArea(); $this->StrokeFrame(); // Special case to hande 90 degree rotated graph corectly if ($aa == 90) { $this->img->SetAngle(90); $this->FillPlotArea(); $aa = $this->img->SetAngle(0); $adj = ($this->img->height - $this->img->width) / 2; $this->img->CopyMerge($bkgimg, $this->img->bottom_margin - $adj, $this->img->left_margin + $adj, 0, 0, $this->img->plotheight + 1, $this->img->plotwidth, $bw, $bh, $this->background_image_mix); } else { $this->FillPlotArea(); $this->img->CopyMerge($bkgimg, $this->img->left_margin, $this->img->top_margin + 1, 0, 0, $this->img->plotwidth + 1, $this->img->plotheight, $bw, $bh, $this->background_image_mix); } break; case BGIMG_FILLFRAME: // Fill the whole area from upper left corner, resize to just fit $hadj = 0; $vadj = 0; if ($this->doshadow) { $hadj = $this->shadow_width; $vadj = $this->shadow_width; } $this->FillMarginArea(); $this->FillPlotArea(); $this->img->CopyMerge($bkgimg, 0, 0, 0, 0, $this->img->width - $hadj, $this->img->height - $vadj, $bw, $bh, $this->background_image_mix); $this->StrokeFrame(); break; case BGIMG_COPY: // Just copy the image from left corner, no resizing $this->FillMarginArea(); $this->FillPlotArea(); $this->img->CopyMerge($bkgimg, 0, 0, 0, 0, $bw, $bh, $bw, $bh, $this->background_image_mix); $this->StrokeFrame(); break; case BGIMG_CENTER: // Center original image in the plot area $this->FillMarginArea(); $this->FillPlotArea(); $centerx = round($this->img->plotwidth / 2 + $this->img->left_margin - $bw / 2); $centery = round($this->img->plotheight / 2 + $this->img->top_margin - $bh / 2); $this->img->CopyMerge($bkgimg, $centerx, $centery, 0, 0, $bw, $bh, $bw, $bh, $this->background_image_mix); $this->StrokeFrame(); break; case BGIMG_FREE: // Just copy the image to the specified location $this->img->CopyMerge($bkgimg, $this->background_image_xpos, $this->background_image_ypos, 0, 0, $bw, $bh, $bw, $bh, $this->background_image_mix); $this->StrokeFrame(); // New break; default: JpGraphError::RaiseL(25042); //(" Unknown background image layout"); } $this->img->SetAngle($aa); }