PHP.mk документација

imagefontheight

Почист и полокален преглед на PHP референцата, со задржана структура од PHP.net и подобра читливост за примери, секции и белешки.

function.imagefontheight.php PHP.net прокси Преводот се освежува
Оригинал на PHP.net
Патека function.imagefontheight.php Локална патека за оваа страница.
Извор php.net/manual/en Оригиналниот HTML се реупотребува и локално се стилизира.
Режим Прокси + превод во позадина Кодовите, табелите и белешките остануваат читливи во истиот тек.
imagefontheight

Референца за `function.imagefontheight.php` со подобрена типографија и навигација.

function.imagefontheight.php

imagefontheight

(PHP 4, PHP 5, PHP 7, PHP 8)

imagefontheightДобиј висина на фонт

= NULL

imagefontheight(GdFont|int $font): int

Враќа пикселска висина на карактер во наведениот фонт.

Параметри

font

вертикално на дадените координати. GdFont инстанца, вратена од imageloadfont().

Вратени вредности

Враќа пикселска висина на фонтот.

Дневник на промени

Верзија = NULL
8.1.0 На font Идентификатор на боја создаден со GdFont параметарот сега прифаќа и intинстанца и int беше прифатено.

Примери

Пример #1 Користење imagefontheight() на вградени фонтови

<?php
echo 'Font height: ' . imagefontheight(4);
?>

Горниот пример ќе прикаже нешто слично на:

Font height: 16

Пример #2 Користење imagefontheight() заедно со imageloadfont()

<?php
// Load a .gdf font
$font = imageloadfont('anonymous.gdf');

echo
'Font height: ' . imagefontheight($font);
?>

Горниот пример ќе прикаже нешто слично на:

Font height: 43

Види Исто така

Белешки од корисници 1 белешка

dev на numist dot net
21 години пред
This library function is very useful for variable-sized images that only contain text, like this function that I use to output error messages that accumulate and cause a fatal error in my thumbnailer:

<?php
function errimg($error) {
   // $error is an array of error messages, each taking up one line
   // initialization
   $font_size = 2;
   $text_width = imagefontwidth($font_size);
   $text_height = imagefontheight($font_size);
   $width = 0;
   // the height of the image will be the number of items in $error
   $height = count($error);

   // this gets the length of the longest string, in characters to determine
   // the width of the output image
   for($x = 0; $x < count($error); $x++) {
      if(strlen($error[$x]) > $width) {
         $width = strlen($error[$x]);
      }
   }
   
   // next we turn the height and width into pixel values
   $width = $width * $text_width;
   $height = $height * $text_height;
   
   // create image with dimensions to fit text, plus two extra rows and
   // two extra columns for border
   $im = imagecreatetruecolor($width + ( 2 * $text_width ), 
                              $height + ( 2 * $text_height ) );
   if($im) {
      // image creation success
      $text_color = imagecolorallocate($im, 233, 14, 91);
      // this loop outputs the error message to the image
      for($x = 0; $x < count($error); $x++) {
         // imagestring(image, font, x, y, msg, color);
         imagestring($im, $font_size, $text_width, 
                     $text_height + $x * $text_height, $error[$x], 
                     $text_color);
      }
      // now, render your image using your favorite image* function 
      // (imagejpeg, for instance)
      out($im, array(), $error);
   } else {
      // image creation failed, so just dump the array along with extra error
      $error[] = "Is GD Installed?";
      die(var_dump($error));
   }
}
?>

The function expects an array of error messages to be passed in, and then outputs an image containing the contents of the array.  This is especially useful if your code is contained in an html page that will display rexes if the images do not render correctly.

This function displays the array in image form with index 0 at the top, and the highest index at the bottom.

You have to write out() yourself though, see imagejpeg, imagepng, etc for good ideas on how to write a decent output function.
Навигација

Прелистувај сродни теми и функции.

На оваа страница

Автоматски outline од активната документација.

Насловите ќе се појават тука по вчитување.

Попрегледно читање

Примерите, changelog табелите и user notes се визуелно издвоени за да не се губат во долгата содржина.

Брз совет Користи го outline-от Скокни директно на главните секции од активната страница.
Извор Оригиналниот линк останува достапен Кога ти треба целосен upstream context, отвори го PHP.net во нов tab.