如果找不到图像,则显示某些图像的自定义图像 - Lighttpd
我有一个网站,可以在创建内容后为一些内容创建图像。 我试图弄清楚在创建内容和创建图像之间要做什么。 我的想法是,我也许可以设置一个自定义图像来显示原始图像上的 404 错误。 但是,我不确定如何使用 lighttpd 执行此操作。 有什么想法或替代方案吗?
编辑:问题是用户不是创建内容的人,而是由进程创建的。 基本上,我们将项目添加到目录中,并且希望根据产品提供商提供的图像创建标准化的目录图像。 但是,我不希望提供商端的服务器速度较慢而减慢新产品的添加速度。 因此,稍后会执行一个单独的过程并在可用的情况下创建图像。 我想我可以让系统在我们创建产品时创建一个默认图像,然后在我们从提供商提供的图像创建图像时覆盖它。
I have a site that creates images for some bit of content after the content is created. I'm trying to figure out what to do in between the time the content is created and the image is created. My thought is that I might be able to set a custom image to display on a 404 error on the original image. However, I'm not sure how to do this with lighttpd. Any ideas or alternatives?
EDIT: The issue is the user isn't the one creating the content, it's being created by a process. Basically we are adding items to a catalog and we want to create a standardized catalog image from an image supplied by the product provider. However, I don't want a slow server on the provider end to slow down the addition of new products. So a separate process goes through and creates the image later, where available. I guess I could have the system create a default image when we create the product and then overwrite it later when we create the image from the provider supplied image.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
客户端的另一种选择是:
Another alternative on the client side is to do:
在 HTML 中使用
(示例来自 w3.org)
Use the
<object>
tag in HTML with a fallback to the default image.(Example from w3.org)
据我了解您的问题:您想显示中间图像,直到生成真实图像?
您可以显示加载图像,并在创建该 DOM 节点时使用 AJAX 将其更改为真实图像。 您可以从头开始编写它,也可以使用任何众所周知且稳定的 AJAX 库,如果您没有自己的偏好,请查看 jQuery。
As I understand your problem: You want to show an intermediate image until the real image has been generated?
You could display a loading image and use AJAX to change that DOM node into the real image when it's been created. You could write it from scratch or use any of the well known and stable AJAX libraries out there, if you have no preference of your own take a look at jQuery.
进一步@kentlarsson - 如果你想通过Javascript来做到这一点,我最近发现了这段代码:
http://jquery.com/plugins/project/Preload 以及 http://demos.flesler.com/jquery/preload/placeholder/ 其作用与他一样建议 - 带有“notFound”选项。
不过,我对 lighttpd 的了解还不够,无法告诉您如何在站点中使用一个或多个子目录设置自定义图像。
Further to @kentlarsson - if you want to do it via Javascript, I recently found this code:
http://jquery.com/plugins/project/Preload and the demo at http://demos.flesler.com/jquery/preload/placeholder/ which does as he suggests - with its 'notFound' option.
I don't know enough about lighttpd to tell you about setting up a custom image with one or more subdirectories in a site though.
我认为你可以单独在客户端解决这个问题。
根据 Jaspers 的回答,您可以这样做:
还可以使用 CSS 分层背景:
后一个解决方案假设您生成的图像没有任何透明度。
I think you could probably solve this on the client side alone.
Based on Jaspers' answer, you could do:
Also layering backgrounds using CSS you could do:
The latter solution assumes you don't have any transparency in your generated image.