Web Hosting Talk







View Full Version : Question on PNG, PHP and Javascript


davidb
05-11-2009, 11:10 PM
I hope I do not sound too dumb, but I have a question. I created a program, http://www.chicago-ecigs.com/js/test.html in javascript(there is more too it like the part that generates the code based on the user input but that is not important for my question.)

My goal was to allow people to put it in forum sigs, blogs, websites, and myspace, but since none of those allow java script, except for websites (maybe blogs im not sure since I dont use it.)

One alternative I have seen is using php(from what I have read the GD libraries) to create a dynamic PNG image. I have seen this done on a per load basis, but i still have some questions.

Also when it comes to programming the most in depth experience I have had was 2 terms of java for my engineering degree, so I can program fairly well, or at least can learn quickly, but what I am unsure are the capabilities.


So here are my questions.
1. I am assuming I cant use javascript to make the PNG, I have to use PHP and the GD libraries.
2. Is it possible to make a PNG with that text dynamically
3. If #2 is possible, can I make it so it changes as time goes by just like in the above link, so the time would update, money value and cigs saved value would update without refreshing?

4. I googled for this info, found some, but no real guides on it, or at least the ones I found were really short and not helpful, so do you know of any guides that might help me achieve this goal. As I said I dont really know any php, but I learn fairly fast.

Thank you.

csparks
05-12-2009, 12:53 AM
Well what you probably want to do, is create a script that gets called from a image tag ie <img src="dynamic_script.php?id=123456789" alt="Dynamic Image!" />

Your script would take the id provided, look it up, generate the image and output as a image(sending image headers).

The hardest part of it will be setting up the php script with the gd to make it look nice.

csparks
05-12-2009, 12:57 AM
I guess I should answer your question as you asked it!

1.) Yes php,gd or a similar solution will be needed

2.)Yes, that is the post of GD, but the formatting becomes a pain in the butt.

3.)Yes, because your script will call the specific id and generate the image. (BTW, GD can be ram intensive, so its usually better to cache the image, but in your case that would not be possible, so you will probably end up needing a decent server if your site becomes popular)

4.)Sorry, dont know any guides off hand. Learn GD, and from there, if you can generate the php file to pull the information from the database, you should be able to generate the image.

davidb
05-12-2009, 01:28 AM
Thanks for both of your comments, I now have a place to start.

foobic
05-12-2009, 02:41 AM
Really what you're trying to do requires a graphics library first, eg. GD or ImageMagick. In either case you can then choose any server-side language with an interface to it. PHP-GD is extremely common but if you want to continue working in Java there's jmagick. Or choose from many other languages:
http://www.imagemagick.org/script/api.php
http://www.libgd.org/Binders

Edit: re. 3, I think the only way you could get it to update without refreshing would be to use a different image format, eg. animated gif, swf or svg. But gif would be very limited, flash and svg probably wouldn't be allowed in many instances.