定制 nullaidev/imgix-wp 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

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

nullaidev/imgix-wp

Composer 安装命令:

composer require nullaidev/imgix-wp

包简介

Add imgix WordPress helpers

README 文档

README

This composer package contains a few helper methods for working with imgix and WordPress. This tooling is helpful if you use the WordPress image functions like wp_get_attachment_image() and want your URLs rewritten to imgix URLs.

Further, this package can also rewrite your image URLs to WebP versions if you are not using imgix. Note, this package does not generate WebP images it only rewrites them to WebP if you are not using imgix. If you are using imgix, use imgix to serve WebP images.

Install

In your WordPress theme or plugin.

composer require nullaidev/imgix-wp

Be sure you include the composer's autoload.php.

// Composer
if(file_exists(__DIR__ . '/vendor/autoload.php')) {
    require __DIR__ . '/vendor/autoload.php';
}

Initialize

In your themes functions.php file call \ImgixWp\Core::init(). When no options are used all image URLs created with wp_get_attachment_image_src(), wp_get_attachment_image(), and wp_calculate_image_srcset() will be rewritten as WebP versions.

// functions.php
\ImgixWp\Core::init();

IMPORTANT: If you don't have WebP versions of your images on your server calling \ImgixWp\Core::init() will break your website images leading to 404 errors.

Generate WebP Images

You can generate your own WebP images in WordPress using the cwebp command.

  1. First, download and install the cwebp CLI tool.
  2. From the command line go to the folder with your images such as wordpress/wp-content/uploads/{year}/{month}.
  3. Run the following command.
  4. Enjoy your webp images.
# Example from path, wordpress/wp-content/uploads/2021/01
for file in *; do cwebp -q 50 "$file" -o "${file%.*}.webp"; done

imgix Activation

In your themes functions.php file call \ImgixWp\Core::init() and provide your imgix source URL host name (exclude https). The imgix source must point to your wp-content/uploads folder.

// functions.php
\ImgixWp\Core::init([
    'imgix_host' => 'your-source-name-here.imgix.net'
]);

Calling the \ImgixWp\Core::init() method will automatically rewrite all of your image URLs to the imgix URL generated by wp_get_attachment_image_src(), wp_get_attachment_image(), and wp_calculate_image_srcset() when they are using on the front-end of your WordPress website.

Raw URLs within content will not be rewritten to an imgix version.

Helper Functions

To apply the special query parameters to an image when using wp_get_attachment_image() you can use \ImgixWp\Image::getImage() instead. The \ImgixWp\Image::getImage() has the same signature as wp_get_attachment_image() but include another parameter for the query.

For example, to get WebP images served by imgix using the query string ?auto=format you can use the following:

// page.php
$attachment_id = 1;

// WordPress version - ?auto=format is NOT applied
echo wp_get_attachment_image($attachment_id, 'full', false, []);

// imgix version - ?auto=format is applied
echo \ImgixWp\Image::getImage($attachment_id, 'full', false, [], [
    'auto' => 'format'
]);

nullaidev/imgix-wp 适用场景与选型建议

nullaidev/imgix-wp 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 24 次下载、GitHub Stars 达 0, 最近一次更新时间为 2021 年 12 月 16 日, 在 PHP 生态内属于活跃度较高的组件。

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

围绕 nullaidev/imgix-wp 我们能提供哪些服务?
定制开发 / 二次开发

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

BUG 修复 & 性能优化

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

项目外包 & 长期维护

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

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

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2021-12-16