Quantcast

Jump to content


Photo

Need quick vBulletin / php / html help!


  • Please log in to reply
26 replies to this topic

#1 Arkidas

Arkidas
  • 1231 posts

Posted 29 November 2007 - 11:30 AM

I need some quick help here! I need a simple parse_template plugin for vBulletin to replace the number of posts and threads in the forum's index table, with graphical numbers ( I'm creating a .gif for numbers 0 - 9 ).
I know this is possible, and now 2 people that can probably do this but you know how people are busy around this season so I was hoping that someone here knew how to do this. You would of course contact me over MSN, and get access to admin, ftp as needed.

Thanks.

Edited by Arkidas, 29 November 2007 - 11:41 AM.


#2 Waser Lave

Waser Lave

  • 25516 posts


Users Awards

Posted 29 November 2007 - 11:35 AM

CODE
<?php
header("Content-type: image/png");
$im = @imagecreate(100, 50)
    or die("Cannot Initialize new GD image stream");
$background_color = imagecolorallocate($im, 255, 255, 255);
$text_color = imagecolorallocate($im, 233, 14, 91);
imagestring($im, 1, 5, 5,  "A Simple Text String", $text_color);
imagepng($im);
imagedestroy($im);
?>


Straight from the php manual.

#3 Arkidas

Arkidas
  • 1231 posts

Posted 29 November 2007 - 11:38 AM

Thanks for the quick reply. Do you have some minutes to explain this to me whether it's here or through MSN? ( arkidas [ at ] hotmail.com ).

#4 Waser Lave

Waser Lave

  • 25516 posts


Users Awards

Posted 29 November 2007 - 11:42 AM

CODE
<?php
header("Content-type: image/png");
$im = @imagecreate(100, 50)
    or die("Cannot Initialize new GD image stream");
$background_color = imagecolorallocate($im, 255, 255, 255);
$text_color = imagecolorallocate($im, 233, 14, 91);
imagestring($im, 1, 5, 5,  "A Simple Text String", $text_color);
imagepng($im);
imagedestroy($im);
?>


header("Content-type: image/png");

That makes it output as an image rather than just a load of text.

$im = @imagecreate(100, 50)
or die("Cannot Initialize new GD image stream");


Creates a blank image of 100,50 or it outputs the error message.

$background_color = imagecolorallocate($im, 255, 255, 255);
$text_color = imagecolorallocate($im, 233, 14, 91);


Just sets some colours to some variables, the numbers are RGB.

imagestring($im, 1, 5, 5, "A Simple Text String", $text_color);

Writes a string onto your image.

bool imagestring ( resource image, int font, int x, int y, string s, int col )

imagestring() draws the string s in the image identified by image with the upper-left corner at coordinates x, y (top left is 0, 0) in color col. If font is 1, 2, 3, 4 or 5, a built-in font is used.

imagepng($im);
imagedestroy($im);


Displays and then destroys the image to free memory.

#5 Arkidas

Arkidas
  • 1231 posts

Posted 29 November 2007 - 11:43 AM

That explains the code. The thing is though, I wanted to use my very own custom made images, is there no way to do that?

Attached Files


Edited by Arkidas, 29 November 2007 - 11:47 AM.


#6 Waser Lave

Waser Lave

  • 25516 posts


Users Awards

Posted 29 November 2007 - 11:48 AM

QUOTE(Arkidas @ Nov 29 2007, 08:43 PM) View Post
That explains the code. The thing is though, I wanted to use my very own custom made images, is there no way to do that?


$im = @imagecreatefromgif ($imgname); /* Attempt to open */

There's also imagecreatefrompng, imagecreatefromjpeg. wink.gif

The PHP documentation should be your first stop whenever you're doing anything with php (<3 the manual). biggrin.gif

http://www.php.net/docs.php

#7 Arkidas

Arkidas
  • 1231 posts

Posted 29 November 2007 - 11:50 AM

Ok, so is this possible with this code? Any idea where I should put it if I just want it for these columns? Sorry, I'm not really a coder but I think I should be able to do this with the right instructions. wink.gif

#8 Waser Lave

Waser Lave

  • 25516 posts


Users Awards

Posted 29 November 2007 - 11:54 AM

Personally I would make it a separate php file. Then you can just do something like <img src='yournewimagecode.php?number=1'/>

I don't mod vbulletin much so i'm not entirely sure where you'd put it either. tongue.gif

Edited by Laser Wave, 29 November 2007 - 11:56 AM.


#9 Arkidas

Arkidas
  • 1231 posts

Posted 29 November 2007 - 11:59 AM

Have you ever browsed the admin cp? I'm just wondering what the numbers are in the template / php file. You're welcome to look at it too, if you want, but I don't want to take too much of your time. You think this is possible though. right? You just put the code in a php file, upload it and then ( this part I don't understand fully ) somehow change the number code which should of course just be one line of code since it's the same coding for all the number displays, and make sure it still contacts the database to get the value and then get the code from the php file uploaded. Something like this right tongue.gif?

#10 Waser Lave

Waser Lave

  • 25516 posts


Users Awards

Posted 29 November 2007 - 12:03 PM

I actually have a copy of vbulletin but I don't use it much. tongue.gif

You need to find the file which that page that you screenshotted uses and then change the bit where it just outputs the numbers to output images instead. Shouldn't be that difficult if you can find the right file.

#11 Arkidas

Arkidas
  • 1231 posts

Posted 29 November 2007 - 12:06 PM

Found the template code in style at least

CODE
        <td class="alt1">$forum[threadcount]</td>
        <td class="alt2">$forum[replycount]</td>


#12 Waser Lave

Waser Lave

  • 25516 posts


Users Awards

Posted 29 November 2007 - 12:08 PM

QUOTE(Arkidas @ Nov 29 2007, 09:06 PM) View Post
Found the template code in style at least

CODE
        <td class="alt1">$forum[threadcount]</td>
        <td class="alt2">$forum[replycount]</td>


Now you'd change that to something like:

CODE
        <td class="alt1"><img src='yourimagecodestuff.php?number=$forum[threadcount]'/></td>
        <td class="alt2"><img src='yourimagecodestuff.php?number=$forum[replycount]'/></td>


#13 Arkidas

Arkidas
  • 1231 posts

Posted 29 November 2007 - 12:08 PM

Really? Doesn't it need any PHP changes?

#14 Waser Lave

Waser Lave

  • 25516 posts


Users Awards

Posted 29 November 2007 - 12:10 PM

QUOTE(Arkidas @ Nov 29 2007, 09:08 PM) View Post
Really? Doesn't it need any PHP changes?


Are you doing this in the template manager thing?

Which one are you customizing?

#15 Arkidas

Arkidas
  • 1231 posts

Posted 29 November 2007 - 12:14 PM

forumhome_forumbit_level1_post
EDIT: Seems it's = forumhome_forumbit_level2_post

Edited by Arkidas, 29 November 2007 - 12:24 PM.


#16 Waser Lave

Waser Lave

  • 25516 posts


Users Awards

Posted 29 November 2007 - 12:24 PM

QUOTE(Arkidas @ Nov 29 2007, 09:14 PM) View Post
forumhome_forumbit_level1_post


Apparently it works with what I posted just before. tongue.gif

You'll probably need to edit forumhome_forumbit_level2_post too.

#17 Arkidas

Arkidas
  • 1231 posts

Posted 29 November 2007 - 12:27 PM

So is it possible to have it so that I create "Warcrafty" images for each number and use them? How would the main .php look then if the images were in = images/numbers/x.gif, x being the number... ( Although there are of course many numbers in each "number" ( 1000, 121 etc tongue.gif ). And would I still just change it to
CODE
       <td class="alt1"><img src='yourimagecodestuff.php?number=$forum[threadcount]'/></td>
        <td class="alt2"><img src='yourimagecodestuff.php?number=$forum[replycount]'/></td>
?

Sorry for being pushy but I don't want to spend the next days on this tongue.gif

#18 Waser Lave

Waser Lave

  • 25516 posts


Users Awards

Posted 29 November 2007 - 12:44 PM

Well I don't want to write the whole thing for you since I prefer for people to actually learn for themselves but this should be a good starting point:

CODE
<?php
    $number = $_GET['number'];
    
    if(is_numeric($number))
    {
        header("Content-type: image/gif");
        $image=imagecreate("50", "20");
        
        $colourWhite=imagecolorallocate($image, 255, 255, 255);
        $colourBlack=imagecolorallocate($image, 0, 0, 0);
        
        imagestring($image,2,2,2,$number,$colourBlack);
        
        imagegif($image);
        imagedestroy($image);
    }
?>


That's working code which will output a number as an image, you'll need to use imagecreatefromgif instead of imagecreate but the rest should be more or less fine.

#19 Arkidas

Arkidas
  • 1231 posts

Posted 29 November 2007 - 12:47 PM

Ok thanks. Can you tell me where to put the path, images/numbers/ and what about the RGB color codes? I don't need them so can't they be wiped out?

#20 Waser Lave

Waser Lave

  • 25516 posts


Users Awards

Posted 29 November 2007 - 12:54 PM

QUOTE(Arkidas @ Nov 29 2007, 09:47 PM) View Post
Ok thanks. Can you tell me where to put the path, images/numbers/ and what about the RGB color codes? I don't need them so can't they be wiped out?


Are you using images for each individual number?

In that case you'd need to loop through each individual character in the number (e.g. 1,2,3,4 in 1234) and then load the image for each individual number and merge them into one overall image.

Lookup the functions imagecopy and imagecopymerge.

http://uk2.php.net/m...n.imagecopy.php
http://uk2.php.net/m...gecopymerge.php

#21 Arkidas

Arkidas
  • 1231 posts

Posted 29 November 2007 - 12:56 PM

Yes, an image for each individual number. It'd be impossible otherwise since the number of threads and posts in forums vary! wink.gif It's impossible to predict the number so would I have to do 1 - 9 in all? I mean, the number is always changing.

#22 Waser Lave

Waser Lave

  • 25516 posts


Users Awards

Posted 29 November 2007 - 12:59 PM

QUOTE(Arkidas @ Nov 29 2007, 09:56 PM) View Post
Yes, an image for each individual number. It'd be impossible otherwise since the number of threads and posts in forums vary! wink.gif It's impossible to predict the number so would I have to do 1 - 9 in all? I mean, the number is always changing.


0-9, otherwise you'd be missing out a lot of numbers. tongue.gif

#23 Arkidas

Arkidas
  • 1231 posts

Posted 29 November 2007 - 01:18 PM

Right, Could you tell me how the template code would work though? I'd still learn if you told me smile.gif

#24 Waser Lave

Waser Lave

  • 25516 posts


Users Awards

Posted 29 November 2007 - 01:56 PM

Something like:

CODE
<?php
    $number = $_GET['number'];
    
    if(is_numeric($number))
    {
        header("Content-type: image/gif");
        $image=imagecreatefromgif("numbers/back.gif"); // load our background image
        
        $x=2; //starting position
        
        for($i=0;$i<strlen($number);$i++)
        {        
            if(file_exists("numbers/".$number[$i].".gif")) // our number image exists
            {
                $imagenum = imagecreatefromgif("numbers/".$number[$i].".gif"); // load our number image
                imagecopymerge($image,$imagenum,$x,2,0,0,15,15,50); // 15 is the width and height of the numbers i made for testing, 50 is the opacity
                $x+=15; // moving 15 places to the right so we're beside the previous number
            }
        }
        
        imagegif($image);
        imagedestroy($image); // clean up and free some memory
        imagedestroy($imagenum); // same here
    }
?>


You can play around with the positioning and stuff yourself.

Edited by Laser Wave, 29 November 2007 - 01:56 PM.


#25 Arkidas

Arkidas
  • 1231 posts

Posted 29 November 2007 - 02:05 PM

Very nice, thank you so much. With positioning, you mean the path to where the numbers are located right? And just one more thing, it that background image thing like an area around the numbers? ( That the number images are inside )
Thanks.


0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users