承接 ngfw/webpconverter 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

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

ngfw/webpconverter

Composer 安装命令:

composer require ngfw/webpconverter

包简介

A Laravel package that automatically converts images to WebP format, serves them efficiently, and caches the converted files to optimize performance.

README 文档

README

Latest Version on Packagist Total Downloads

The WebP Converter package is your go-to tool for converting images to the WebP format. It’s built to make your images smaller, faster, and more efficient without sacrificing quality. Whether you're dealing with JPEGs, PNGs, or even BMPs, this package handles them all with ease. It supports both GD and Imagick drivers, giving you flexibility depending on your server environment. And yes, it’s PSR-4 compliant, so it fits seamlessly into your modern PHP projects.

Installation

You can install the package via Composer:

composer require ngfw/WebpConverter

After installing the package, you may want to publish the configuration file to customize the settings according to your project’s needs. To publish the configuration file, run the following command:

php artisan vendor:publish --tag="webp_converter"

This will create a webp_converter.php file in your config directory. Inside this file, you can configure the following options:

driver: Specifies the image processing library to use (gd or imagick).

quality: Sets the default quality for WebP conversion.

storage_path: Defines the default storage path for the converted WebP images.

Example configuration file (config/webp_converter.php):

return [

    /*
    * Default Image Processing Driver
    */
    'driver' => env('WEBP_CONVERTER_DRIVER', 'gd'),

    /*
    * Default WebP Quality
    */
    'quality' => env('WEBP_CONVERTER_QUALITY', 80),

    /*
    * Storage Path
    */

    'storage_path' => env('WEBP_CONVERTER_STORAGE_PATH', 'public/webp_images'),
];

You can then customize these settings as needed to better fit your application’s requirements.

Usage

Using the WebP Converter is super simple. Here’s how you can integrate it into your project:

Loading an Image:

You can load an image from a local path or even a remote URL. The package is smart enough to handle both.

use Ngfw\WebpConverter\WebpConverterFacade as WebpConverter;

// Load a local image
// WebpConverter::load('/path/to/image.jpg');

// Load a remote image
$imgUrl = "https://images.unsplash.com/photo-1724169913051-49f6ff76a070?q=80&w=3570&auto=format&fit=crop&ixlib=rb-4.0.3&ixid=M3wxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8fA%3D%3D";

$image = WebpConverter::load($imgUrl)->convert();
// /storage/webp_images/photo-1724169913051-49f6ff76a070.webp

Example of generating Thumbnail image:

$thumbnailUrl = WebpConverter::load($imgUrl)
        ->width(200)
        ->quality(70) // Set the quality for optimization
        ->optimize() // Apply optimization
        ->saveAs('optimized_thumbnail')
        ->convert();
// /storage/webp_images/optimized_thumbnail.webp

Setting Quality:

Want to control the quality of the output WebP image? No problem. Adjust the quality easily.

$converter->quality(80); // Set quality to 80%

Resizing the Image:

Need to resize the image? Just specify the width and height.

$converter->width(300)->height(200); // Resize to 300x200

Optimizing the Image:

Optimize your image to reduce file size even further. The package applies smart optimizations to deliver the best results.

$converter->optimize();

Converting to WebP:

Finally, convert your image to WebP. You can even specify a custom filename for the output.

$webpUrl = $converter->saveAs('optimized_image')->convert();
echo $webpUrl; // Outputs the URL to the converted WebP image

Chaining Multiple Methods:

You can chain multiple methods for a concise, single-line conversion:

$webpUrl = $converter->load('/path/to/image.jpg')
                     ->quality(90)
                     ->width(500)
                     ->height(300)
                     ->optimize()
                     ->saveAs('final_image')
                     ->convert();
echo $webpUrl; // Outputs the URL to the optimized WebP image

Serving the Image:

Serve the WebP image directly, or get the raw data if you need to do something custom.

$content = $converter->serve(true); // Serve the image as a response array

Blade Examples

Here are a couple of examples on how to use the WebP Converter in a Blade template:

Local Image Conversion: Convert a local image using Laravel's asset helper:

<img src="@webpConverter(asset('/images/png1.png'))" />

This will convert the image located at public/images/png1.png into WebP format and serve it.

Remote Image Conversion:

Convert an image from a remote URL:

<img src="@webpConverter('https://images.unsplash.com/photo-1724217552369-22b256e395d9?q=80&w=3270&auto=format&fit=crop&ixlib=rb-4.0.3&ixid=M3wxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8fA%3D%3D')" />

This will download the image from the specified URL, convert it to WebP format, and then serve it.

Changelog

Please see CHANGELOG for more information what has changed recently.

Contributing

Please see CONTRIBUTING for details.

Security

If you discover any security related issues, please email the author instead of using the issue tracker.

Credits

License

The MIT License (MIT). Please see License File for more information.

ngfw/webpconverter 适用场景与选型建议

ngfw/webpconverter 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 407 次下载、GitHub Stars 达 1, 最近一次更新时间为 2024 年 08 月 25 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「ngfw」 「laravel webpconverter」 「webpconverter」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

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

围绕 ngfw/webpconverter 我们能提供哪些服务?
定制开发 / 二次开发

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

BUG 修复 & 性能优化

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

项目外包 & 长期维护

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

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

统计信息

  • 总下载量: 407
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 1
  • 点击次数: 11
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 1
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2024-08-25