带有 PNG 扩展名的动态 PHP 图像

发布于 2024-12-07 11:21:27 字数 734 浏览 5 评论 0原文

我正在尝试制作类似于以下之一的图像: http://www.danasoft.com/vipersig .jpg

并不是真正的内容明智(显示 IP 地址和标头),而是以 PNG 格式显示的 PHP 图像(因此我可以在网站上的 BB 图像标签内使用它)。

我知道如何创建动态图像,但那只是当您访问 PHP 页面时。如果重要的话,目前正在使用它:

$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);

关于如何实现这一点有什么想法吗?

我正在寻找的更多示例是: http://draynor.net/signatures

编辑:大多数评论是关于从 PNG 转换为 PHP 的,我想从 PHP 转换为 PNG,只是为了清除它。

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/signatures

Edit: most comments are about converting from PNG to PHP, I want to convert from PHP to PNG, just to clear it up.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

一直在等你来 2024-12-14 11:21:27

您已经很接近了,像上面那样创建图像,有用的变量是 $_SERVER['REMOTE_ADDR'] (ip 地址)、$_SERVER['HTTP_USER_AGENT'] (浏览器)。请参阅保留服务器变量

在您的图像上设置它们的格式,并通过在浏览器中查看 PHP 脚本使其看起来像您想要的那样。

然后,如果您使用 Apache,请设置重写规则来重写 URL 以指向您的 PHP 脚本。

这是一个示例:

RewriteEngine On
RewriteRule ^/signatures/sig.png$ /signature.php [L]

这会将 http://yoursite.com/signatures/sig.png 重写为 http://yoursite.com/signature.php 这样用户可以将该 png URL 嵌入到他们的签名或网页中以显示您的图像。

最终,您可以拥有多个签名并通过重写特殊参数(即 /signature/1234.pngsignature.php?id=1234/signature 来重写您的 URL /style1/1234.pngsignature.php?id=1234&style=style1)。

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).

很酷又爱笑 2024-12-14 11:21:27

如果您托管在 apache 上,则可以使用 mod_rewrite。这是一个示例(未经测试):

RewriteEngine On
RewriteRule /signatures/([A-Za-z0-9])+\.png$ /signature.php?name=$1

这是一个教程:http://www.easymodrewrite.com/
更多信息: http://httpd.apache.org/docs/current/mod/ mod_rewrite.html

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文