Dynamic PHP image with a PNG extension
I'm trying to make an image similar to one of these: http://www.danasoft.com/vipersig.jpg
Not really content wise (displaying IP addresses and headers), but more so a PHP image displayed in a PNG format (so I can use it on websites, within BB image tags).
I know how to create a dynamic image, but that's only when you visit the PHP pages. Currently using this if it's matters:
$image = imagecreate(200, 60);
$text_color = imagecolorallocate($image, 255, 255, 0);
header("Content-type: image/png");
imagestring($image, 4, 40, 30, "hello", $text_color);
imagepng($image);
imagecolordeallocate($text_color);
imagedestroy($image);
Any thoughts on how this could be achieved?
A few more examples of what I'm looking for are: http://draynor.net/s开发者_运维百科ignatures
Edit: most comments are about converting from PNG to PHP, I want to convert from PHP to PNG, just to clear it up.
You are close, create your image like you have done above, helpful variables would be $_SERVER['REMOTE_ADDR']
(ip address), $_SERVER['HTTP_USER_AGENT']
(browser). See the reserved server variables.
Format them on your image and get it looking how you want by viewing the PHP script in your browser.
Then if you are using Apache, set up a rewrite rule to rewrite a URL to point to your PHP script.
Here is an example:
RewriteEngine On
RewriteRule ^/signatures/sig.png$ /signature.php [L]
This will rewrite http://yoursite.com/signatures/sig.png
to http://yoursite.com/signature.php
That way users can embed that png URL in their signatures or webpages to display your image.
Eventually you can have multiple signatures and rewrite your URLs by rewriting special parameters (i.e. /signature/1234.png
to signature.php?id=1234
or /signature/style1/1234.png
to signature.php?id=1234&style=style1
).
If you're hosting on apache, you can use mod_rewrite
. Here's a sample (not tested):
RewriteEngine On
RewriteRule /signatures/([A-Za-z0-9])+\.png$ /signature.php?name=$1
Here's a tutorial: http://www.easymodrewrite.com/ More info: http://httpd.apache.org/docs/current/mod/mod_rewrite.html
精彩评论