所以我目前正在使用 php 后端和 polymer 前端构建一个网站。客户希望能够为他们自己的事件提供新闻功能。为此,我想将所有图像转换为 webp 并创建一些不同的尺寸,以便我可以快速将它们提供给不同的浏览器(手机、平板电脑、桌面等)。但是我一直没能找到在 PHP 或 JS 中执行此操作的好方法。 Squoosh 非常适合静态 Assets ,但不适合用户生成的内容。任何帮助表示感谢!
最佳答案
PHP 具有处理 webp 图像的函数。试试这个。
<?php
$im = imagecreatefromstring(file_get_contents('path/to/image.jpg')); // Create image identifier
imagewebp($im, 'path/to/image.webp'); // Generate webp image and save to location
imagedestroy($im); // Free up image identifier
?>
关于javascript - 为 Web 压缩和调整图像大小,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54118515/