Help - Search - Members - Calendar
Full Version: Parsing HTML into Image
MSFN Forums > Customizing Windows and Graphics > Graphics and Designing Art > Signatures

   
Google Internet Forums Unattended CD/DVD Guide
EchoNoise
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.com/robot.php?name=un...mp;style=pretty

and parse it into an image... can it be done so I can use it as my sig?
gamehead200
Follow my guide here:

http://www.msfn.org/board/index.php?showtopic=47730

then define the variable:

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


and output it somewhere in the image like so:

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


Should work. smile.gif 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. smile.gif

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... newwink.gif

Edit2:

Here we go!!!



CODE
<?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:



And the contents of the .htaccess file:

CODE
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.)
EchoNoise
EDIT: yay!
gamehead200
QUOTE (undeadsoldier @ Jul 17 2006, 10:15 PM) *
Its not working unfortunately, thanks for the info though smile.gif

*starts to pull hair out*

laugh.gif


Never mind... tongue.gif

I hope that's what you wanted. smile.gif

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.
EchoNoise
It works when I test it on my own server smile.gif

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 smile.gif
gamehead200
QUOTE (undeadsoldier @ Jul 17 2006, 10:24 PM) *
It works when I test it on my own server smile.gif

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 smile.gif


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

CODE
Options All -Indexes

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


OR

You might not have GD enabled.
EchoNoise
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...
gamehead200
QUOTE (undeadsoldier @ Jul 17 2006, 10:42 PM) *
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.gif
EchoNoise
Nope... I have not changed anything at all
gamehead200
QUOTE (undeadsoldier @ Jul 17 2006, 11:04 PM) *
Nope... I have not changed anything at all


Check your error log? confused.gif
EchoNoise
*cries*... laugh.gif

I'll see what I can do from here, thanks for your help man smile.gif !!
EchoNoise
I just got informed that file_get_contents is not supported sad.gif

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 smile.gif
gamehead200
QUOTE (undeadsoldier @ Jul 18 2006, 01:34 AM) *
I just got informed that file_get_contents is not supported sad.gif

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 smile.gif


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.
gamehead200
Ah, some new code generates this biggrin.gif:



Try the following out:

CODE
<?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);

?>
EchoNoise
My host have PHP 5.1.4 but they have disabled things for "security" purposes.... dry.gif

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

CODE
<?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:



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 smile.gif
Google Internet Forums Unattended CD/DVD Guide
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.