Autor | Zpráva | ||
---|---|---|---|
spacek145 Profil |
<?php $prislovi = array( "Text v Array", ); $index = array_rand($prislovi); ?> <?php $width = 640; $height = 20; $text = $prislovi[$index]; $fontsize = 5; $img = imagecreate($width, $height); // Transparent background $black = imagecolorallocate($img, 0, 0, 0); imagecolortransparent($img, $black); // Cernej text $black = imagecolorallocate($img, 0, 0, 0); imagestring($img, $fontsize, 0, 0, $text, $black); header('Content-type: image/png'); imagepng($img); imagedestroy($img); ?> Dobrý den, jak zde v tomto scriptu změním FONT v generovaném obrázku... třeba na Arial? :P |
||
ShiraNai7 Profil |
Použij funkci imagefttext(), u té můžeš použít vlastní font.
|
||
Virtus Profil |
nebo tímhle možná taky: imageloadfont()
|
||
spacek145 Profil |
#4 · Zasláno: 22. 3. 2013, 22:12:55
To mi tam právě nejde zakomponovat :( Můžete mi to pomoci zasadit do kodu?
|
||
Virtus Profil |
#5 · Zasláno: 22. 3. 2013, 22:29:49
S funkcí imagefttext() asi takhle:
<?php $prislovi = array( "Text v Array", ); $index = array_rand($prislovi); ?> <?php $width = 640; $height = 20; $text = $prislovi[$index]; $fontsize = 5; $img = imagecreate($width, $height); // Transparent background $black = imagecolorallocate($img, 0, 0, 0); imagecolortransparent($img, $black); $font_file = './arial.ttf'; // je potřeba nastavit cestu k fontu if(!file_exists($font_file)){ $text = "Nebyl nalezen font"; } // Cervenej text $red = imagecolorallocate($img, 255, 0, 0); imagefttext($img, $fontsize, 0, 0, 0, $red, $font_file, $text); header('Content-type: image/png'); imagepng($img); imagedestroy($img); ?> a s funkcí imageloadfont() asi takhle: <?php $prislovi = array( "Text v Array", ); $index = array_rand($prislovi); ?> <?php $width = 640; $height = 20; $text = $prislovi[$index]; $img = imagecreate($width, $height); // Transparent background $black = imagecolorallocate($img, 0, 0, 0); imagecolortransparent($img, $black); $font = imageloadfont('./myfont.gdf'); imagestring($img, $font, 0, 0, $text, $black); header('Content-type: image/png'); imagepng($img); imagedestroy($img); ?> |
||
spacek145 Profil |
#6 · Zasláno: 22. 3. 2013, 22:43:39
A ještě jeden dotaz:
<?php header('Content-Type: image/png'); $im = imagecreatetruecolor(640, 25); $grey = imagecolorallocate($im, 128, 128, 128); imagefilledrectangle($im, 0, 0, 399, 29); $text = $prislovi[$index]; $font = 'OpenSans.ttf'; imagettftext($im, 13, 0, 11, 21, $grey, $font, $text); imagepng($im); imagedestroy($im); ?> jak u tohohle udělám transparentní pozadíčko? |
||
Virtus Profil |
Teď už můžu odkázat jenom na funkce imagealphablending() a imagesavealpha(), bohužel s obrázky jsem nikdy nepracoval a nemám to momentálně kde vyzkoušet, snad poradí někdo jiný, když nato nepřídete sám.
Edit, možná takhle: $im = imagecreatetruecolor(640, 25); imageSaveAlpha($im, true); ImageAlphaBlending($im, false); Na php.net u funkce imagealphablending() si určitě projděte diskuzi pod manuálem k funkci, letmo sem to prohlíd a myslím, že tam odpoveď i s řešením najdete.
|
||
donny Profil |
#8 · Zasláno: 22. 3. 2013, 23:39:18
Virtus:
„Na php.net u funkce imagealphablending() si určitě projděte diskuzi pod manuálem k funkci, letmo sem to prohlíd a myslím, že tam odpoveď i s řešením najdete.“ Odpoveď s názvom potrebnej funkcie a odkazom do manuálu mu zjavne nestačí, inak by nezakladal druhú tému o tom istom v priebehu 24 hodín.. |
||
Časová prodleva: 11 let
|
0