codebuds/webp-conversion-bundle 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

codebuds/webp-conversion-bundle

Composer 安装命令:

composer require codebuds/webp-conversion-bundle

包简介

A Symfony bundle to generate WebPImages

README 文档

README

Code Coverage Badge

WebP Conversion Bundle

The WebP Conversion Bundle is a Symfony bundle designed to facilitate the automatic conversion of JPEG, BMP, PNG, and GIF images to WebP format. By converting images to WebP, you can significantly reduce file sizes and improve website rendering speed. This bundle is compatible with PHP 8.1 and 8.2, as well as Symfony 6.1, 6.2, and 6.3

Configuration

The WebPConversionBundle allows you to configure various settings to customize the behavior of the image conversion process. To do this, follow these steps:

  1. Install the bundle: If you haven't already installed the WebPConversionBundle, add it to your Symfony project by running the following command:

    composer require codebuds/webp-conversion-bundle
  2. Override default configuration: To customize the bundle's configuration, create a new file named webp_conversion.yaml inside the config/packages directory of your Symfony project (if it doesn't exist, create it).

  3. Configure the parameters: In the webp_conversion.yaml file, you can set the desired configuration options. For example, to change the default quality and upload path, use the following syntax:

    # config/packages/webp_conversion.yaml
    web_p_conversion:
    quality: 90
    upload_path: '/custom/upload/directory'
    • quality: The quality parameter sets the quality for the generated WebP images. By default, it is set to 80. You can adjust it to a higher or lower value as per your requirements.
    • upload_path: The upload_path parameter defines the directory where the WebP images will be created. By default, it is set to /public/images. You can change it to any other directory that suits your project structure.

Command

This bundle provides a command, codebuds:webp:convert, that simplifies the process of converting images to WebP format. The command accepts a directory as an argument, and all images (JPEG, PNG, GIF, and BMP) within that directory will be converted to WebP. The command offers several optional parameters to customize the conversion:

  • --create: Use this flag to generate the WebP images. If not provided, the directories will be checked, but the final images will not be created.
  • --quality: Set the quality level for the WebP images (80 by default).
  • --force: Use this flag to recreate existing WebP images. By default, existing WebP images will not be overwritten.
  • --suffix: Add a suffix to the names of the created WebP images.

Example:

php bin/console codebuds:webp:convert --create --quality=90 --suffix=_q90 public/images

If the public/images directory contains an image named test.jpg, after executing the command, it will also contain test_q90.webp.

Twig extension

The bundle includes a Twig extension that generates WebP images and returns the path to them. This makes it easy to create elements to optimize website rendering speed.

Example

<!-- Traditional approach -->
<img src="/public/images/test.jpg">

<!-- Modern approach using WebP -->
<picture>
    <source srcset="{{ '/images/test.jpg' | cb_webp }}" type="image/webp">
    <source srcset="/images/test.jpg" type="image/jpeg">
    <img src="/images/test.jpg">
</picture>

The Twig extension also supports VichUploaderBundle assets and LiipImagineBundle filters:

<picture>
    <source srcset="{{ vich_uploader_asset(asset, 'imageFile') | cb_webp | set_webp_extension | imagine_filter(filter) }}"
            type="image/webp">
    <source srcset="{{ vich_uploader_asset(asset, 'imageFile') | imagine_filter(filter) }}">
    <img src="{{ vich_uploader_asset(asset, 'imageFile') | imagine_filter(filter) }}">
</picture>

codebuds/webp-conversion-bundle 适用场景与选型建议

codebuds/webp-conversion-bundle 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 4.38k 次下载、GitHub Stars 达 12, 最近一次更新时间为 2020 年 05 月 10 日, 在 PHP 生态内属于活跃度较高的组件。

我们在过去多个企业项目中使用过 codebuds/webp-conversion-bundle 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 codebuds/webp-conversion-bundle 我们能提供哪些服务?
定制开发 / 二次开发

基于 codebuds/webp-conversion-bundle 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 4.38k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 12
  • 点击次数: 4
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 12
  • Watchers: 4
  • Forks: 2
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2020-05-10