public function __destruct() { imagepsfreefont($this->handle); $this->handle = 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); }
gd_alpha(); imagefilledrectangle($image, $offset_left, 0, imagesx($image), imagesy($image), gd_bkg()); imagettftext($image, $FLIR['size_pts'], 0, $bounds['xOffset'], $REAL_HEIGHT_BOUNDS['yOffset'], gd_color(), $FLIR['font'], $FLIR['text']); render_text($bounds); break; case 'spacer': if (false === @($image = imagecreatetruecolor($SPACE_BOUNDS['width'] * $SPACES_COUNT, 1))) { err('COULD_NOT_CREATE'); } imagesavealpha($image, true); imagealphablending($image, false); imagefilledrectangle($image, 0, 0, imagesx($image), imagesy($image), gd_bkg()); break; } if ($FLIR['postscript']) { imagepsfreefont($FLIR['ps']['font']); } if (false !== $image) { switch ($FLIR['output']) { default: case 'png': imagepng($image, $FLIR['cache']); break; case 'gif': imagegif($image, $FLIR['cache']); break; case 'jpg': $qual = is_number($FStyle['quality']) ? $FStyle['quality'] : 90; imagejpeg($image, $FLIR['cache'], $qual); break; }
private function free_font_memory() { imagepsfreefont($this->font); imagepsfreefont($this->stated_intention_font); imagepsfreefont($this->character_name_font); imagepsfreefont($this->frame_name_font); }
<?php define("WIDTH", 600); define("HEIGHT", 100); define("F_SIZE", 40); define("F_ANGLE", 0); define("F_FONT", "/usr/share/fonts/default/Type1/n019003l.pfb"); $img = imagecreate(WIDTH, HEIGHT); $white = imagecolorallocate($img, 255, 255, 255); $black = imagecolorallocate($img, 0, 0, 0); $font = imagepsloadfont(F_FONT); $start_x = 10; $start_y = (int) HEIGHT / 2; $text = "PHP Developer's Handbook"; imagerectangle($img, 0, 0, WIDTH - 1, HEIGHT - 1, $black); imagepstext($img, $text, $font, F_SIZE, $black, $white, $start_x, $start_y, 0, 0, F_ANGLE, 16); imagepsfreefont($font); header("Content-Type: image/png"); imagepng($img);