Jump to content

[SOLVED] How would I Do This?


marcus

Recommended Posts

In terms of advertising a website using a banner and referral link.

 

I've written the mod rewrite for this.

 

My problem is: How would I go about using a premade banner and printing unique text on it for each users banner.

 

So:

 

http://website.org/userpics/marcus.png

 

Say I had: 800 forum posts

I wanted it to say: Username: marcus // Forum Posts: 800

 

Doing this by a SQL query.

 

$username = $_GET['username'];
protect($username); //pre-made function to protect variable
$sql = "SELECT * FROM `users` WHERE `username` ='$username'"; //username being marcus, atm
$res = mysql_query($sql) or die(mysql_error());

if(mysql_num_rows($res) == 0){
$text = "This user does not exist!";
}else {
$sql2 = "SELECT * FROM `replies` WHERE `username` ='$username'";
$res2 = mysql_query($sql2) or die(mysql_error());
$num = mysql_num_rows($res2);
$text = "Username: $username // Forum Posts: $num";
}

 

RewriteRule ^userpic/([^/]*)\.png$ /userpics.php?username=$1 [L]

 

How would I go about (probably using GD) to make the text ($text) print on the image?

Link to comment
Share on other sites

Ha. It looks very simple, but it looks confusing.

 

Is it possible to load an external image?

 

Yes, all you need to do is pass it an image resource created from the image. For a jpg image you could do this:

<?php

$image_resource = imagecreatefromjpeg ( 'filename/to/image.jpg' );
$text = "Hello World";

$textcolor = imagecolorallocate($im, 0, 0, 255);
$font = 5; // research imageloadfont() for options
$x_pos = 10;
$y_pos = 10;

imagestring($image_resource, $font, $x_pos, $y_pos, $text, $textcolor);

?>

Link to comment
Share on other sites

<?php

function protect($input)
{
$escaped_input = mysql_real_escape_string(urldecode($_POST['input']));
// $sql = "INSERT INTO table VALUES ('$escaped_input')";
$input = mysql_real_escape_string($input);
$input = eregi_replace("%","",$input);
$input = eregi_replace("--","",$input);
$input = htmlspecialchars(mysql_real_escape_string($input));

return $input;
}
$username = $_GET['username'];
protect($username);
$font = $_GET['font'];
protect($font);
$color = $_GET['color'];
protect($color);
$sql = "SELECT * FROM `users` WHERE `username` ='$username'";
$res = mysql_query($sql) or die(mysql_error());
if(mysql_num_rows($res) == 0){
$text = "This user does not exist!";
}else {
$row = mysql_fetch_assoc($res);
$text = "Username: $username // Forum Posts: $row[post_count]";
}
// create a 100*30 image
$im = imagecreate(500, 98);

// white background and blue text
$bg = imagecolorallocate($im, 255, 255, 255);
$array2 = array('black','red','blue','green','purple','grey');
if(in_array($color,$array2)){

switch($color){
case black:
$textcolor = imagecolorallocate($im, 0, 0, 0);
break;
case red:
$textcolor = imagecolorallocate($im, 255, 0, 0);
break;
case blue:
$textcolor = imagecolorallocate($im, 0, 0, 255);
break;
case green:
$textcolor = imagecolorallocate($im, 0, 128, 0);
break;
case purple:
$textcolor = imagecolorallocate($im, 128, 0, 128);
break;
case grey:
$textcolor = imagecolorallocate($im, 128,128,128);
break;
}
}else {
$textcolor = imagecolorallocate($im,0,0,0);
}

// write the string at the top left
$array = array(1,2,3,4,5);
if(in_array($font,$array)){
switch($font){
case 1:
$font = imageloadfont("andale12.gdf");
break;
case 2:
$font = imageloadfont("bmreceipt.gdf");
break;
case 3:
$font = imageloadfont("8x13iso.gdf");
break;
case 4:
$font = imageloadfont("bmcorrode.gdf");
break;
case 5:
$font = imageloadfont("bettynoir.gdf");
break;
}
}else {
$font = imageloadfont("andale12.gdf");
}
imagestring($im,$font, 5, 10, $text, $textcolor);

// output the image
header("Content-type: image/png");
imagepng($im);
?> 

 

This is my current file.

 

How would I be able to put a break in the text?

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.