View Full Version : dynamic image with stats?
09-09-2009, 09:59 AM
So I'm trying to familiarize myself with gd. I know how to add text to an image with it, but I want something more.
If you look there, this is what I'm going for. Auto-updating stats on the .png image.
I can do this just fine (get stats and show image) but my image is viewed through the php file I create. How can I get it to update MY png image to show the latest stats from the php file?
09-09-2009, 12:35 PM
Give us a PNG image all by itself (blank),
and then the same PNG image with text on it (example of how you want it to look).
We can then show you how to put "any text" onto your blank PNG image
so it looks like your example (with text on it).
09-09-2009, 03:22 PM
If you can view your image through your PHP file, like you say, then just use <img src="whatever.php"/> and it will work just fine.
09-09-2009, 07:43 PM
I know how to put text on it, I was just wondering how I can get that so the image is imagename.png (with the dynamic text) and not imagename.php?
09-09-2009, 08:20 PM
Well, you can either configure your server to execute image files as PHP, then save your php file with the extension of your choice (who knows what side-effects that would have), or have your PHP script save the image on your server every time it runs...
But all that's really a lot of extra work. Why can't you just use the PHP extension?
09-09-2009, 09:31 PM
Most forums don't allow images as PHP. Besides, most sites now-a-days like Runescape, Xbox Live, etc use a .PNG for stats.
09-09-2009, 09:35 PM
As far as I know, then, your only real option is to use your PHP script to actually save an image file to your server (If you're in the situation described above). This isn't very hard...just use imagepng with the second argument as your filename. The only downside is that in order to regenerate your image, you'll have to re-run your script. You could do this manually or set up a cron job to do it automatically for you every so often.
09-09-2009, 09:37 PM
09-09-2009, 10:08 PM
I can easily have the image update itself every hour or so, but how can I go about writing this code? I'm new to gd.
09-09-2009, 11:22 PM
We'll need to see the image and what you want to write on it.
So an example of both the blank image and one with text so we know
what it's supposed to look like.
09-10-2009, 12:08 AM
It should write above it "Total Banners: X"
X a variable called from the number of rows in a table of my database.
09-10-2009, 01:29 AM
Here's my shot at it.
Tough to write that much text on your tiny image, but here it is ....
09-10-2009, 02:28 AM
Hey, that's awesome!! That's almost exactly what I'm looking for. Thanks! :)
Now I'm wondering how I can make banner.png display that text? Instead of banner.php.
09-10-2009, 02:46 AM
I never tried it, but Mod Rewrite with a .htaccess file might be able to do it. It has the ability to rewrite urls and even extensions to urls so you may be able to rewrite the .php file to .png
09-11-2009, 02:46 AM
I know it can be done without that.
I need this to provide full functionality. You can't always use .php extensions on forums.
09-11-2009, 06:42 AM
If you use mod rewrite you can make .png extension resolve to .php, but still using the png extension. Otherwise you'll have to make the server save the image you create physically as a .png
09-11-2009, 12:59 PM
Why would you need to display it on someone else's forum?
If it was your own forum, it's not an issue.
And describe what it has to do with a forum.
09-11-2009, 01:20 PM
Like Zangeel said, you'll have to manually edit your .htaccess file on your webserver (or actually save the file). Add this line to the .htaccess file:
AddType application/x-httpd-php .png
There's no other way what you're asking can be done.