public function EvaluateTemplate($strTemplate) { global $_ITEM; global $_CONTROL; $_FORM = $this; if ($strTemplate) { QApplication::$ProcessOutput = false; // Store the Output Buffer locally $strAlreadyRendered = ob_get_contents(); ob_clean(); // Evaluate the new template ob_start('__QForm_EvaluateTemplate_ObHandler'); require $strTemplate; $strTemplateEvaluated = ob_get_contents(); ob_end_clean(); // Restore the output buffer and return evaluated template print $strAlreadyRendered; QApplication::$ProcessOutput = true; return $strTemplateEvaluated; } else { return null; } }
protected function RenderImage($strPath = null) { $strWidth = $this->Width; // Make Sure Font File Exists if (file_exists($this->strFontNames)) { $strFontPath = $this->strFontNames; } else { throw new QCallerException('Cannot find font file: ' . $this->strFontNames); } // Figure Out Font Type $strFontExtension = substr($this->strFontNames, strlen($this->strFontNames) - 3); $strFontExtension = strtolower($strFontExtension); // Based on Font Type, Calculate Bounding Box switch ($strFontExtension) { case 'ttf': $blnTrueType = true; $objBox = imagettfbbox($this->strFontSize, $this->intAngle, $strFontPath, $this->strText); // Calculate Bounding Box Dimensions $intXCoordinate1 = $objBox[0]; $intYCoordinate1 = $objBox[5]; $intXCoordinate2 = $objBox[4]; $intYCoordinate2 = $objBox[1]; break; case 'pfb': $blnTrueType = false; // Load Font and Calculate $objFont = imagepsloadfont($strFontPath); $objBox = imagepsbbox($this->strText, $objFont, $this->strFontSize, $this->intSpace, $this->intTightness, $this->intAngle); // Calculate Bounding Box Dimensions $intXCoordinate1 = $objBox[0]; $intYCoordinate1 = $objBox[1]; $intXCoordinate2 = $objBox[2]; $intYCoordinate2 = $objBox[3]; break; default: throw new QCallerException('Cannot Determine Font Type: ' . $this->strFontNames); } $intBoxWidth = $intXCoordinate2 - $intXCoordinate1; $intBoxHeight = $intYCoordinate2 - $intYCoordinate1; // Figure Out Image Width and Height: // 1. If no width/height set, then use bounding box + padding // 2. otherwise, if alignment, we set to alignment // 3. otherwise, use coordinates if (!$strWidth) { // Step 1 -- Use Bounding Box + Padding $intWidth = $intBoxWidth + $this->intPaddingWidth * 2; $intX = $this->intPaddingWidth; } else { // Step 2 - Alignment switch ($this->strHorizontalAlign) { case QHorizontalAlign::Left: $intX = -1 * $intXCoordinate1 + 2 + $this->intPaddingWidth; break; case QHorizontalAlign::Right: $intX = $strWidth - $intBoxWidth - 2 - $this->intPaddingWidth; break; case QHorizontalAlign::Center: $intX = round(($strWidth - $intBoxWidth) / 2); break; // Step 3 - Use Coordinates // Step 3 - Use Coordinates default: $intX = $this->intXCoordinate; break; } $intWidth = $strWidth; } if (!$this->Height) { // Step 1 -- Use Bounding Box + Padding $intHeight = $intBoxHeight + $this->intPaddingHeight * 2; if ($blnTrueType) { $intY = $intBoxHeight - $intYCoordinate2 + $this->intPaddingHeight; } else { $intY = $intYCoordinate2 + $this->intPaddingHeight + 1; } } else { // Step 2 - Alignment switch ($this->strVerticalAlign) { case QVerticalAlign::Top: if ($blnTrueType) { $intY = $intBoxHeight - $intYCoordinate2 + $this->intPaddingHeight; } else { $intY = $intYCoordinate2 + 2 + $this->intPaddingHeight; } break; case QVerticalAlign::Bottom: if ($blnTrueType) { $intY = $this->Height - $intYCoordinate2 - $this->intPaddingHeight; } else { $intY = $this->Height + $intYCoordinate1 - 2 - $this->intPaddingHeight; } break; case QVerticalAlign::Middle: if ($blnTrueType) { $intY = round(($this->Height - $intBoxHeight) / 2) + $intBoxHeight - $intYCoordinate2; } else { $intY = round(($this->Height - $intBoxHeight) / 2) + $intYCoordinate2; } break; // Step 3 - Use Coordinates // Step 3 - Use Coordinates default: $intY = $this->intYCoordinate; break; } $intHeight = $this->Height; } if ($intWidth <= 0) { $intWidth = 100; } if ($intHeight <= 0) { $intHeight = 100; } $objImage = imagecreate($intWidth, $intHeight); // Define Colors $intRed = hexdec(substr($this->strBackColor, 0, 2)); $intGreen = hexdec(substr($this->strBackColor, 2, 2)); $intBlue = hexdec(substr($this->strBackColor, 4)); $clrBackground = imagecolorallocate($objImage, $intRed, $intGreen, $intBlue); $intRed = hexdec(substr($this->strForeColor, 0, 2)); $intGreen = hexdec(substr($this->strForeColor, 2, 2)); $intBlue = hexdec(substr($this->strForeColor, 4)); $clrForeground = imagecolorallocate($objImage, $intRed, $intGreen, $intBlue); if ($this->blnBackgroundTransparent) { imagecolortransparent($objImage, $clrBackground); } imagefilledrectangle($objImage, 0, 0, $intWidth, $intHeight, $clrBackground); if ($blnTrueType) { imagettftext($objImage, $this->strFontSize, $this->intAngle, $intX, $intY, $clrForeground, $strFontPath, $this->strText); } else { // Anti Aliasing if ($this->blnSmoothFont) { $intAntiAliasing = 16; } else { $intAntiAliasing = 4; } // Draw Text and Free Font imagepstext($objImage, $this->strText, $objFont, $this->strFontSize, $clrForeground, $clrBackground, $intX, $intY, $this->intSpace, $this->intTightness, $this->intAngle, $intAntiAliasing); imagepsfreefont($objFont); } // Output the Image (if path isn't specified, output to buffer. Otherwise, output to disk) if (!$strPath) { // TODO: Update Cache Parameters QApplication::$ProcessOutput = false; header('Cache-Control: cache'); header('Expires: Wed, 20 Mar 2019 05:00:00 GMT'); header('Pragma: cache'); switch ($this->strImageType) { case QImageType::Gif: header('Content-type: image/gif'); imagegif($objImage); break; case QImageType::Jpeg: header('Content-type: image/jpeg'); imagejpeg($objImage, null, $this->intQuality); break; default: header('Content-type: image/png'); imagepng($objImage); break; } } else { switch ($this->strImageType) { case QImageType::Gif: imagegif($objImage, $strPath); break; case QImageType::Jpeg: imagejpeg($objImage, $strPath, $this->intQuality); break; default: imagepng($objImage, $strPath); break; } } imagedestroy($objImage); }
/** * This function evaluates a template and is used by a variety of controls. It is similar to the function found in the * QForm, but recreated here so that the "$this" in the template will be the control, instead of the form, * and the protected members of the control are available to draw directly. * @param string $strTemplate Path to the HTML template file * * @return string The evaluated HTML string */ public function EvaluateTemplate($strTemplate) { global $_ITEM; // used by data repeater global $_CONTROL; global $_FORM; if ($strTemplate) { QApplication::$ProcessOutput = false; // Store the Output Buffer locally $strAlreadyRendered = ob_get_contents(); if ($strAlreadyRendered) { ob_clean(); } // Evaluate the new template ob_start('__QForm_EvaluateTemplate_ObHandler'); $strTemplate = $this->GetTemplatePath($strTemplate); require $strTemplate; $strTemplateEvaluated = ob_get_contents(); ob_end_clean(); // Restore the output buffer and return evaluated template if ($strAlreadyRendered) { print $strAlreadyRendered; } QApplication::$ProcessOutput = true; return $strTemplateEvaluated; } return null; }
/** * Used by custom RenderImage method to output the final image. * Uses $this->strImageType to determine type of image to be rendered. * This version is to be used when rendering an image using the Imagick library. * * If strPath is not set, output to the screen. If it is, save to strPath. * * @param Imagick $objFinalImage image as an instance of the Imagick class * @param string $strPath */ protected function RenderImageMagickHelper($objFinalImage, $strPath) { // Output the Image (if path isn't specified, output to buffer. Otherwise, output to disk) if (!$strPath) { $strPath = $this->strImagickTempFilePath . '/image_' . str_replace('.', '_', microtime(true)); // Output to a temporary location switch ($this->strImageType) { case QImageType::Gif: $strPath .= '.gif'; $objFinalImage->setImageFormat('gif'); header('Content-Type: image/gif'); break; case QImageType::AnimatedGif: $strPath .= '.gif'; $objFinalImage->setImageFormat('gif'); header('Content-Type: image/gif'); break; case QImageType::Jpeg: $strPath .= '.jpg'; $objFinalImage->setImageFormat('jpeg'); $objFinalImage->setCompressionQuality($this->intJpegQuality); header('Content-Type: image/jpeg'); break; default: $strPath .= '.png'; $objFinalImage->setImageFormat('png'); header('Content-Type: image/png'); break; } if ($this->strImageType == QImageType::AnimatedGif) { file_put_contents($strPath, $objFinalImage->GetImagesBlob()); } else { $objFinalImage->writeImage($strPath); } QApplication::$ProcessOutput = false; header('Cache-Control: cache'); header('Expires: Wed, 20 Mar 2019 05:00:00 GMT'); header('Pragma: cache'); print file_get_contents($strPath); unlink($strPath); } else { // Make Directory QApplication::MakeDirectory(dirname($strPath), 0777); // Output to Disk switch ($this->strImageType) { case QImageType::Gif: $objFinalImage->setImageFormat('gif'); break; case QImageType::AnimatedGif: $objFinalImage->setImageFormat('gif'); break; case QImageType::Jpeg: $objFinalImage->setImageFormat('jpeg'); $objFinalImage->setCompressionQuality($this->intJpegQuality); break; default: $objFinalImage->setImageFormat('png'); break; } $objFinalImage->writeImage($strPath); chmod($strPath, 0777); } $objFinalImage->Destroy(); }
protected function SetupContentType() { // TODO: Update Cache Parameters QApplication::$ProcessOutput = false; header('Cache-Control: cache'); header('Expires: Wed, 20 Mar 2019 05:00:00 GMT'); header('Pragma: cache'); if (!($strImageType = $this->strImageType)) { $strImageType = $this->strSourceImageType; } switch ($strImageType) { case QImageType::Jpeg: case QImageType::Png: case QImageType::Gif: header('Content-Type: image/' . $strImageType); break; default: throw new Exception('Invalid Image Type'); } }