• Stars
    star
    203
  • Rank 192,890 (Top 4 %)
  • Language
    PHP
  • Created almost 8 years ago
  • Updated over 5 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Resize WordPress images in the background

Image Processing Queue

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

GPLv2+

More Repositories

1

wp-background-processing

WordPress background processing class
PHP
1,025
star
2

wordpress-nginx

Nginx server configurations for WordPress
DIGITAL Command Language
542
star
3

wp-migrate-db

WordPress plugin that exports your database, does a find and replace on URLs and file paths, then allows you to save it to your computer.
PHP
341
star
4

wp-amazon-s3-and-cloudfront

Automatically copies media uploads to Amazon S3 for delivery. Optionally configure Amazon CloudFront for even faster delivery.
JavaScript
304
star
5

wp-migrations

WordPress library for managing database table schema upgrades and data seeding
PHP
190
star
6

sqlbuddy

phpMyAdmin alternative with a focus on usability
PHP
188
star
7

wp-queue

Job queues for WordPress
PHP
154
star
8

wp-migrate-db-pro-tweaks

Examples of using WP Migrate DB Pro's filters
PHP
98
star
9

spinupwp-composer-site

A WordPress site setup using Composer that is primed and ready to be hosted using SpinupWP.
PHP
82
star
10

better-search-replace

A simple plugin for updating URLs or other text in a database.
PHP
82
star
11

wp-plugin-build

Shell script we use to create builds of our WordPress plugins.
PHP
68
star
12

serialized-editor

A Vue.js component for editing data that has been serialized in PHP
Vue
55
star
13

wp-amazon-s3-and-cloudfront-tweaks

Examples of using Amazon S3 and CloudFront's filters
PHP
53
star
14

wpfbbotkit

A messenger bot developer framework for WordPress
PHP
51
star
15

wp-migrate-db-anonymization

An addon for WP Migrate DB Pro that anonymizes user data
PHP
46
star
16

wp-dbi-file-uploader

A basic JavaScript file uploader plugin that can upload large files
PHP
45
star
17

wp-amazon-web-services

Houses the Amazon Web Services (AWS) PHP libraries and manages access keys. Required by other AWS plugins.
PHP
42
star
18

wp-phpstorm-code-styles

Delicious Brains WordPress coding styles for PhpStorm
25
star
19

npm-scripts

SCSS
23
star
20

spinupwp-plugin

PHP
20
star
21

wp-auto-login

WordPress library for generating automatic login URLs for users
PHP
16
star
22

wp-post-types

WordPress library for registering, reading and writing custom post types.
PHP
13
star
23

spinupwp-mu-plugin

PHP
13
star
24

wp-offload-ses-lite

WP Offload SES Lite sends all outgoing WordPress emails through Amazon Simple Email Service (SES) instead of the local wp_mail() function.
PHP
13
star
25

wp-filesystem

A wrapper for the WP Filesystem
PHP
11
star
26

wp-db-backup

PHP
11
star
27

wp-post-series

WordPress library for adding a series support to posts
PHP
9
star
28

mergebot-schemas

Contains all the WordPress core, plugin and theme schemas for the Mergebot application.
PHP
9
star
29

wp-testimonials

WordPress must-use plugin for managing testimonials, importing from tweets and displaying them.
PHP
7
star
30

spinupwp-cli

The official command-line tool for SpinupWP.
PHP
6
star
31

wp-post-promoter

WordPress must-use plugin for promoting posts via email and social media.
PHP
6
star
32

spinupwp-php-sdk

The official SpinupWP PHP SDK.
PHP
5
star
33

github-gardener

Gardening of GitHub issues and pull requests
PHP
5
star
34

finance-app-trial-project

PHP
4
star
35

wordpress-ansible

Ansible playbook for provisioning WordPress servers
4
star
36

wp-cli-up

wp-cli-up
PHP
4
star
37

wp-mergebot

PHP
3
star
38

testdriiive

PHP
3
star
39

mergebot-schema-generator

Generate Mergebot schema files for WordPress plugins, themes, or core
PHP
2
star
40

woocommerce-subscriptions-renew-active

Abandoned (see below). Extends WooCommerce Subscriptions plugin to enable manual renewals of active subscriptions
PHP
2
star
41

wp-migrate-db-pro-bugs

Bug tracking for WP Migrate DB Pro beta release
2
star
42

wp-markdown

PHP
1
star
43

gp-login-with-email

GlotPress plugin to allow login with the user's email
PHP
1
star