rwsite / wp-thumbnail-plugin
Creates post thumbnails on fly and cache it.
Package info
github.com/tikhomirov/wp-thumbnail-plugin
Type:wordpress-plugin
pkg:composer/rwsite/wp-thumbnail-plugin
Requires
- php: ^7.4 || ^8.0
- composer/installers: ^2.2
Requires (Dev)
- fakerphp/faker: ^1.23
- laravel/pint: ^1.13
- mockery/mockery: ^1.4
- pestphp/pest: ^2.0
- phpstan/phpstan: ^1.10
- phpunit/phpunit: ^10.0
- squizlabs/php_codesniffer: ^3.7
Suggests
None
Provides
None
Conflicts
None
Replaces
None
This package is auto-updated.
Last update: 2026-09-17 18:12:55 UTC
README
On-the-fly thumbnail generation and caching for WordPress. A modern fork of Kama Thumbnail with WebP support, PSR-4 architecture, and both legacy (kama_thumb_*) and modern (thumb_*) APIs.
Requirements
| Component | Minimum | Tested |
|---|---|---|
| WordPress | 5.6 | 6.6 – 6.9 |
| PHP | 7.4 | 7.4, 8.0 – 8.4 |
| Image library | GD or Imagick | GD, Imagick |
Features
- On-the-fly thumbnails — resize and crop images with filesystem caching
- WebP output — optional WebP generation when supported by the server
- Smart source resolution — featured image, first content image, attachments, or custom source
- Admin settings — quality, format, cache directory, placeholder image
- Dual API — modern
thumb_*functions and legacykama_thumb_*aliases - Filters —
get_post_thumbnailand other hooks for integration with term covers and themes - PSR-4 architecture — domain/application/infrastructure layers with Pest tests
Installation
From Git (submodule)
git submodule add git@github.com:tikhomirov/wp-thumbnail-plugin.git wp-content/plugins/wp-thumbnail-plugin
Manual
- Download the latest release.
- Upload to
wp-content/plugins/wp-thumbnail-plugin/. - Activate Thumbnails in WordPress admin.
- Configure options under Settings → Thumbnails.
Composer (inside the plugin)
cd wp-content/plugins/wp-thumbnail-plugin
composer install
Usage
Get thumbnail URL
$url = thumb_src([ 'width' => 480, 'height' => 340, 'crop' => true, ]); // With explicit source (attachment ID or URL) $url = thumb_src([ 'width' => 300, 'height' => 200, ], get_post_thumbnail_id());
Output <img> tag
echo thumb_img([ 'width' => 480, 'height' => 340, 'crop' => true, 'class' => 'img-fluid rounded', 'alt' => 'Image description', ]);
Output linked image
echo thumb_a_img([ 'width' => 480, 'height' => 340, 'crop' => true, ]);
Arguments
| Key | Type | Default | Description |
|---|---|---|---|
width |
int | 0 | Target width in pixels |
height |
int | 0 | Target height in pixels |
crop |
bool | true | Crop to exact dimensions |
class |
string | '' | CSS class for <img> |
alt |
string | '' | Alt text for <img> |
attr |
string | '' | Extra HTML attributes |
src |
string|int | '' | Attachment ID or image URL |
Legacy API
For backward compatibility with Kama Thumbnail themes and snippets:
kama_thumb_src()kama_thumb_img()kama_thumb_a_img()
Development
composer install composer test # Pest unit + integration tests composer test:coverage composer phpstan composer lint composer quality # phpstan + lint
Architecture
wp-thumbnail-plugin/
├── wp-thumbnail-plugin.php # Bootstrap, constants
├── autoload.php
├── src/
│ ├── Application/
│ │ └── ThumbnailService.php # Orchestration
│ ├── Domain/
│ │ ├── Contracts/ # Storage, ImageProcessor interfaces
│ │ ├── Services/ # ThumbnailGenerator
│ │ └── ValueObjects/ # ThumbnailProfile, ImageSource
│ └── Infrastructure/
│ ├── ImageProcessors/ # GD, Imagick
│ ├── Storage/ # FileSystemStorage
│ └── WordPress/ # Plugin, Settings, TemplateFunctions
├── views/admin/ # Settings page
├── assets/js/ # Admin scripts
└── tests/ # Pest tests
Template functions (thumb_src, thumb_img, thumb_a_img) are registered by TemplateFunctions and delegate to ThumbnailService.
Changelog
See CHANGELOG.md.
License
GPL-2.0-or-later
Author
Aleksey Tikhomirov — rwsite.ru
Русский
WP Thumbnails — плагин для генерации и кэширования миниатюр «на лету» в WordPress. Современный форк Kama Thumbnail с WebP, PSR-4 и двумя API.
Совместимость
- WordPress: от 5.6, протестировано на 6.6 – 6.9
- PHP: от 7.4, протестировано на 7.4, 8.0 – 8.4
- Библиотека изображений: GD или Imagick
Что умеет
- Генерация и кэширование миниатюр с обрезкой и изменением размера
- WebP при поддержке сервером
- Поиск исходника: featured image, первое изображение в контенте, вложения
- Настройки в Настройки → Thumbnails
- Современный API (
thumb_*) и legacy (kama_thumb_*) - Фильтр
get_post_thumbnailдля интеграции с обложками терминов
Установка
Скачайте релиз или подключите как git submodule. После активации настройте параметры в админке.
Пример в шаблоне темы
<?php echo thumb_img([ 'width' => 480, 'height' => 340, 'crop' => true, 'class' => 'img-fluid', ]); ?>