Jump to content

Welcome to MSFN Forum
Register now to gain access to all of our features. Once registered and logged in, you will be able to create topics, post replies to existing threads, give reputation to your fellow members, get your own private messenger, post status updates, manage your profile and so much more. This message will be removed once you have signed in.
Login to Account Create an Account



Photo

Parsing HTML into Image

- - - - -

This topic has been archived. This means that you cannot reply to this topic.
14 replies to this topic

#1
EchoNoise

EchoNoise

    Defender of the Penguin

  • Member
  • PipPipPipPipPip
  • 885 posts
  • Joined 10-April 05
Hey peoples!

I need some help, I've only got a simple text signature that doesn't update automatically...

I need to have the text that shows on here

http://progressquest...mp;style=pretty

and parse it into an image... can it be done so I can use it as my sig?
Posted Image


How to remove advertisement from MSFN

#2
gamehead200

gamehead200

    SEARCH!!! SEARCH!!!

  • Patrons
  • 6,870 posts
  • Joined 02-September 02
Follow my guide here:

http://www.msfn.org/...showtopic=47730

then define the variable:

$status = file_get_contents("http://progressquest.com/robot.php?name=undeadsoldier&realm=Expodrine&style=pretty");

and output it somewhere in the image like so:

ImageTTFText ($image, 8, 0, 10, 17, $white, $font, $status);

Should work. :) It's working in my sig below... See the little green (or red) dot on the top right? That's basically giving my computer's online status by grabbing it from the text output at the Hamachi status site. :)

Edit: I just realized the file_get_contents will not work because it will grab the entire HTML of that page... Working on a solution... ;)

Edit2:

Here we go!!!

Posted Image

<?php

Header ('Content-type: image/jpeg');
Header('Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0');
Header('Expires: Thu, 19 Nov 1981 08:52:00 GMT');
Header('Pragma: no-cache');

// create the image
$image = imagecreatefromjpeg("background.jpg");

// set the colors
$black = imagecolorallocate($image, 0, 0, 0);
$blue = imagecolorallocate($image, 63, 70, 88);
$red = imagecolorallocate($image, 255, 0, 0);

// set the font
$font = 'verdana.ttf';
$size = 8;

// grab status
$grab = file_get_contents("http://progressquest.com/robot.php?name=undeadsoldier&realm=Expodrine");

$split = preg_split("/[\n]+/", $grab);

$line1 = $split[0] . " of Expodrine (" . $split[4] . ")";
$line2 = "Level " . $split[3] . " " . $split[1] . " " . $split[2];
$line3 = $split[5] . " / " . $split[6] . " / " . $split[7];

$combine = $line1 . "\n" . $line2 . "\n" . $line3;

// put text together
ImageTTFText($image, $size, 0, 8, 16, $black, $font, $combine);

// output and destroy
imagejpeg($image);
imagedestroy($image);

?>

This is the background image used:

Posted Image

And the contents of the .htaccess file:

Options All -Indexes

<Files sig.jpg>
SetHandler application/x-httpd-php
</Files>

I used the Verdana font because I had already saved it somewhere on my machine.

Please try to host this on your own server if you're going to use it since I am now hosting it on one that isn't very reliable and because I use it for other things that usually slow it down (compiling/home music sharing/etc.)

#3
EchoNoise

EchoNoise

    Defender of the Penguin

  • Member
  • PipPipPipPipPip
  • 885 posts
  • Joined 10-April 05
EDIT: yay!

Edited by undeadsoldier, 17 July 2006 - 08:15 PM.

Posted Image

#4
gamehead200

gamehead200

    SEARCH!!! SEARCH!!!

  • Patrons
  • 6,870 posts
  • Joined 02-September 02

Its not working unfortunately, thanks for the info though :)

*starts to pull hair out*

:lol:


Never mind... :P

I hope that's what you wanted. :)

Also, you might have to play around with it a bit as it is too big, according to forum rules, to be used as a sig.

Edited by gamehead200, 17 July 2006 - 08:18 PM.


#5
EchoNoise

EchoNoise

    Defender of the Penguin

  • Member
  • PipPipPipPipPip
  • 885 posts
  • Joined 10-April 05
It works when I test it on my own server :)

But when I go and upload it, it gives me a "Error 500"

I'm guessing its something to do with the .htaccess file...

My host is on linux :)
Posted Image

#6
gamehead200

gamehead200

    SEARCH!!! SEARCH!!!

  • Patrons
  • 6,870 posts
  • Joined 02-September 02

It works when I test it on my own server :)

But when I go and upload it, it gives me a "Error 500"

I'm guessing its something to do with the .htaccess file...

My host is on linux :)


You might have to put this instead in your .htaccess file:

Options All -Indexes

<Files sig.jpg>
AddHandler application/x-httpd-php .jpg
</Files>

OR

You might not have GD enabled.

#7
EchoNoise

EchoNoise

    Defender of the Penguin

  • Member
  • PipPipPipPipPip
  • 885 posts
  • Joined 10-April 05
GD is enabled, I've talked to the host admin people

I'll try that method above, and i'll let you know...

EDIT: nope... It doesn't seem to work... Unlesssssssssss.. *idea* (taking out "options")

Taking out the options tag, just gives me the result of whats in the address bar... Which is very odd...

Edited by undeadsoldier, 17 July 2006 - 08:40 PM.

Posted Image

#8
gamehead200

gamehead200

    SEARCH!!! SEARCH!!!

  • Patrons
  • 6,870 posts
  • Joined 02-September 02

GD is enabled, I've talked to the host admin people

I'll try that method above, and i'll let you know...

EDIT: nope... It doesn't seem to work... Unlesssssssssss.. *idea* (taking out "options")

Taking out the options tag, just gives me the result of whats in the address bar... Which is very odd...


Hehe... This has happened to me before... Did you by any chance rename the sig.jpg file and forget to change it in the .htaccess file? :unsure:

#9
EchoNoise

EchoNoise

    Defender of the Penguin

  • Member
  • PipPipPipPipPip
  • 885 posts
  • Joined 10-April 05
Nope... I have not changed anything at all
Posted Image

#10
gamehead200

gamehead200

    SEARCH!!! SEARCH!!!

  • Patrons
  • 6,870 posts
  • Joined 02-September 02

Nope... I have not changed anything at all


Check your error log? :}

#11
EchoNoise

EchoNoise

    Defender of the Penguin

  • Member
  • PipPipPipPipPip
  • 885 posts
  • Joined 10-April 05
*cries*... :lol:

I'll see what I can do from here, thanks for your help man :) !!
Posted Image

#12
EchoNoise

EchoNoise

    Defender of the Penguin

  • Member
  • PipPipPipPipPip
  • 885 posts
  • Joined 10-April 05
I just got informed that file_get_contents is not supported :(

So is there anywhere I can put my dynamic signature that IS supported?

I have edited Gameheads files a bit, I just need somebody to upload and I'll be as good to go :)

Edited by undeadsoldier, 17 July 2006 - 11:35 PM.

Posted Image

#13
gamehead200

gamehead200

    SEARCH!!! SEARCH!!!

  • Patrons
  • 6,870 posts
  • Joined 02-September 02

I just got informed that file_get_contents is not supported :(

So is there anywhere I can put my dynamic signature that IS supported?

I have edited Gameheads files a bit, I just need somebody to upload and I'll be as good to go :)


What version of PHP does your host have? He should upgrade to at least PHP 4.4.2 for this to work, if not, PHP 5.1.4.

#14
gamehead200

gamehead200

    SEARCH!!! SEARCH!!!

  • Patrons
  • 6,870 posts
  • Joined 02-September 02
Ah, some new code generates this :D:

Posted Image

Try the following out:

<?php

Header ('Content-type: image/jpeg');
Header('Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0');
Header('Expires: Thu, 19 Nov 1981 08:52:00 GMT');
Header('Pragma: no-cache');

// create the image
$image = imagecreatefromjpeg("background.jpg");

// set the colors
$black = imagecolorallocate($image, 0, 0, 0);

// set the font
$font = 'verdana.ttf';
$size = 8;

// grab status and split it up
$handle = @fopen("http://progressquest.com/robot.php?name=undeadsoldier&realm=Expodrine", "r");
if($handle){
		for( $i = 0; !feof($handle); $i++ ){
				$get = fgets($handle, 4096);
				$split[$i] = trim($get, "\n");
		}
		fclose($handle);
}

$line1 = $split[0] . " of Expodrine (" . $split[4] . ")";
$line2 = "Level " . $split[3] . " " . $split[1] . " " . $split[2];
$line3 = $split[5] . " / " . $split[6] . " / " . $split[7];

$combine = $line1 . "\n" . $line2 . "\n" . $line3;

// put text together
ImageTTFText($image, $size, 0, 8, 16, $black, $font, $combine);

// output and destroy
imagejpeg($image);
imagedestroy($image);

?>


#15
EchoNoise

EchoNoise

    Defender of the Penguin

  • Member
  • PipPipPipPipPip
  • 885 posts
  • Joined 10-April 05
My host have PHP 5.1.4 but they have disabled things for "security" purposes.... <_<

I made these changes, not major, but yeah...

<?php

Header ('Content-type: image/png');

$image = imagecreatefrompng("bck.png");
$colour = imagecolorallocate($image, 0, 0, 0);
$font = 'verdana.ttf';
$size = 8;

$grab = file_get_contents("http://progressquest.com/robot.php?name=undeadsoldier&realm=Expodrine");

$split = preg_split("/[\n]+/", $grab);

$line1 = "Name: " . $split[0] . " of expodrine (" . $split[4] . ")";
$line2 = "Level: " . $split[3];
$line3 = "Class: " . $split[1] ." ". $split[2];
$line4 = "Prized Item: " . $split[5];
$line5 = "Specialty: " . $split[6];
$line6 = "Prime Stat: " . $split[7];

$combine = $line1 . "\n" . $line2 . "\n" . $line3 . "\n" . $line4 . "\n" . $line5 . "\n" . $line6;

ImageTTFText($image, $size, 0, 8, 16, $colour, $font, $combine);

imagepng($image);
imagedestroy($image);

?>

It produces this:

Posted Image

What do you think?

And I know I shouldn't ask this, but would it be ok if you could host it gamehead? Or know of a place where I can host it? Thanks :)
Posted Image