简体   繁体   English

如何在 Lightbox 中使用 WebP 图片?

[英]how to use WebP images in Lightbox?

Using WebP images through <picture> tag is a great way of speeding up the web for a majority of browsers.通过<picture>标签使用 WebP 图像是加快大多数浏览器网络速度的好方法。 I am able to do the same inside the Lightbox, but just for a thumbnails.我可以在灯箱内做同样的事情,但只是为了缩略图。

<a href="some_img.jpg" data-lightbox="reference">
    <picture>
        <source srcset="some_img.webp" type="image/webp">
        <img src="some_img.jpg"alt="">
    </picture>
</a>

Is there a way to use the WebP images even for the image displayed on click (in Lightbox set through the anchor's href )?有没有办法使用 WebP 图像,即使是单击时显示的图像(在通过锚点的href设置的灯箱中)?

The following relates to wordpress - I'm using the WebP Express plugin - Which serves the webp images as an extention to jpg ie "myimage.jpg.webp" my guess is the lightbox could be served the image simply by adding".webp" to js code somewhere以下内容与 wordpress 有关 - 我正在使用 WebP Express 插件 - 它将 webp 图像作为 jpg 的扩展,即“myimage.jpg.webp” 我猜想灯箱可以通过添加“.webp”来提供图像到某处的 js 代码

*Update it seems possible - I can get the lightbox to open the webp photo by changing the custom url in the photo to go to .webp version *更新似乎是可能的 - 我可以通过将照片中的自定义 url 更改为 .webp 版本来让灯箱打开 webp 照片

The problem remains figuring out a way to open the .jpg or the .webp respectively in the lightbook based on the browser compatibility问题仍然是想办法根据浏览器的兼容性在灯本中分别打开 .jpg 或 .webp

Found this thread which says that the swipebox lightbox is webp compatible发现这个帖子说 swipebox 灯箱是 webp 兼容的

https://wordpress.org/support/topic/support-webp-images/ https://wordpress.org/support/topic/support-webp-images/

maybe you can modify your existing lightbox code similarly:也许您可以类似地修改现有的灯箱代码:

Adding webp is just a simple change – just add the extension in line 235 of lightbox-photoswipe.php:添加 webp 只是一个简单的更改 - 只需在 lightbox-photoswipe.php 的第 235 行添加扩展名:

OLD:老的:

if (in_array($type['ext'], array('jpg', 'jpeg', 'jpe', 'gif', 'png', 'bmp', 'tif', 'tiff', 'ico'))) {

NEW:新的:

if (in_array($type['ext'], array('jpg', 'jpeg', 'jpe', 'gif', 'png', 'bmp', 'tif', 'tiff', 'ico', 'webp'))) {

screenshot截屏

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM