Can someone put me in the right direction?
I want to know how these image generators work.
I can input some text and it will generate an image which will include my text ON the image...
here is an example:
http://txt2pic.com/signs/books/dummi...tag=&time=2320
how is this done in PHP? how can I do it?
Re: Can someone put me in the right direction?
Re: Can someone put me in the right direction?
Have a look at the Image Functions and please don't bump your threads.
Re: Can someone put me in the right direction?
Ok I've gotten pretty far but I am now very stuck, I've tried my hardest to figure it out.
It says cannot modify header information or already set. What I'm trying to do is pull random quotes from my database, I can display random quotes by TEXT with echo but cant seem to get them to work with my image code below:
PHP Code:
<?php
// Set the content-type
header("Content-type: image/gif");
$fontsize = 15;
if(@$_GET['fontsize']) {
$fontsize = $_GET['fontsize'];
}
$font = 'times.ttf';
$domain = GetHostByName($REMOTE_ADDR);
$text = @$_GET['text'];// . "" . $domain;
// Create the image
$size = imagettfbbox($fontsize, 0, $font, $text);
$width = $size[2] + $size[0] + 8;
$height = abs($size[1]) + abs($size[7]);
$im = imagecreate($width, $height);
$colourBlack = imagecolorallocate($im, 255, 255, 255);
imagecolortransparent($im, $colourBlack);
// Create some colors
$white = imagecolorallocate($im, 255, 255, 255);
$black = imagecolorallocate($im, 0, 0, 0);
// Add the text
imagefttext($im, $fontsize, 0, 0, abs($size[5]), $black, $font, $text);
// Using imagepng() results in clearer text compared with
imagegif($im);
imagedestroy($im);
?>
Both codes work how I want them to when they are separate. What's going on here?!
The code freaks out when I add this:
PHP Code:
<?php
header("Content-type: image/gif");
mysql_connect("SERVER", "USERNAME", "PASSWORD") or die(mysql_error());
mysql_select_db("Servic4_msr") or die(mysql_error());
?>
<?php
$query = "SELECT * FROM quotes ORDER BY RAND()LIMIT 1";
$result = mysql_query($query) or die(mysql_error());
while($row = mysql_fetch_array($result)){
$line = $row['lines'];
}
?>
Re: Can someone put me in the right direction?
and while I'm at it, how do I make a new line with this? It all goes on one line no matter what I try.
(im trying my hardest, I swear!) thanks
Re: Can someone put me in the right direction?
Okay, nevermind about the newline, slash n didn't work the first time, I got it now.
Re: Can someone put me in the right direction?
What's the exact error message?
Re: Can someone put me in the right direction?
As I said in my third reply, It says cannot modify header information or already set. - When I try to put both codes within one php file.
PHP Code:
Warning: Cannot modify header information - headers already sent by (output started at D:\hshome\servicep\site.com\msr\image.php:2) in D:\hshome\servicep\site.com\msr\image.php on line 18
Line 18 contains: header("Content-type: image/gif");
and thanks for un-closing my thread.
Re: Can someone put me in the right direction?
You need to ensure there i no output or white space before you call the header function.
Re: Can someone put me in the right direction?
EDIT - wait, it works now!
I can't believe WHITE SPACE (or empty lines) effect the header. LOL?)
Re: Can someone put me in the right direction?
Lets say one of my quotes is more than 50 chars long
how can I insert a new line break (/n)
after every 50 chars
i dont want it to stretch forum pages.
http://www.erbio.com/msr/image.php (my sig)
Re: Can someone put me in the right direction?
You could use the wordwrap() function.