Composer
composer require rwsite/wp-thumbnail-plugin
Вручную
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.
| 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 |
thumb_* functions and legacy kama_thumb_* aliasesget_post_thumbnail and other hooks for integration with term covers and themesgit submodule add git@github.com:tikhomirov/wp-thumbnail-plugin.git wp-content/plugins/wp-thumbnail-plugin
wp-content/plugins/wp-thumbnail-plugin/.cd wp-content/plugins/wp-thumbnail-plugin
composer install
$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());
<img> tagecho thumb_img([
'width' => 480,
'height' => 340,
'crop' => true,
'class' => 'img-fluid rounded',
'alt' => 'Image description',
]);
echo thumb_a_img([
'width' => 480,
'height' => 340,
'crop' => true,
]);
| 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 | '' |
For backward compatibility with Kama Thumbnail themes and snippets:
kama_thumb_src()kama_thumb_img()kama_thumb_a_img()composer install
composer test # Pest unit + integration tests
composer test:coverage
composer phpstan
composer lint
composer quality # phpstan + lint
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.
See CHANGELOG.md.
GPL-2.0-or-later
Aleksey Tikhomirov — rwsite.ru
WP Thumbnails — плагин для генерации и кэширования миниатюр «на лету» в WordPress. Современный форк Kama Thumbnail с WebP, PSR-4 и двумя API.
thumb_*) и legacy (kama_thumb_*)get_post_thumbnail для интеграции с обложками терминовСкачайте релиз или подключите как git submodule. После активации настройте параметры в админке.
<?php echo thumb_img([
'width' => 480,
'height' => 340,
'crop' => true,
'class' => 'img-fluid',
]); ?>