public function __construct($file, $size, $color, $bgcolor = null) { $this->handle = imagepsloadfont($file); $this->size = $size; $this->color = $color; if ($bgcolor === null) { $this->bgcolor = $color; } else { $this->color = $color; } }
function printWordWrapped($image, $top, $left, $maxWidth, $font, $couleur, $text, $textSize, $align = "left", $hauteur_ligne = 0) { static $memps = array(); $fontps = false; // imageftbbox exige un float, et settype aime le double pour php < 4.2.0 settype($textSize, 'double'); // calculer les couleurs ici, car fonctionnement different selon TTF ou PS $black = imagecolorallocatealpha($image, hexdec("0x{" . substr($couleur, 0, 2) . "}"), hexdec("0x{" . substr($couleur, 2, 2) . "}"), hexdec("0x{" . substr($couleur, 4, 2) . "}"), 0); $grey2 = imagecolorallocatealpha($image, hexdec("0x{" . substr($couleur, 0, 2) . "}"), hexdec("0x{" . substr($couleur, 2, 2) . "}"), hexdec("0x{" . substr($couleur, 4, 2) . "}"), 127); // Gaffe, T1Lib ne fonctionne carrement pas bien des qu'on sort de ASCII // C'est dommage, parce que la rasterisation des caracteres est autrement plus jolie qu'avec TTF. // A garder sous le coude en attendant que ca ne soit plus une grosse bouse. // Si police Postscript et que fonction existe... if (false and strtolower(substr($font, -4)) == ".pfb" and function_exists("imagepstext")) { // Traitement specifique pour polices PostScript (experimental) $textSizePs = round(1.32 * $textSize); if (!($fontps = $memps["{$font}"])) { $fontps = imagepsloadfont($font); // Est-ce qu'il faut reencoder? Pas testable proprement, alors... // imagepsencodefont($fontps,find_in_path('polices/standard.enc')); $memps["{$font}"] = $fontps; } } $rtl_global = false; for ($i = 0; $i < spip_strlen($text); $i++) { $lettre = spip_substr($text, $i, 1); $code = rtl_mb_ord($lettre); if ($code >= 54928 && $code <= 56767 || $code >= 15707294 && $code <= 15711164) { $rtl_global = true; } } // split the text into an array of single words $words = explode(' ', $text); // les espaces foreach ($words as $k => $v) { $words[$k] = str_replace(array('~'), array(' '), $v); } if ($hauteur_ligne == 0) { $lineHeight = floor($textSize * 1.3); } else { $lineHeight = $hauteur_ligne; } $dimensions_espace = imageftbbox($textSize, 0, $font, ' ', array()); if ($dimensions_espace[2] < 0) { $dimensions_espace = imageftbbox($textSize, 0, $font, $line, array()); } $largeur_espace = $dimensions_espace[2] - $dimensions_espace[0]; $retour["espace"] = $largeur_espace; $line = ''; $lines = array(); while (count($words) > 0) { $mot = $words[0]; if ($rtl_global) { $mot = rtl_visuel($mot, $rtl_global); } $dimensions = imageftbbox($textSize, 0, $font, $line . ' ' . $mot, array()); $lineWidth = $dimensions[2] - $dimensions[0]; // get the length of this line, if the word is to be included if ($lineWidth > $maxWidth) { // if this makes the text wider that anticipated $lines[] = $line; // add the line to the others $line = ''; // empty it (the word will be added outside the loop) } $line .= ' ' . $words[0]; // add the word to the current sentence $words = array_slice($words, 1); // remove the word from the array } if ($line != '') { $lines[] = $line; } // add the last line to the others, if it isn't empty $height = count($lines) * $lineHeight; // the height of all the lines total // do the actual printing $i = 0; // Deux passes pour recuperer, d'abord, largeur_ligne // necessaire pour alignement right et center $largeur_max = 0; foreach ($lines as $line) { if ($rtl_global) { $line = rtl_visuel($line, $rtl_global); } $dimensions = imageftbbox($textSize, 0, $font, $line, array()); $largeur_ligne = $dimensions[2] - $dimensions[0]; if ($largeur_ligne > $largeur_max) { $largeur_max = $largeur_ligne; } } foreach ($lines as $i => $line) { if ($rtl_global) { $line = rtl_visuel($line, $rtl_global); } $dimensions = imageftbbox($textSize, 0, $font, $line, array()); $largeur_ligne = $dimensions[2] - $dimensions[0]; if ($align == "right") { $left_pos = $largeur_max - $largeur_ligne; } else { if ($align == "center") { $left_pos = floor(($largeur_max - $largeur_ligne) / 2); } else { $left_pos = 0; } } if ($fontps) { $line = trim($line); imagepstext($image, "{$line}", $fontps, $textSizePs, $black, $grey2, $left + $left_pos, $top + $lineHeight * $i, 0, 0, 0, 16); } else { imagefttext($image, $textSize, 0, $left + $left_pos, $top + $lineHeight * $i, $black, $font, trim($line), array()); } } $retour["height"] = $height; # + round(0.3 * $hauteur_ligne); $retour["width"] = $largeur_max; return $retour; }
function stroke($callback = false) { $xs = $this->x_size; $ys = $this->y_size; # Load the font for this chart. if ($this->font_type == "type1") { $this->font = imagepsloadfont($this->font_name); } elseif ($this->font_type == "ttf") { $this->font = imagettfloadfont($this->font_name); } else { $this->font = $this->font_name; } if ($xs == 0 || $ys == 0) { php3_error(E_ERROR, "Invalid X or Y sizes: (%s, %s)", $xs, $ys); } $im = imagecreate($xs, $ys); $this->image = $im; $bgcolor = $this->allocate_color($this->background_color); imagefilledrectangle($im, 0, 0, $xs, $ys, $bgcolor); list($xmin, $xmax) = $this->get_extrema(2); list($ymin, $ymax) = $this->get_extrema(1); $grace = ($ymax - $ymin) * 0.01; $ymin -= $grace; $ymax += $grace; if (!is_array($this->y_min)) { $ymin = $this->y_min; } if (!is_array($this->y_max)) { $ymax = $this->y_max; } if (!is_array($this->x_min)) { $xmin = $this->x_min; } if (!is_array($this->x_max)) { $xmax = $this->x_max; } if ($ymax == $ymin) { $ymax *= 1.01; $ymin *= 0.99; } if ($xmax == $xmin) { $xmax++; } if ($ymax == $ymin) { $ymax++; } $xoff = $this->left_margin; $yoff = $this->top_margin; $width = $xs - $this->left_margin - $this->right_margin; $height = $ys - $this->top_margin - $this->bottom_margin; $axes_color = $this->allocate_color($this->axes_color); if ($this->grid_under_plot) { # Draw the grid and the axes. $this->draw_y_axis($im, $ymin, $ymax, $xs, $ys, $height, $yoff, false, $axes_color); $this->draw_x_axis($im, $xmin, $xmax, $xs, $ys, $width, $xoff, false, $axes_color); } # Go through all the plots and stroke them. if ($callback != false) { $callback($im, $xmin, $xmax, $ymin, $ymax, $xoff, $yoff, $width, $height); } else { for ($i = 0; $i < sizeof($this->plots); $i++) { $plot = $this->plots[$i]; $plot->stroke($im, $xmin, $xmax, $ymin, $ymax, $xoff, $yoff, $width, $height); } } if (!$this->grid_under_plot) { # Draw the grid and the axes. $this->draw_y_axis($im, $ymin, $ymax, $xs, $ys, $height, $yoff, false, $axes_color); $this->draw_x_axis($im, $xmin, $xmax, $xs, $ys, $width, $xoff, false, $axes_color); } # The plotting may have plotted outside of the allocated # "framed" area (if autoscaling is not in use), so we # blank out the surrounding area. $margin = $this->allocate_color($this->margin_color); imagefilledrectangle($im, 0, 0, $xs, $this->top_margin - 1, $margin); imagefilledrectangle($im, $xs - $this->right_margin + 1, $this->top_margin - 1, $xs, $ys, $margin); imagefilledrectangle($im, 0, $ys - $this->bottom_margin + 1, $xs, $ys, $margin); imagefilledrectangle($im, 0, 0, $this->left_margin - 1, $ys, $margin); if (!$this->frame) { imageline($im, $this->left_margin, $this->top_margin, $this->left_margin, $ys - $this->bottom_margin + 3, $axes_color); imageline($im, $this->left_margin - 3, $ys - $this->bottom_margin, $xs - $this->right_margin, $ys - $this->bottom_margin, $axes_color); } else { imagerectangle($im, $this->left_margin, $this->top_margin, $xs - $this->right_margin, $ys - $this->bottom_margin, $this->allocate_color($this->border_color)); } # Put the text onto the axes. $this->draw_y_axis($im, $ymin, $ymax, $xs, $ys, $height, $yoff, true, $axes_color); $this->draw_x_axis($im, $xmin, $xmax, $xs, $ys, $width, $xoff, true, $axes_color); $title_color = $this->allocate_color("black"); # Draw the labels, if any. if ($this->y_label) { imagestringup($im, $this->font, 5, $ys / 2 + $this->string_pixels($this->y_label) / 2, $this->y_label, $title_color); } if ($this->x_label) { imagestring($im, $this->font, $xs / 2 - $this->string_pixels($this->x_label) / 2, $ys - 20, $this->x_label, $title_color); } # Draw the boorder. if ($this->border_color) { imagerectangle($im, 0, 0, $xs - 1, $ys - 1, $this->allocate_color($this->border_color)); } # Draw the title. for ($i = 0; $i < sizeof($this->title_text); $i++) { if (!strcmp($this->title_where[$i], "center")) { $tx = $xs / 2 - $this->string_pixels($this->title_text[$i]) / 2; } else { $tx = 0; } if ($this->font_type == "type1") { imagepstext($im, $this->title_text[$i], $this->font, 12, $this->allocate_color($this->title_color[$i]), $this->allocate_color("white"), $tx, 15); } elseif ($this->font_type == "internal") { imagestring($im, $this->font, $tx, 5, $this->title_text[$i], $this->allocate_color($this->title_color[$i])); } } if ($this->cache) { $this->put_cache($im); } $this->headers(); imagegif($im); imagedestroy($im); return true; }
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); }
private function load_font($font_name) { return imagepsloadfont(PROJECT_ROOT . '/project-specific/public-html/fonts/' . $font_name); }
EDI 00222738 EIP 77F53284 ntdll.77F53284 C 0 ES 0023 32bit 0(FFFFFFFF) P 0 CS 001B 32bit 0(FFFFFFFF) A 1 SS 0023 32bit 0(FFFFFFFF) Z 0 DS 0023 32bit 0(FFFFFFFF) S 0 FS 0038 32bit 7FFDE000(FFF) T 0 GS 0000 NULL D 0 O 0 LastErr ERROR_SUCCESS (00000000) EFL 00010212 (NO,NB,NE,A,NS,PO,GE,G) ST0 empty +UNORM 7D18 00560000 00561378 ST1 empty +UNORM 2402 0012BCD0 00000001 ST2 empty +UNORM 17CD 77F516F5 FFFFFFFF ST3 empty 0.0889391783750232330e-4933 ST4 empty +UNORM 0082 0017020C 77D43A5F ST5 empty +UNORM 0002 77D489FF 00000000 ST6 empty 10000.00000000000000 ST7 empty 10000.00000000000000 3 2 1 0 E S P U O Z D I FST 4000 Cond 1 0 0 0 Err 0 0 0 0 0 0 0 0 (EQ) FCW 027F Prec NEAR,53 Mask 1 1 1 1 1 1 Proof of concept below: */ if (!extension_loaded("gd")) { die("PHP_GD2 extension not loaded!"); } $buff = str_repeat("A", 9999); $res = imagepsloadfont($buff); echo "boom!!\n";
} else { $font_file = $fonts['default']; } $FLIR['font'] = $fonts_dir . $font_file; //die($FStyle['cFont']); if (!is_file($FLIR['font'])) { err('FONT_DOESNT_EXIST'); } if (in_array(strtolower(pathinfo($FLIR['font'], PATHINFO_EXTENSION)), array('pfb', 'pfm'))) { // pfm doesn't work // You can try uncommenting this line to see what kind of mileage you get. err('FONT_PS_UNSUPPORTED'); // PostScript will work as long as you don't set any kind of spacing... unless you are using Windows (PHP bug?). $FLIR['postscript'] = true; $FLIR['ps'] = array('kerning' => 0, 'space' => 0); if (false === @($FLIR['ps']['font'] = imagepsloadfont($FLIR['font']))) { err('FONT_PS_COULDNT_LOAD'); } } $FLIR['color'] = convert_color($FStyle['cColor']); if ($FLIR['bkg_transparent']) { $FLIR['bkgcolor'] = array('red' => abs($FLIR['color']['red'] - 100), 'green' => abs($FLIR['color']['green'] - 100), 'blue' => abs($FLIR['color']['blue'] - 100)); } else { $FLIR['bkgcolor'] = convert_color($FStyle['cBackground'], false, 'FFFFFF'); } $FLIR['opacity'] = is_number($FStyle['cOpacity'], true) ? $FStyle['cOpacity'] * 100 : 100; if ($FLIR['opacity'] > 100 || $FLIR['opacity'] < 0) { $FLIR['opacity'] = 100; } $FLIR['text'] = $_GET['text'] != '' ? str_replace(array('{amp}nbsp;', '{amp}', '{plus}'), array(' ', '&', '+'), trim($_GET['text'], "\t\n\r")) : 'null'; $FLIR['cache'] = get_cache_fn(md5(($FLIR['mode'] == 'wrap' ? $FLIR['maxwidth'] : '') . $FLIR['font'] . (print_r($FStyle, true) . $FLIR['text'])), $FLIR['output']);
function stroke($callback = false) { global $chart_use_png, $type1_font_encoding; $xs = $this->x_size; $ys = $this->y_size; // Load the font for this chart. if ($this->font_type == "type1") { $this->font = imagepsloadfont($this->font_name); imagepsencodefont($this->font, $type1_font_encoding); } elseif ($this->font_type == "ttf") { $this->font = imagettfloadfont($this->font_name); } else { $this->font = $this->font_name; } if ($xs == 0 || $ys == 0) { php3_error(E_ERROR, "Invalid X or Y sizes: (%s, %s)", $xs, $ys); } $im = imagecreate($xs, $ys); $this->image = $im; $bgcolor = $this->allocate_color($this->background_color); imagefilledrectangle($im, 0, 0, $xs, $ys, $bgcolor); list($xmin, $xmax) = $this->get_extrema(2); list($ymin, $ymax) = $this->get_extrema(1); $grace = ($ymax - $ymin) * 0.01; $ymin -= $grace; $ymax += $grace; if (!is_array($this->y_min)) { $ymin = $this->y_min; } if (!is_array($this->y_max)) { $ymax = $this->y_max; } if (!is_array($this->x_min)) { $xmin = $this->x_min; } if (!is_array($this->x_max)) { $xmax = $this->x_max; } if ($ymax == $ymin) { $ymax *= 1.01; $ymin *= 0.99; } if ($xmax == $xmin) { $xmax++; } if ($ymax == $ymin) { $ymax++; } $xoff = $this->left_margin; $yoff = $this->top_margin; $width = $xs - $this->left_margin - $this->right_margin; $height = $ys - $this->top_margin - $this->bottom_margin; $axes_color = $this->allocate_color($this->axes_color); if ($this->grid_under_plot) { // Draw the grid and the axes. $this->draw_y_axis($im, $ymin, $ymax, $xs, $ys, $height, $yoff, false, $axes_color); $this->draw_x_axis($im, $xmin, $xmax, $xs, $ys, $width, $xoff, false, $axes_color); } if (!$this->cleanup_after_plotting) { $margin = $this->allocate_color($this->margin_color); imagefilledrectangle($im, 0, 0, $xs, $this->top_margin - 1, $margin); imagefilledrectangle($im, $xs - $this->right_margin + 1, $this->top_margin - 1, $xs, $ys, $margin); imagefilledrectangle($im, 0, $ys - $this->bottom_margin + 1, $xs, $ys, $margin); imagefilledrectangle($im, 0, 0, $this->left_margin - 1, $ys, $margin); } // Go through all the plots and stroke them. if ($callback != false) { $callback($im, $xmin, $xmax, $ymin, $ymax, $xoff, $yoff, $width, $height); } else { for ($i = 0; $i < sizeof($this->plots); $i++) { $plot = $this->plots[$i]; $plot->stroke($im, $xmin, $xmax, $ymin, $ymax, $xoff, $yoff, $width, $height, &$this); } } if (!$this->grid_under_plot) { // Draw the grid and the axes. $this->draw_y_axis($im, $ymin, $ymax, $xs, $ys, $height, $yoff, false, $axes_color); $this->draw_x_axis($im, $xmin, $xmax, $xs, $ys, $width, $xoff, false, $axes_color); } // The plotting may have plotted outside of the allocated // "framed" area (if autoscaling is not in use), so we // blank out the surrounding area. if ($this->cleanup_after_plotting) { $margin = $this->allocate_color($this->margin_color); imagefilledrectangle($im, 0, 0, $xs, $this->top_margin - 1, $margin); imagefilledrectangle($im, $xs - $this->right_margin + 1, $this->top_margin - 1, $xs, $ys, $margin); imagefilledrectangle($im, 0, $ys - $this->bottom_margin + 1, $xs, $ys, $margin); imagefilledrectangle($im, 0, 0, $this->left_margin - 1, $ys, $margin); } if (!$this->frame) { imageline($im, $this->left_margin, $this->top_margin, $this->left_margin, $ys - $this->bottom_margin + 3, $axes_color); imageline($im, $this->left_margin - 3, $ys - $this->bottom_margin, $xs - $this->right_margin, $ys - $this->bottom_margin, $axes_color); } else { imagerectangle($im, $this->left_margin, $this->top_margin, $xs - $this->right_margin, $ys - $this->bottom_margin, $this->allocate_color($this->border_color)); } // Put the text onto the axes. $this->draw_y_axis($im, $ymin, $ymax, $xs, $ys, $height, $yoff, true, $axes_color); $this->draw_x_axis($im, $xmin, $xmax, $xs, $ys, $width, $xoff, true, $axes_color); $title_color = $this->allocate_color("black"); // Draw the labels, if any. if ($this->y_label) { if ($this->font_type == "type1") { imagepstext($im, $this->y_label, $this->font, $this->font_size, $this->allocate_color($title_color), $this->allocate_color("white"), 15, (int) ($ys / 2 + $this->string_pixels($this->y_label) / 2), 0, 0, 90, 16); } else { imagestringup($im, $this->font, 5, $ys / 2 + $this->string_pixels($this->y_label) / 2, $this->y_label, $title_color); } } if ($this->x_label) { imagestring($im, $this->font, $xs / 2 - $this->string_pixels($this->x_label) / 2, $ys - 20, $this->x_label, $title_color); } // Draw the boorder. if ($this->border_color) { imagerectangle($im, 0, 0, $xs - 1, $ys - 1, $this->allocate_color($this->border_color)); } // Draw the title. $tx = "noval"; for ($i = 0; $i < sizeof($this->title_text); $i++) { if ($this->font_type == "type1") { if ($tx == "noval") { if (!strcmp($this->title_where[$i], "center")) { list($llx, $lly, $urx, $ury) = imagepsbbox($this->title_text[$i], $this->font, $this->font_size); $tx = $xs / 2 - ($urx - $llx) / 2; } else { $tx = 0; } } imagepstext($im, $this->title_text[$i], $this->font, $this->font_size, $this->allocate_color($this->title_color[$i]), $this->allocate_color("white"), (int) $tx, 15, 0, 0, 0, 16); } elseif ($this->font_type == "internal") { if (!strcmp($this->title_where[$i], "center")) { $tx = $xs / 2 - $this->string_pixels($this->title_text[$i]) / 2; } else { $tx = 0; } imagestring($im, $this->font, $tx, 5, $this->title_text[$i], $this->allocate_color($this->title_color[$i])); } } // Draw the legend. if (sizeof($this->legends) != 0) { $maxlength = 0; foreach ($this->legends as $legend) { $length = $this->real_string_pixels($legend[0]); if ($length > $maxlength) { $maxlength = $length; } } if ($this->legend_placement == "r") { $x = (int) ($this->x_size - $this->right_margin - $maxlength - 20); $y = (int) ($this->top_margin + 20); } else { $x = (int) ($this->right_margin + 40); $y = (int) ($this->top_margin + 20); } $lmargin = $this->legend_margin; // Draw a box behind the legend. if ($this->legend_background_color) { imagefilledrectangle($im, $x - $lmargin, $y - $lmargin, $x + $lmargin + $maxlength, $y + $lmargin + ($this->font_size + 2) * sizeof($this->legends), $this->allocate_color($this->legend_background_color)); } if ($this->legend_border_color) { imagerectangle($im, $x - $lmargin, $y - $lmargin, $x + $lmargin + $maxlength, $y + $lmargin + ($this->font_size + 2) * sizeof($this->legends), $this->allocate_color($this->legend_border_color)); } foreach ($this->legends as $legend) { $this->draw_text($legend[0], $legend[1], $x, $y); $y += $this->font_size + 2; } } // Rescale the image before outputting, if requested. if ($this->output_x_size) { global $gd2; $owidth = $this->output_x_size; $oheight = $this->output_x_size; $om = imagecreate($owidth, $oheight); if ($gd2) { imagecopyresampled($om, $im, 0, 0, 0, 0, $owidth, $oheight, $xs, $ys); } else { imagecopyresized($om, $im, 0, 0, 0, 0, $owidth, $oheight, $xs, $ys); } $im = $om; } // This statement usually doesn't return. if ($this->cache) { $this->put_cache($im); } $this->headers(); if ($chart_use_png) { imagepng($im); } else { imagegif($im); } imagedestroy($im); return true; }
<?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);