如果找不到图像,则显示某些图像的自定义图像 - Lighttpd

发布于 2024-07-08 16:17:38 字数 342 浏览 5 评论 0原文

我有一个网站,可以在创建内容后为一些内容创建图像。 我试图弄清楚在创建内容和创建图像之间要做什么。 我的想法是,我也许可以设置一个自定义图像来显示原始图像上的 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 技术交流群。

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

发布评论

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

评论(5

苄①跕圉湢 2024-07-15 16:17:38

客户端的另一种选择是:

<img src="/images/generated_image_xyz.png" 
    onerror="this.src='/images/default_image.png'; this.title='Loading...';" />

Another alternative on the client side is to do:

<img src="/images/generated_image_xyz.png" 
    onerror="this.src='/images/default_image.png'; this.title='Loading...';" />
月亮邮递员 2024-07-15 16:17:38

在 HTML 中使用 标记并回退到默认图像。

<P>                 <!-- First, try the Python applet -->
<OBJECT title="The Earth as seen from space" 
        classid="http://www.observer.mars/TheEarth.py">
                    <!-- Else, try the MPEG video -->
  <OBJECT data="TheEarth.mpeg" type="application/mpeg">
                    <!-- Else, try the GIF image -->
    <OBJECT data="TheEarth.gif" type="image/gif">
                    <!-- Else render the text -->
     The <STRONG>Earth</STRONG> as seen from space.
    </OBJECT>
  </OBJECT>
</OBJECT>
</P>

(示例来自 w3.org)

Use the <object> tag in HTML with a fallback to the default image.

<P>                 <!-- First, try the Python applet -->
<OBJECT title="The Earth as seen from space" 
        classid="http://www.observer.mars/TheEarth.py">
                    <!-- Else, try the MPEG video -->
  <OBJECT data="TheEarth.mpeg" type="application/mpeg">
                    <!-- Else, try the GIF image -->
    <OBJECT data="TheEarth.gif" type="image/gif">
                    <!-- Else render the text -->
     The <STRONG>Earth</STRONG> as seen from space.
    </OBJECT>
  </OBJECT>
</OBJECT>
</P>

(Example from w3.org)

逆蝶 2024-07-15 16:17:38

据我了解您的问题:您想显示中间图像,直到生成真实图像?

您可以显示加载图像,并在创建该 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.

怼怹恏 2024-07-15 16:17:38

进一步@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.

浅笑依然 2024-07-15 16:17:38

我认为你可以单独在客户端解决这个问题。

根据 Jaspers 的回答,您可以这样做:

<OBJECT data="/images/generated_image_xyz.png" type="image/png">
     Loading..<blink>.</blink>
</OBJECT>

还可以使用 CSS 分层背景:

<style type="text/css">
    .content_image { width:100px; height: 100px; 
        background: transparent url('/images/default_image.png') no-repeat }
    .content_image div { width:100px; height: 100px; }
</style>

<div class="content_image">
     <div style="background: 
         transparent url('/images/generated_image_xyz.png') no-repeat" />
</div>

后一个解决方案假设您生成的图像没有任何透明度。

I think you could probably solve this on the client side alone.

Based on Jaspers' answer, you could do:

<OBJECT data="/images/generated_image_xyz.png" type="image/png">
     Loading..<blink>.</blink>
</OBJECT>

Also layering backgrounds using CSS you could do:

<style type="text/css">
    .content_image { width:100px; height: 100px; 
        background: transparent url('/images/default_image.png') no-repeat }
    .content_image div { width:100px; height: 100px; }
</style>

<div class="content_image">
     <div style="background: 
         transparent url('/images/generated_image_xyz.png') no-repeat" />
</div>

The latter solution assumes you don't have any transparency in your generated image.

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