Autor Zpráva
juraj
Profil
Zdravím
Ako mám upraviť kód, aby sa vety zalomili pomocou príkazu br?
<?php
/*
Credits: BitRepository
URL: http://www.bitrepository.com/web-programming/php/how-to-center-a-text-on-an-image-using-gd.html
*/
 
$width = 400;
$height = 100;
 
$im = ImageCreate($width, $height);
 
// white background and blue text
$bg = ImageColorAllocate($im, 255, 255, 255);
 
// grey border
$border = ImageColorAllocate($im, 207, 199, 199);
ImageRectangle($im, 0, 0, $width - 1, $height - 1, $border);
 
 
$text = 'Tu je moja prva veta.<br>Dalsia veta by mala byt yalomena.';
 
$textcolor = ImageColorAllocate($im, 0, 0, 255);
 
// Font Size
$font = 3;
 
$font_width = ImageFontWidth($font);
$font_height = ImageFontHeight($font);
 
/* 
-----------
Text Width 
-----------
*/
 
$text_width = $font_width * strlen($text);
 
// Position to align in center
$position_center = ceil(($width - $text_width) / 2);
 
/* 
-----------
Text Height 
-----------
*/
 
$text_height = $font_height;
 
// Position to align in abs middle
$position_middle = ceil(($height - $text_height) / 2);
 
/* 
-----------------
Write the string
-----------------
*/
 
$image_string = ImageString($im, $font, $position_center, $position_middle, $text, $textcolor);
 
/* 
--------------------------------------
Output our image (PNG in our example)
--------------------------------------
*/
header("Content-type: image/png");
ImagePNG($im);
?>
Taps
Profil
juraj:
Vyzkoušej níže uvedené
<?
$width = 400;
$height = 100;

$im = ImageCreate($width, $height);

// white background and blue text
$bg = ImageColorAllocate($im, 255, 255, 255);

// grey border
$border = ImageColorAllocate($im, 207, 199, 199);
ImageRectangle($im, 0, 0, $width - 1, $height - 1, $border);


$text = 'Tu je moja prva veta.<br>Dalsia veta by mala byt yalomena.<br>zalomeni textu<br>';
$lines = explode('<br>', $text);
$textcolor = ImageColorAllocate($im, 0, 0, 255);

// Font Size
$font = 3;

$font_width = ImageFontWidth($font);
$font_height = ImageFontHeight($font);
$pocet_radku = count($lines);

/* 
-----------
Text Width 
-----------
*/

$text_width = $font_width * 30;

// Position to align in center
$position_center = ceil(($width - $text_width) / 2);

/* 
-----------
Text Height 
-----------
*/

$text_height = $font_height;

// Position to align in abs middle
$position_middle = ceil(($height - $text_height) / $pocet_radku );

/* 
-----------------
Write the string
-----------------
*/
foreach ($lines as $line)
{

    $image_string = ImageString($im, $font, $position_center, $position_middle, $line, $textcolor);

    // Increment Y so the next line is below the previous line
    $position_middle+= 23;
}


header("Content-type: image/png");
ImagePNG($im);
?>
juraj
Profil
Dakujem funguje to

Vaše odpověď


Prosím používejte diakritiku a interpunkci.

Ochrana proti spamu. Napište prosím číslo dvě-sta čtyřicet-sedm:

0