deliciousbrains/wp-image-processing-queue
Composer 安装命令:
composer require deliciousbrains/wp-image-processing-queue
包简介
Resize WordPress images in the background
关键字:
README 文档
README
Image Processing Queue is an alternative to on-the-fly (OTF) image processing (e.g. Aqua Resizer) for WordPress themes.
Like OTF image processing, it allows theme developers to define image sizes for specific theme contexts rather than defining a size for all uploaded images. This greatly reduces the number of resized images and hence reduces disk space usage and the wait time when uploading an image.
Image Processing Queue differs from OTF image processing in how it behaves when an image doesn't exist yet. OTF generates the image right away and the end-user has to wait for the image to be generated. With Image Processing Queue there's no waiting. It immediately returns an image that already exists (that is the closest fit to the image size requested) and adds the image size to a queue. Image sizes are quietly generated in the background using WP Queue.
Image Processing Queue also accommodates responsive themes much better than OTF. It allows theme developers to define a list of image sizes that will work best for their theme's responsive breakpoints. Images generated by Image Processing Queue are added to the post meta so that WordPress core's responsive functions will automatically add them to the srcset and delete them from the filesystem when the image is deleted from the Media Library.
Installation
Install as a Plugin
To install Image Processing Queue as a plugin search for "Image Processing Queue" in your WordPress dashboard and install it from there.
Install as a Library
If you're a plugin or theme developer you will need to require Image Processing Queue using Composer:
$ composer require deliciousbrains/wp-image-processing-queue
The following boilerplate will need adding to your project, which will load the required files and ensure WP cron processes the images in the background:
require_once '/vendor/autoload.php'; Image_Processing_Queue\Queue::instance(); wp_queue()->cron();
The following database tables will also need creating:
CREATE TABLE {$wpdb->prefix}queue_jobs (
id bigint(20) NOT NULL AUTO_INCREMENT,
job longtext NOT NULL,
attempts tinyint(3) NOT NULL DEFAULT 0,
reserved_at datetime DEFAULT NULL,
available_at datetime NOT NULL,
created_at datetime NOT NULL,
PRIMARY KEY (id)
CREATE TABLE {$wpdb->prefix}queue_failures (
id bigint(20) NOT NULL AUTO_INCREMENT,
job longtext NOT NULL,
error text DEFAULT NULL,
failed_at datetime NOT NULL,
PRIMARY KEY (id)
You can use the wp_queue_install_tables() helper function to create the required database tables. This should be called from within an activation hook or custom upgrade routine.
Usage
When you want to output an image in your theme, simply call the ipq_get_theme_image() function passing in the ID of the image post, an array of sizes you've decided on for the image in this particular context, and an array of additional HTML attributes for the <img> tag:
echo ipq_get_theme_image( $post_id, array( array( 600, 400, false ), array( 1280, 720, false ), array( 1600, 1067, false ), ), array( 'class' => 'header-banner' ) );
You can return an image URL directly using the ipq_get_theme_image_url() function by passing in the image ID and required size. If the image size doesn't exist it will be pushed to the queue and the closest matching image URL will be returned.
echo ipq_get_theme_image_url( $post_id, array( 600, 400, false ) );
License
deliciousbrains/wp-image-processing-queue 适用场景与选型建议
deliciousbrains/wp-image-processing-queue 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 1.43k 次下载、GitHub Stars 达 206, 最近一次更新时间为 2017 年 11 月 13 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「queue」 「wordpress」 「images」 「resize」 「crop」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 deliciousbrains/wp-image-processing-queue 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 deliciousbrains/wp-image-processing-queue 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 deliciousbrains/wp-image-processing-queue 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
A Laravel Nova field for distribute your images as array of object.
Pexels API Client for www.pexels.com
PHP AMQP Binding Library
A Laravel package to monitor queue jobs.
TYPO3 CMS extension to create gallery content element with preset crop ratios and pagination
Convert and serve jpeg/png to webp with PHP (if at all possible)
统计信息
- 总下载量: 1.43k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 206
- 点击次数: 19
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: GPLv2
- 更新时间: 2017-11-13