生成 PHP 输出的图像

发布于 2024-08-05 02:26:33 字数 109 浏览 2 评论 0原文

我想尝试创建 PHP 输出的图像/缩略图。使用它的地方是在具有各种模块的 CMS 中,然后有一个每个模块的输出外观的缩略图。这应该包括图像和所有内容。

我有什么建议/想法可以去做这件事吗?

I want to experiment with creating images/thumbnails of PHP output. A place where one would use this is in a CMS with various modules, and then have a thumbnail of how the output of how each module looks. This should include images and all.

Any tips/ideas how I would go about doing this?

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

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

发布评论

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

评论(3

就像说晚安 2024-08-12 02:26:33

我相信您想要创建渲染 html 的缩略图/图像,这并不容易。因为您需要为此使用第三方屏幕截图组件。您将 html 保存在临时文件中,并向该组件传递该文件的 url,它将截取该文件的屏幕截图,然后创建您可以在自己的应用程序中使用的图像。

因为渲染效果因浏览器而异,并且明确是浏览器/客户端功能,所以我认为这不能用纯 PHP 来完成。

i believe that you want to create the thumbnail/image of the rendered html, this is not going to be easy. Cause you will need to use a 3rd party screenshot component for this. You will save the html in a temp file and pass that component the url of that file and it will take a screenshot of it and then create the image which in turn u can use in your own application.

Because the rendering would differ from browser to browser and is explicitly a browser/client feature, i dont think this can be done with pure PHP.

半步萧音过轻尘 2024-08-12 02:26:33

您需要确保 php.ini 文件中的 GD 库已打开。

然后通过 php.net 浏览 GD 库函数,了解如何操作图像。

祝你好运!

You need to make sure the GD library is turned on in your php.ini file.

Then have a surf through php.net on the GD library functions that cover how to manipulate images.

Good luck!

太傻旳人生 2024-08-12 02:26:33

我刚刚在我的项目中实现了缩略图系统,因此我可以给您一些有用的提示:

  • 定义用于获取缩略图的脚本,例如 /thumb.php?file=/some/file.jpg
  • 缓存您的结果。在您的脚本中,检查缩略图之前是否已完成,如果是,则仅发送缓存文件,如果没有,则生成缩略图,保存,然后发送。生成缩略图的过程并不快。
  • 您可以使用 cron 清空拇指缓存文件夹,以确保它们始终是最新的。
  • 将带有 str_replace '/' 字符的缩略图存储到其他字符中会更容易,例如 ' '(空格)。这样,您就不需要重新创建文件夹的结构(当您收到 /some/file/image.gif 的请求时,获得“某些文件 image.gif”会更容易)。

I have just implemented thumbnail system in my project, so I can give you some useful tips:

  • Define script for getting thumbnails, like /thumb.php?file=/some/file.jpg
  • Cache your result. In your script, check if thumbnail already was done before, if so, just send cached file, if not, generate thumb, save, then send. Generating thumbnail is not fast process.
  • You can empty your thumb-cache folder with cron, to be sure that they always are up-to-date.
  • It would be easier to store thumbnails with str_replace '/' character into other one, like ' ' (space). With that you won't need to recreate folder's structure (when you get request for /some/file/image.gif it would be easier to get "some file image.gif").
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文