public function writeText($image, $x, $y, $text, $angle = 0) { if ($image->isTrueColor()) { $image->alphaBlending(true); } imagepstext($image->getHandle(), $text, $this->handle, $this->size, $this->color, $this->bgcolor, $x, $y, 0, 0, $angle, 4); }
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 draw_y_axis($im, $ymin, $ymax, $xs, $ys, $height, $yoff, $do_text, $axes_color) { $grid_color = $this->allocate_color($this->grid_color); # Compute the Y axis. if (!strcmp($this->axes, "y") || !strcmp($this->axes, "xy")) { $ticks = $this->get_ticks($ymin, $ymax); $step = ceil(sizeof($ticks) / (($ys - $this->top_margin - $this->bottom_margin) / $this->tick_distance)); for ($i = 0; $i < sizeof($ticks); $i += 1) { $y = $ticks[$i]; $yt = $yoff + $height - ($y * 1.0 - $ymin) / ($ymax - $ymin) * $height; if ($do_text) { if (!($i % $step)) { if ($y == 0) { $yst = 0; } elseif (abs($y) < 1) { $yst = sprintf("%.2f", $y); } elseif (!($y % 1000000)) { $yst = sprintf("%sM", $y / 1000000); } elseif (!($y % 1000)) { $yst = sprintf("%sk", $y / 1000); } else { $yst = $y; } if ($this->font_type == "type1") { imagepstext($im, $yst, $this->font, 10, $axes_color, $this->allocate_color("white"), $this->left_margin - 3 - strlen($yst) * 6, $yt + 4, 0, 0, 0, 16); } elseif ($this->font_type == "internal") { imagestring($im, $this->font, $this->left_margin - 3 - strlen($yst) * 6, $yt - 7, $yst, $axes_color); } imageline($im, $this->left_margin - 3, $yt, $this->left_margin, $yt, $axes_color); } else { imageline($im, $this->left_margin - 1, $yt, $this->left_margin, $yt, $axes_color); } } else { imageline($im, $this->left_margin + 1, $yt, $xs - $this->right_margin, $yt, $grid_color); } } if (!$do_text && $this->marked_grid_color) { $y = $this->marked_grid_point; $yt = $yoff + $height - ($y * 1.0 - $ymin) / ($ymax - $ymin) * $height; imageline($im, $this->left_margin + 1, $yt, $xs - $this->right_margin, $yt, $this->allocate_color($this->marked_grid_color)); } } }
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 center_text($text, $font, $background_color, $bounding_width, $bounding_height) { /* * get the left lower corner and the right upper */ list($lx, $ly, $rx, $ry) = imagepsbbox($text, $this->font, $this->font_size); /* * calculate the size of the text */ $textW = $rx - $lx; $textH = $ry - $ly; /* * Calculate the positions */ $positionLeft = ($bounding_width - $textW) / 2; $positionTop = ($bounding_height - $textH) / 2; /* * Add some text */ imagepstext($this->image, $text, $font, $this->font_size, $this->font_color, $this->background_color, $positionLeft, $positionTop, 0, 0, 0, 16); }
function stroke($im, $xmin, $xmax, $ymin, $ymax, $xoff, $yoff, $width, $height, &$chart) { $color = rgb_allocate($im, $this->color); $style = $this->style; $param = $this->param; $ycoords = $this->coords[0]; $end = sizeof($ycoords); if (!strcmp($style, "points")) { $style = 1; } elseif (!strcmp($style, "lines")) { $style = 2; } elseif (!strcmp($style, "impulse")) { $style = 3; } elseif (!strcmp($style, "circle")) { $style = 4; if ($param) { if (is_array($param)) { $circle_size = $param[0]; $position_style = $param[1]; } else { $circle_size = $param; } } else { $circle_size = 10; } } elseif (!strcmp($style, "cross")) { $style = 5; if ($param) { $cross_size = $param / 2; } else { $cross_size = 5; } } elseif (!strcmp($style, "fill")) { $style = 6; $this->dimension = 1; } elseif (!strcmp($style, "square")) { $style = 7; } elseif (!strcmp($style, "triangle")) { if ($this->to_color) { $dcolor = $this->to_color; } else { $dcolor = $this->color; } $dcolor = rgb_allocate($im, $dcolor); $style = 9; } elseif (!strcmp($style, "box")) { if ($this->to_color) { $to_color = $this->to_color; } else { $to_color = $this->color; } $tcolors = rgb_allocate_colors($im, rgb_gradient_color($this->color, $to_color, 3)); $style = 10; } elseif (!strcmp($style, "gradient") || !strcmp($style, "fillgradient")) { // Calculate the gradient. if (!strcmp($style, "gradient")) { $style = 8; } else { $style = 12; $this->dimension = 1; } $gradient_style = $this->param & 1; $gradient_updown = $this->param & 2; $gradient_direction = $this->param & 4; $gradient_horizontal = $this->param & 8; if ($gradient_direction == 0) { $fcol = rgb_color($this->color); $tcol = rgb_color($this->to_color); } else { $tcol = rgb_color($this->color); $fcol = rgb_color($this->to_color); } // We use at most 220 different colors. $numcols = 110; $rfactor = ($tcol[0] - $fcol[0]) / $numcols; $gfactor = ($tcol[1] - $fcol[1]) / $numcols; $bfactor = ($tcol[2] - $fcol[2]) / $numcols; if ($gradient_horizontal) { $h = $width + 2; } else { $h = $height + 2; } $col_factor = $numcols / $h; $prev = -1; for ($i = 0; $i < $h; $i++) { $num = floor($col_factor * ($h - $i)); $rnum = floor($fcol[0] + $num * $rfactor); $gnum = floor($fcol[1] + $num * $gfactor); $bnum = floor($fcol[2] + $num * $bfactor); if ($num == $prev) { $colors[$i] = $col; } else { $col = rgb_allocate($im, sprintf("#%02x%02x%02x", $rnum, $gnum, $bnum)); $colors[$i] = $col; } $prev = $num; } } elseif (!strcmp($style, "text")) { $style = 11; $textnum = 0; $position_style = $param; $circle_size = 10; } if ($end == 1 && $position_style == "last") { $y = $ycoords[0]; $xt = $xoff + $width; $yt = $yoff + $height - ($y * 1.0 - $ymin) / ($ymax - $ymin) * $height; if ($style == 11) { imagepstext($im, $this->texts[0], $chart->font, $chart->font_size, $chart->allocate_color("red"), $chart->allocate_color("white"), (int) ($xt - $chart->real_string_pixels($this->texts[0])), (int) $yt, 0, 0, 0, 16); } else { imagearc($im, $xt, $yt, $circle_size, $circle_size, 0, 360, $color); } return $color; } for ($i = 0; $i < $end; $i++) { $y = $ycoords[$i]; if (!is_string($y) || strcmp($y, "noplot")) { if ($this->dimension == 1) { $x = $i; } else { $x = $this->coords[1][$i]; } $xt = $xoff + ($x - $xmin) / ($xmax - $xmin) * $width; $yt = $yoff + $height - ($y * 1.0 - $ymin) / ($ymax - $ymin) * $height; if (!isset($pxt)) { $pxt = $xt; } if (!isset($pyt)) { $pyt = $yt; } if ($style == 1) { imageline($im, $xt, $yt, $xt, $yt, $color); } elseif ($style == 2) { imageline($im, $pxt, $pyt, $xt, $yt, $color); } elseif ($style == 3) { imageline($im, $xt, $yoff + $height, $xt, $yt, $color); } elseif ($style == 4) { imagearc($im, $xt, $yt, $circle_size, $circle_size, 0, 360, $color); } elseif ($style == 5) { imageline($im, $xt - $cross_size, $yt - $cross_size, $xt + $cross_size, $yt + $cross_size, $color); imageline($im, $xt + $cross_size, $yt - $cross_size, $xt - $cross_size, $yt + $cross_size, $color); } elseif ($style == 6) { // Fill if (!isset($poyt)) { $poyt = $oyt; } $oyt = $yoff + $height - ($this->coords[1][$i] * 1.0 - $ymin) / ($ymax - $ymin) * $height; for ($j = $pxt; $j <= $xt; $j++) { imageline($im, $j, $oyt, $j, $yt, $color); } $poyt = $oyt; } elseif ($style == 7) { imageline($im, $pxt, $pyt, $pxt, $yt, $color); imageline($im, $pxt, $yt, $xt, $yt, $color); } elseif ($style == 8) { // gradient // We plot down from the value to the bottom of the chart. // There might be several pixels width of stuff to be plotted, // so we first calculate the gradient of the top of the chart // between the two points. So the top of the "gradient" // chart will resemble the "lines" chart, not the "square" // chart. if ($xt == $pxt) { $b = 0; } else { $b = ($yt - $pyt) / ($xt - $pxt); } $a = $yt - $b * $xt; for ($x = $pxt; $x <= $xt; $x++) { $firsty = $a + $b * $x; if ($gradient_updown == 0) { for ($y = $a + $b * $x; $y < $yoff + $height; $y++) { if ($gradient_style && !$gradient_horizontal) { $coff = $y - $firsty; } elseif (!$gradient_style && !$gradient_horizontal) { $coff = $y - $yoff; } elseif ($gradient_style && $gradient_horizontal) { $coff = $x - $firstx; } elseif (!$gradient_style && $gradient_horizontal) { $coff = $x - $xoff; } imagesetpixel($im, $x, $y, $colors[$coff]); } } else { for ($y = $a + $b * $x; $y > $yoff; $y--) { if ($gradient_style && !$gradient_horizontal) { $coff = $firsty - $y; } elseif (!$gradient_style && !$gradient_horizontal) { $coff = $y - $yoff; } elseif ($gradient_style && $gradient_horizontal) { $coff = $firstx - $x; } elseif (!$gradient_style && $gradient_horizontal) { $coff = $x - $xoff; } imagesetpixel($im, $x, $y, $colors[$coff]); } } } } elseif ($style == 12) { // fillgradient if (!isset($poyt)) { $poyt = $oyt; } $oyt = $yoff + $height - ($this->coords[1][$i] * 1.0 - $ymin) / ($ymax - $ymin) * $height; for ($x = $pxt; $x <= $xt; $x++) { if ($oyt < $yt) { $miny = $oyt; $maxy = $yt; } else { $miny = $yt; $maxy = $oyt; } $firsty = $oyt; if ($gradient_updown == 0) { for ($y = $miny; $y < $maxy; $y++) { if ($gradient_style == 1) { imagesetpixel($im, $x, $y, $colors[$y - $firsty]); } else { imagesetpixel($im, $x, $y, $colors[$y - $yoff]); } } } else { for ($y = $maxy; $y > $miny; $y--) { if ($gradient_style == 1) { imagesetpixel($im, $x, $y, $colors[$firsty - $y]); } else { imagesetpixel($im, $x, $y, $colors[$y - $yoff]); } } } } $poyt = $oyt; } elseif ($style == 9) { // Triangle imageline($im, $xt - 3, $yt + 3, $xt + 3, $yt + 3, $dcolor); imageline($im, $xt - 3, $yt + 2, $xt + 3, $yt + 2, $color); imageline($im, $xt - 2, $yt + 1, $xt + 2, $yt + 1, $color); imageline($im, $xt - 2, $yt, $xt + 2, $yt, $color); imageline($im, $xt - 1, $yt - 1, $xt + 1, $yt - 1, $color); imageline($im, $xt - 1, $yt - 2, $xt + 1, $yt - 2, $color); imagesetpixel($im, $xt, $yt - 3, $color); imagesetpixel($im, $xt, $yt - 4, $color); imageline($im, $xt + 4, $yt + 3, $xt + 1, $yt - 4, $dcolor); } elseif ($style == 10) { // Box imageline($im, $xt - 2, $yt - 2, $xt + 2, $yt - 2, $tcolors[0]); imageline($im, $xt - 2, $yt - 1, $xt - 2, $yt + 2, $tcolors[0]); imageline($im, $xt - 1, $yt - 1, $xt + 1, $yt - 1, $tcolors[1]); imageline($im, $xt - 1, $yt, $xt + 1, $yt, $tcolors[1]); imageline($im, $xt - 1, $yt + 1, $xt + 1, $yt + 1, $tcolors[1]); imageline($im, $xt - 1, $yt + 2, $xt + 2, $yt + 2, $tcolors[2]); imageline($im, $xt + 2, $yt - 1, $xt + 2, $yt + 1, $tcolors[2]); } elseif ($style == 11) { imagestring($im, $this->font, $xt, $yt, $this->texts[$textnum++], $color); } $pxt = $xt; $pyt = $yt; } } return $color; }
function render_text($bounds, $text = NULL, $img = NULL, $realheight = NULL) { global $FLIR; if (!is_null($realheight)) { $REAL_HEIGHT_BOUNDS = $realheight; } else { global $REAL_HEIGHT_BOUNDS; } if (is_null($img)) { global $image; } else { $image = $img; } if (is_null($text)) { $text = $FLIR['postscript'] ? $FLIR['original_text'] : $FLIR['text']; } if ($FLIR['postscript']) { imagepstext($image, $text, $FLIR['ps']['font'], $FLIR['size'], gd_color($image), imagecolorallocatealpha($image, $FLIR['bkgcolor']['red'], $FLIR['bkgcolor']['green'], $FLIR['bkgcolor']['blue'], 127), $bounds['xOffset'], $REAL_HEIGHT_BOUNDS['yOffset'], $FLIR['ps']['space'], $FLIR['ps']['kerning'], 0, $FLIR['size'] < 20 ? 16 : 4); } else { imagettftext($image, $FLIR['size_pts'], 0, $bounds['xOffset'], $REAL_HEIGHT_BOUNDS['yOffset'], gd_color($image), $FLIR['font'], $text); } }
<?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);
$angle = $possible_angle[rand(0, count($possible_angle) - 1)]; $t_x = $t_x + rand(24, 27); $t_y = rand(33, 28); $char = substr($captcha_text, $i, 1); imagettftext($img, $ttfsize, $angle, $t_x, $t_y, $color, $ttf, $char); } } elseif (function_exists('imagepstext')) { // This function is only available if PHP is compiled using --with-t1lib[=DIR]. $pfbsize = 34; $pfb = ImagePsLoadFont(DIR_FS_SMARTY . 'catalog/templates/' . SELECTED_TPL . '/includes/captcha/captcha.pfb'); for ($i = 0; $i < $strlen; $i++) { $angle = $possible_angle[rand(0, count($possible_angle) - 1)]; $t_x = $t_x + rand(24, 27); $t_y = rand(33, 28); $char = substr($captcha_text, $i, 1); imagepstext($img, $char, $pfb, $pfbsize, $color, $background, $t_x, $t_y, 0, 0, $angle); } } else { imagedestroy($img); $img = imagecreate(140, 40); $color = ImageColorAllocate($img, 255, 0, 255); $background = ImageColorAllocate($img, 0, 255, 0); imagefill($img, 0, 0, $background); for ($i = 0; $i < $strlen; $i++) { $pfb = 5; $t_x = $t_x + imagefontwidth($pfb) * 3; $t_y = 12; $char = substr($captcha_text, $i, 1); imagestring($img, $pfb, $t_x, $t_y, $char, $color); } }