sabioweb/php-cwebp-package
Composer 安装命令:
composer require sabioweb/php-cwebp-package
包简介
A pure PHP package for converting images to WebP format
关键字:
README 文档
README
A pure PHP package for converting images to WebP format. This package provides a simple and efficient way to convert JPEG, PNG, GIF, and BMP images to WebP format using PHP's GD extension.
Features
- Convert JPEG, PNG, GIF, and BMP images to WebP
- Configurable quality settings (0-100)
- Lossless conversion mode
- Metadata preservation (when possible)
- Comprehensive error handling
- PSR-4 autoloading
- PHP 8.3+ compatible
Installation
Install via Composer:
composer require sabioweb/php-cwebp-package
Requirements
- PHP 8.3 or higher
- GD extension enabled
Quick Start
<?php use Sabioweb\WebPConverter\SBWebPConverter; use Sabioweb\WebPConverter\SBConversionOptions; require 'vendor/autoload.php'; // Create converter instance $converter = new SBWebPConverter(); // Convert image with default settings $converter->convert('input.jpg', 'output.webp'); // Convert with custom quality $options = SBConversionOptions::create() ->setQuality(85); $converter->convert('input.png', 'output.webp', $options); // Convert with lossless mode $options = SBConversionOptions::create() ->setLossless(true); $converter->convert('input.png', 'output.webp', $options);
Usage
Basic Conversion
use Sabioweb\WebPConverter\WebPConverter; $converter = new SBWebPConverter(); $converter->convert('path/to/image.jpg', 'path/to/output.webp');
Advanced Options
use Sabioweb\WebPConverter\SBWebPConverter; use Sabioweb\WebPConverter\SBConversionOptions; $converter = new SBWebPConverter(); $options = SBConversionOptions::create() ->setQuality(90) ->setLossless(false) ->preserveMetadata(true); $converter->convert('input.png', 'output.webp', $options);
Error Handling
use Sabioweb\WebPConverter\SBWebPConverter; use Sabioweb\WebPConverter\Exceptions\SBInvalidImageException; use Sabioweb\WebPConverter\Exceptions\SBConversionFailedException; use Sabioweb\WebPConverter\Exceptions\SBFileNotFoundException; try { $converter = new SBWebPConverter(); $converter->convert('input.jpg', 'output.webp'); } catch (SBFileNotFoundException $e) { echo "File not found: " . $e->getMessage(); } catch (SBInvalidImageException $e) { echo "Invalid image: " . $e->getMessage(); } catch (SBConversionFailedException $e) { echo "Conversion failed: " . $e->getMessage(); }
API Reference
SBWebPConverter
Main converter class.
Methods
convert(string $inputPath, string $outputPath, ?ConversionOptions $options = null): void- Converts an image file to WebP format
- Parameters:
$inputPath: Path to input image file$outputPath: Path to output WebP file$options: Optional conversion options
SBConversionOptions
Configuration options for image conversion.
Methods
create(): self- Creates a new instancesetQuality(int $quality): self- Sets quality (0-100, default: 80)setLossless(bool $lossless): self- Enables/disables lossless modepreserveMetadata(bool $preserve): self- Preserves metadata when possiblegetQuality(): int- Gets current quality settingisLossless(): bool- Checks if lossless mode is enabledshouldPreserveMetadata(): bool- Checks if metadata preservation is enabled
Supported Formats
- Input: JPEG, PNG, GIF, BMP
- Output: WebP
License
MIT License. See LICENSE file for details.
Documentation
For Persian documentation, see README.fa.md.
Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
sabioweb/php-cwebp-package 适用场景与选型建议
sabioweb/php-cwebp-package 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 0 次下载、GitHub Stars 达 0, 最近一次更新时间为 2025 年 12 月 02 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「php」 「image」 「gd」 「converter」 「Webp」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 sabioweb/php-cwebp-package 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 sabioweb/php-cwebp-package 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 sabioweb/php-cwebp-package 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Tools to convert between .NET and PHP date formats
Encode integer IDs using a preset or customized symbol set
Yii2 LightBox image galary widget uses Lightbox v2.10.0 by Lokesh Dhakar
The Yii2 extension uses jQuery jquery.carousel-1.1.min.js and makes image carousel from php array of structure defined.
The Yii2 extension uses jQuery PrettyPhoto and OwlCarousel js and makes image galary from php array of structure defined.
TCMB Currenct Converter
统计信息
- 总下载量: 0
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 1
- 点击次数: 18
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2025-12-02