|
-
Jul 23rd, 2007, 10:17 PM
#1
Thread Starter
Hyperactive Member
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?
-
Jul 24th, 2007, 02:58 AM
#2
Thread Starter
Hyperactive Member
Re: Can someone put me in the right direction?
Last edited by erbio; Jul 28th, 2007 at 04:04 AM.
8 gigs/ram (hey why not)
300 gig HD x2
Windows XP 64
-
Jul 24th, 2007, 09:12 PM
#3
Re: Can someone put me in the right direction?
Have a look at the Image Functions and please don't bump your threads.
-
Jul 28th, 2007, 04:14 AM
#4
Thread Starter
Hyperactive Member
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'];
}
?>
8 gigs/ram (hey why not)
300 gig HD x2
Windows XP 64
-
Jul 28th, 2007, 04:17 AM
#5
Thread Starter
Hyperactive Member
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
8 gigs/ram (hey why not)
300 gig HD x2
Windows XP 64
-
Jul 28th, 2007, 04:32 AM
#6
Thread Starter
Hyperactive Member
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.
-
Jul 28th, 2007, 06:37 AM
#7
Re: Can someone put me in the right direction?
What's the exact error message?
-
Jul 30th, 2007, 12:24 PM
#8
Thread Starter
Hyperactive Member
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.
Last edited by erbio; Jul 30th, 2007 at 12:30 PM.
-
Jul 30th, 2007, 12:49 PM
#9
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.
-
Jul 30th, 2007, 02:42 PM
#10
Thread Starter
Hyperactive Member
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?)
-
Jul 30th, 2007, 03:17 PM
#11
Thread Starter
Hyperactive Member
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)
8 gigs/ram (hey why not)
300 gig HD x2
Windows XP 64
-
Jul 31st, 2007, 12:20 AM
#12
Re: Can someone put me in the right direction?
You could use the wordwrap() function.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|