4images Forum & Community

General / Allgemeines => Programming => Topic started by: Sunny C. on July 02, 2010, 07:38:15 PM

Title: Text to Png
Post by: Sunny C. on July 02, 2010, 07:38:15 PM
Hello i write a script to show text to png.
http://gn.germannaruto.de/wp-gallerie/lol.php?text=woot!
Works fine, but i cant use in home.html
Like:
Code: [Select]
<h2><a class="title" href="../?p=1" rel="bookmark"><?php include ("lol.php?Hallo Welt!"); ?></a></h2>
Title: Re: Text to Png
Post by: V@no on July 02, 2010, 11:53:20 PM
Don't forget, that template files are being executed via functions, so if your included script requires some global variables, you'll need use global keyword before it will be able use them.

Then, you can't use query type strings in the path for a local include.
And finally, your script generates image itself, not HTML code, you need use it like this instead:

Code: [Select]
<h2><a class="title" href="../?p=1" rel="bookmark"><img src="lol.php?text=Hallo Welt!"></a></h2>
P.S.
Please post such questions in programming section, as it's clearly not related to 4images package itself.
Title: Re: Text to Png
Post by: Sunny C. on July 03, 2010, 09:56:02 AM
Hallo Vano,

genau das habe ich auch schon gemacht, aber das funktioniert auch nicht. Der Code wird nun so ausgegeben:
Code: [Select]
<a class="title" href="../?p=1" rel="bookmark"><img src="lol.php?Hallo%20Welt%21"></a>
//

Hello Vano,

I have already made exactly this, but this also does not function. Now the code is given thus:
Code: [Select]
<a class = "headlines" href = "./? p=1" rel = "bookmark"> <img src = "lol.php? Hallo%20Welt%21"> </a>
The Code
<?php

header("Content-type: image/png"); //Picture Format
header("Expires: Mon, 01 Jul 2003 00:00:00 GMT"); // Past date
header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT"); // Consitnuously modified
header("Cache-Control: no-cache, must-revalidate"); // HTTP/1.1
header("Pragma: no-cache"); // NO CACHE

/*image generation code*/
//create Image of size 350px x 75px
$bg = imagecreatetruecolor(350, 75);

//This will make it transparent
imagesavealpha($bg, true);

$trans_colour = imagecolorallocatealpha($bg, 0, 0, 0, 127);
imagefill($bg, 0, 0, $trans_colour);

//Text to be written
$helloworld = $_GET['text'];

// White text
$white = imagecolorallocate($bg, 255, 255, 255);
// Grey Text
$grey = imagecolorallocate($bg, 128, 128, 128);
// Black Text
$black = imagecolorallocate($bg, 0,0,0);

$font = 'Alibi___.ttf'; //path to font you want to use
$fontsize = 20; //size of font

//Writes text to the image using fonts using FreeType 2
imagettftext($bg, $fontsize, 0, 20, 20, $grey, $font, $helloworld);

//Create image
imagepng($bg);

//destroy image
ImageDestroy($bg);
?>
Title: Re: Text to Png
Post by: V@no on July 03, 2010, 10:35:46 PM
sorry, it should be lol.php?text=Hallo Welt! (I've updated my post above)

regarding Hallo%20Welt%21 - it should not matter.
Title: Re: Text to Png
Post by: Sunny C. on July 03, 2010, 11:27:52 PM
Work!
THX