 |
Forum PHP Romania - Discutii despre PHP, MySQL, Javascript, AJAX, etc Comunitatea PHP Romania
|
| Subiectul anterior :: Subiectul următor |
| Autor |
Mesaj |
soryn4u
Data înscrierii: 12/Feb/2007
Mesaje: 150
|
| Trimis: Lun Feb 04, 2008 3:20 pm Titlul subiectului: word wrap with imagecreate |
|
|
a reusit cinveva pana acuma sa puna textul pe mai multe randuri intro imagine
am incercat sa unesc 2 coduri imagecreate si wordwrap
dar nici un rezultat:
Cod:
<?php
header("Content-type: image/png");
//word wrap
$text = "cum naiba sa fac sa impart acest text in 3 randuri ca ..... sa vad tot textul pe toata imaGINEA.";
$newtext = wordwrap($text, 20, "<br />\n");
//image create
$im = @imagecreate(400, 100)
or die("Cannot Initialize new GD image stream");
$background_color = imagecolorallocate($im, 0, 0, 0);
$text_color = imagecolorallocate($im, 72, 246, 38);
imagestring($im, 1, 5, 5, "$newtext", $text_color);
imagepng($im);
imagedestroy($im);
?> [/code] |
|
| Sus |
|
kleampa
Data înscrierii: 10/Iul/2005
Mesaje: 1988
Locație: Bucuresti
|
| Trimis: Lun Feb 04, 2008 5:26 pm Titlul subiectului: |
|
|
| scoate <br /> si lasa decat /n |
|
| Sus |
|
soryn4u
Data înscrierii: 12/Feb/2007
Mesaje: 150
|
| Trimis: Lun Feb 04, 2008 5:43 pm Titlul subiectului: |
|
|
tie iti merge ???
ca mie nu |
|
| Sus |
|
cigraphics
Data înscrierii: 08/Iul/2006
Mesaje: 233
Locație: Pitesti
|
| Trimis: Lun Feb 04, 2008 11:30 pm Titlul subiectului: |
|
|
poate asta te ajuta
Cod: I like this better than "tjpoe at cableaz dot com"'s function for wrapping text to fit width (auto-adjusts height as needed) since it doesn't only do 1 word per line.
function make_wrapped_txt($txt, $color=000000, $space=4, $font=4, $w=300) {
if (strlen($color) != 6) $color = 000000;
$int = hexdec($color);
$h = imagefontheight($font);
$fw = imagefontwidth($font);
$txt = explode("\n", wordwrap($txt, ($w / $fw), "\n"));
$lines = count($txt);
$im = imagecreate($w, (($h * $lines) + ($lines * $space)));
$bg = imagecolorallocate($im, 255, 255, 255);
$color = imagecolorallocate($im, 0xFF & ($int >> 0x10), 0xFF & ($int >> 0x8), 0xFF & $int);
$y = 0;
foreach ($txt as $text) {
$x = (($w - ($fw * strlen($text))) / 2);
imagestring($im, $font, $x, $y, $text, $color);
$y += ($h + $space);
}
header('Content-type: image/jpeg');
die(imagejpeg($im));
}
Link
Cod: http://php.net/imagestring |
|
| Sus |
|
PHPRomania Bot
Bot Member
Data înscrierii: 27/Dec/2007
Mesaje: 1
Locaţie: Server Google |
| Trimis: Mie Dec 26, 2007 7:01 pm Titlul subiectului: Ad |
|
|
|
|
|
| Sus |
|
| |
|