PDA

View Full Version : embedding html isn't allowed, so....now what?



Peegee
02-20-2004, 02:41 PM
I suppose this is a tad bit unnecessary, but I'd like to have different signatures load up, sort of like that thingie where different avatars can load up by using some sort of script I can't remember. I'm sure I can make a webpage that loads a (small) something every time I refresh, but since I can't embed html here, I can't use that method (though FG is another matter...I'll do that for FG)

So what am I left with? If it's not possible, can I at least get a tutorial/information on how to get random images to show up in the signature? (I'm speaking about a script or something that loads a random image based on a list of urls).

Dr Unne
02-20-2004, 04:08 PM
Perl is your friend. You can write a Perl script that returns image data instead of text data.


#!/usr/bin/perl -T

use strict;
use warnings;

use CGI;

my $filename = int(rand(2));

($filename == 1) ? ($filename = 'tux2.png') : ($filename = 'tux.png');

if(open FILE, "<", $filename) {
print CGI::header('image/png');
binmode FILE;
print while(<FILE>);
close FILE;
} else {
print CGI::header();
print "Error: $!";
}


Now if you use an IMG tag and put the .cgi script as the URL, if you refresh this page and it should show a random picture.

<img src="http://chwombat.net/cgi-bin/picture.cgi">

gives

<img src="http://chwombat.net/cgi-bin/picture.cgi">

Endless
02-20-2004, 04:37 PM
PHP allows the same kind of trick.
If you have a dir full of gifs, rename them all to start with "banner" (banner_blah.gif for example) and this script will output the image for you, cycling through the available images depending on the time of the day:


<?php

function imagesel( $max )
{
$h=strftime("%H");
$m=strftime("%M");
$t=($h*60)+$m;
$n=1440/$max;
$r=$t/$n;
$r=floor($r);
return $r;
}

$i = 0;
$d = dir(".");
while($entry=$d->read())
if (substr($entry,0,6) == "banner") {
$array[$i++] = $entry;
}
$d->close();

/* pick a banner at random
*/
$r = imagesel( $i );

/* Send a no-cache header, and the gif type header, and output the file.
*/
Header( "Pragma: no-cache" );
Header( "Expires: Monday 01-Jan-80 12:00:00 GMT" );
Header( "Content-type: image/gif");
$im = fopen("./".$array[$r], "r");
fpassthru($im);
?>

It only needs a small modification of the imagesel function to make it random.

Dr Unne
02-20-2004, 05:20 PM
Another thing for the programming-impaired: see the image/gif and image/png in the code? Those need to correspond to the kinds of images you're displaying. If you send GIF data as image/png, your browser will probably either choke on it, or else do some magic to display it as a GIF anyways (which may be what IE does, and which is the WRONG thing to do, but anyways).

On a side note, why in the world did they make the "php" vB tag so hard to read? Do those colors look good in ANY color scheme? Because they make my eyes bleed on this color scheme.

The Man
02-20-2004, 11:24 PM
Originally posted by Dr Unne
On a side note, why in the world did they make the "php" vB tag so hard to read? Do those colors look good in ANY color scheme? Because they make my eyes bleed on this color scheme. It looks fine in the default vBulletin colour scheme, but crap in any light-on-dark colour scheme. It also seems to be hard-coded into PHP itself, because I've been entirely unable to find those colour codes anywhere in the vB source. What they SHOULD have done is put a white background behind the php tag so that you could read it no matter what the background colours were. Or else written their own function that allows you to change the colours, that would have been better.

Endless
02-21-2004, 12:05 AM
It's done by the built-in highlight_string() php function. So, in order to modify it, you would have to write a syntax highlighter and then change the function call to the one you wrote. It's doable, but requires hacking, a bit of a pita (mainly to code the new highlighter) imho.
Basicly for the curious, search for <i>phphighlite</i> in admin/functions.php, that's the part that needs to be modified.

Edit: minor hacking should let you put a white background (just change the return line).

Peegee
02-21-2004, 12:13 PM
Okay I copied Dr Unne's code, set up a webserver here on my computer, and put the cgi file in there. I then put two images in the directory.

It doesn't work. I get a red 'x' when I run the html file that has the image tag.



#!/usr/bin/perl -T

use strict;
use warnings;

use CGI;

my $filename = int(rand(2));

($filename == 1) ? ($filename = 'F_H.jpg') : ($filename = 'takebacktheweb_large.jpg');

if(open FILE, "<", $filename) {
print CGI::header('image/png');
binmode FILE;
print while(<FILE>);
close FILE;
} else {
print CGI::header();
print "Error: $!";
}







[img src="http://192.168.2.103/pics.cgi" /]

Endless
02-21-2004, 03:02 PM
Originally posted by Dr Unne
Another thing for the programming-impaired: <b>see the image/gif and image/png in the code? Those need to correspond to the kinds of images you're displaying.</b> If you send GIF data as image/png, your browser will probably either choke on it, or else do some magic to display it as a GIF anyways (which may be what IE does, and which is the WRONG thing to do, but anyways).

On a side note, why in the world did they make the "php" vB tag so hard to read? Do those colors look good in ANY color scheme? Because they make my eyes bleed on this color scheme.

Peegee
02-22-2004, 05:38 AM
oops. Okay it's image/jpg now and still doesn't show up

crono_logical
02-22-2004, 05:50 AM
Have you got Perl installed on your machine, seeing as it's a Perl script you copy/pasted? :p

Dr Unne
02-22-2004, 07:12 AM
Tell what OS and web server you're using. Look in your web server logs and see what error it's giving you. Post the HTML code you're using to display the image.

Endless
02-22-2004, 02:41 PM
In the HTML code you posted, it's a local network IP, so other people than you wouldn't see it, and cgi scripts have to be in the cgi-bin directory. If you're on XP, you need to download and install the perl module. If you're on linux, it most likely is already here, and you just need to use the cgi-bin folder which should be /var/www/cgi-bin