Forum Moderators: coopster

Message Too Old, No Replies

How to output a php file as an image file?

         

cameraguy

12:50 pm on May 25, 2006 (gmt 0)

10+ Year Member



Hello,

I developped a web counter in php that can be inserted in blogs like this:
<script language="javascript" src="http://counter.php"></script>

This works just fine, but there are many blog providers like MSN Spaces that do not allow js scripts. So I am looking for an alternative method to output 'counter.php'.

I have seen counters that are displayed via image files, like:
<img src="http://counter.gif">

I found solutions that involve the instruction 'CreateImage', but it's always an image created on the fly with the GD library and made of text. My output would be more complex, involving a table with images and text, mysql queries, etc.

Is there a way to output a whole php file as an image, independently of what it is made of?

alexorig

7:57 pm on May 25, 2006 (gmt 0)

10+ Year Member



<?php
$t = "text";
header("Content-type: image/png");
$im = @imagecreate(128, 16) or die("Cannot Initialize new GD image stream");
$bc = imagecolorallocate($im, 0, 255, 255);
$tc = imagecolorallocate($im, 0, 0, 0);
imagestring($im, 1, 4, 4, $t, $tc);
imagepng($im);
imagedestroy($im);
?>

Is a chunk of code that will create a simple image, you can obviously modify that so every time it is called it will have a?user=72879 on the end or whatever and allow you to do counting and return counts.

The important bit you need is the php header() command which you can always explore further by searching for it.

Hope that helps

jatar_k

8:01 pm on May 25, 2006 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



Welcome to WebmasterWorld alexorig

cameraguy

8:34 pm on May 25, 2006 (gmt 0)

10+ Year Member



Thanks Alexorig, but this only turns the string "text" into an image. I need to convert a whole page...